达梦官方提供镜像目前是dm8_x86 版本,因为众所周知的国产化方面的需求,需要在kylin v10机器上部署一个DM数据库以及其他使用数据库的服务,为了更便捷的交付需要把安装步骤都写入到ansible 脚本里,这里就单说下DM 的部署
DM7 数据库镜像build
先使用安装包在Arm宿主机上进行安装
#创建安装目录
mkdir /dm7
#更改目录权限
chown dmdba.dinstall -R /dm7
#创建用户组
groupadd distall
#创建安装用户
useradd -g distall dmdba
#初始化用户密码
passwd dmdba
#dmdba用户的~/.bash_profile 里添加如下内容:
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/dm7/bin"
export DM_HOME="/dm7"
export PATH=$DM_HOME/bin:$PATH:$HOME/bin
# 数据库安装
./DMInstall.bin -i
# 通过执行dminit文件初始化实例参数来创建实例
./dminit PATH=/dm7/data LOG_PATH=/dm7/data/DAMENG/DAMENG01.log LOG_PATH=/dm7/data/DAMENG/DAMENG02.log LOG_PATH=/dm7/data/DAMENG/DAMENG03.log EXTENT_SIZE=16 PAGE_SIZE=8 LOG_SIZE=500 CASE_SENSITIVE=Y DB_NAME=DAMENG INSTANCE_NAME=DMSERVER port_num=5236 SYSDBA_PWD=123456789012
# 创建数据库服务实例
./dm_service_installer.sh -t dmserver -i /dm7/data/DAMENG/dm.ini -p DMSERVER
# 启动数据库
./DmServiceDMSERVER start
安装目录在/dm7 目录
构建镜像Dockerfile, 把宿主机上安装二进制文件服务到镜像里
FROM centos:centos8
COPY /dm7 /
WORKDIR /dm7
构建镜像 dm7:centos_kylin_arm64
安装脚本
ansible 安装入口 install.yaml
hosts: node_hosts
gather_facts: false
vars:
ansible_python_interpreter: /usr/bin/python2
tasks:
# 加载所有镜像
- name: load all images for dm, harbor etc.
include_role:
name: deploy
tasks_from: 01.loadimages.yml
when: (deploy_type is not defined) or (deploy_type == "loadimages")
tags: [ "always" ]
# 创建dm的namespace
- name: Create namespace
include_role:
name: deploy
tasks_from: 02.create_ns.yml
when: (deploy_type is not defined) or (deploy_type == "create_namespace")
tags: [ "always" ]
# 部署 dm 数据库
- name: Deploy DM
include_role:
name: deploy_rlstudio
tasks_from: 03.dm.yml
when: (deploy_type is not defined) or (deploy_type == "dm")
tags: [ "always" ]
01.loadimages.yml
- name: Load all images
args:
chdir: "{{ role_path }}/images/"
shell: |
echo "load all images"
# 查找当前目录及其子目录下的所有 .tar 文件,并循环处理
find . -type f -name "*.tar" | while read -r tar_file; do
echo "Loading Docker image from: $tar_file"
docker load -i "$tar_file"
if [ $? -eq 0 ]; then
echo "Successfully loaded: $tar_file"
else
echo "Failed to load: $tar_file"
fi
done
echo "All .tar files have been processed."
ignore_errors: True
01.create_ns.yml
- name: Create dm namespace
shell: "kubectl create namespace {{ dm7_namespace }} "
ignore_errors: True
03.dm.yml
- name: Label dm7 node | rlstudio/dataNode=dm
delegate_to: "{{ inventory_hostname }}"
shell: "{{ kubectl }} label --overwrite node {{ inventory_hostname }} rlstudio/dataNode=dm"
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
- name: Ensure parent directory exists
file:
path: "{{ dm7_dir }}"
state: directory
mode: 0755
become: yes
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
- name: Deploy dm7 | copy persistent volume
copy:
src: "{{ role_path }}/files/dm7/data"
dest: "{{ dm7_dir }}"
mode: 0755
delegate_to: "{{ inventory_hostname }}"
run_once: true
become: yes
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
- name: chmod dm7 persistent volume | sudo chmod -R 777 /dm7/data
delegate_to: "{{ inventory_hostname }}"
run_once: true
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
shell: |
sudo chmod -R 777 /dm7/data
- name: Deploy dm7 | modify dm7.yaml (nodePort)
delegate_to: "{{ inventory_hostname }}"
run_once: true
shell: "sed -i 's/nodePort:.*$/nodePort: {{ rlstudio_dm7_port }}/' {{ role_path }}/files/dm_dp/dm7_svc.yaml"
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
- name: Deploy dm7 | modify dm7.yaml (pvc path)
delegate_to: "{{ inventory_hostname }}"
run_once: true
shell: "sed -i 's#path:.*$#path: {{ dm7_dir }}#' {{ role_path }}/files/dm_dp/dm7_dp.yaml"
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
- name: Check if PVC exists
shell: "kubectl get pvc dm7-data-pvc -n dm --ignore-not-found"
register: pvc_check
delegate_to: "{{ inventory_hostname }}"
run_once: true
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
- name: Apply PVC if it does not exist
shell: "kubectl apply -f {{ role_path }}/files/dm_dp/dm7_pvc.yaml"
when: pvc_check.stdout == ""
delegate_to: "{{ inventory_hostname }}"
run_once: true
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
- name: Deploy dm
delegate_to: "{{ inventory_hostname }}"
run_once: true
shell: "kubectl apply -f {{ role_path }}/files/dm_dp/dm7_dp.yaml -n {{ dm7_namespace }}"
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
- name: Check if dm7-nodeport Service exists and get details
shell: "kubectl get service dm7-nodeport -n dm -o json --ignore-not-found"
register: service_check
delegate_to: "{{ inventory_hostname }}"
run_once: true
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
ignore_errors: yes
- name: Apply dm7-nodeport Service if it does not exist
shell: "kubectl apply -f {{ role_path }}/files/dm_dp/dm7_svc.yaml"
when: service_check.stdout | length == 0
delegate_to: "{{ inventory_hostname }}"
run_once: true
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
- name: Deploy dm7 | Check dm7 status
block:
- name: Check status dm7 is running
shell: "{{ kubectl }} get pod -n dm --no-headers | awk '{print $3}'"
register: shell_result
retries: 40
delay: 20
until: shell_result.stdout == "Running"
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
rescue:
- name: Status of dm7 is not running
fail:
msg: "Please check dm7 status"
vars:
ansible_python_interpreter: "{{ custom_python_interpreter }}"
上面涉及k8s deployment 的部署文件

dm7_dp.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: dm7
namespace: dm
spec:
replicas: 1
selector:
matchLabels:
app: apps.deployment-dm-dm7
template:
metadata:
labels:
app: apps.deployment-dm-dm7
spec:
containers:
- name: container-0
image: dm7:centos_kylin_arm64
imagePullPolicy: IfNotPresent
ports:
- containerPort: 5236
name: 5236tcp31236
protocol: TCP
volumeMounts:
- mountPath: /dm7/data
name: dm7-data
volumes:
- name: dm7-data
persistentVolumeClaim:
claimName: dm7-data-pvc
dm7_pvc.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: dm7-data-pv
namespace: dm
spec:
capacity:
storage: 5Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /dm7/data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: dm7-data-pvc
namespace: dm
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
dm7_svc.yaml
apiVersion: v1
kind: Service
metadata:
name: dm7-nodeport
namespace: dm
spec:
type: NodePort
selector:
app: apps.deployment-dm-dm7
ports:
- name: 5236tcp31236
port: 5236
targetPort: 5236
nodePort: 31236
protocol: TCP
执行安装脚本
ansible-playbook playbooks/install.yml -e deploy_type=dm

启动成功

工具测试下
