前言
本次内容基于在docker上添加dm数据库并运行,以及如何在docker中编辑dm数据库,并上传相应的软件包用来安装,以及配置相应的环境变量信息
一、docker安装和启动
1.docker安装
本次基于centos7来安装docker,docker的安装方法很多,这边我介绍下最为简单方便的安装方式
方法一:执行下面的命令,该命令为官方安装脚本,自动安装非常方便,大概需要等待5-10分钟安装会完毕
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
方法二:执行下面的命令,该命令为国内 daocloud 一键安装命令,跟上面的差不多也是自动安装,两条命令任选其一
curl -sSL https://get.daocloud.io/docker | sh
注意!运行上述安装命令请确保机器能够连接互联网
[root@czk ~]# curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
# Executing docker install script, commit: 614d05e0e669a0577500d055677bb6f71e822356
+ sh -c 'yum install -y -q yum-utils'
file:///mnt/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml"
正在尝试其它镜像。
No Presto metadata available for base
警告:RPM 数据库已被非 yum 程序修改。
+ sh -c 'yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo'
已加载插件:fastestmirror
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
+ '[' stable '!=' stable ']'
+ sh -c 'yum makecache'
已加载插件:fastestmirror
base | 3.6 kB 00:00:00
file:///mnt/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml"
正在尝试其它镜像。
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/6): docker-ce-stable/7/x86_64/filelists_db | 32 kB 00:00:00
(2/6): docker-ce-stable/7/x86_64/updateinfo | 55 B 00:00:00
(3/6): docker-ce-stable/7/x86_64/primary_db | 78 kB 00:00:00
(4/6): docker-ce-stable/7/x86_64/other_db | 124 kB 00:00:00
(5/6): updates/7/x86_64/other_db | 1.0 MB 00:00:00
(6/6): updates/7/x86_64/filelists_db | 8.4 MB 00:00:07
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
元数据缓存已建立
+ sh -c 'yum install -y -q docker-ce docker-ce-cli containerd.io docker-scan-plugin docker-compose-plugin docker-ce-rootless-extras'
file:///mnt/cdrom/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/cdrom/repodata/repomd.xml"
正在尝试其它镜像。
No Presto metadata available for base
No Presto metadata available for updates
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.16-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
docker-ce-20.10.16-3.el7.x86_64.rpm 的公钥尚未安装
导入 GPG key 0x621E9F35:
用户ID : "Docker Release (CE rpm) <docker@docker.com>"
指纹 : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
来自 : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
================================================================================
To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:
dockerd-rootless-setuptool.sh install
Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.
To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/
WARNING: Access to the remote API on a privileged Docker daemon is equivalent
to root access on the host. Refer to the 'Docker daemon attack surface'
documentation for details: https://docs.docker.com/go/attack-surface/
================================================================================
2.docker启动
安装好的docker可以直接通过systemctl start docker来启动docker,启动后可以通过命令来查看是否启动成功
[root@czk ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since 一 2022-05-16 09:20:04 CST; 7min ago
Docs: https://docs.docker.com
Main PID: 26384 (dockerd)
Memory: 42.3M
CGroup: /system.slice/docker.service
└─26384 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
5月 16 09:20:04 czk dockerd[26384]: time="2022-05-16T09:20:04.105558484+08:00" level=info msg="scheme \"unix\" n...e=grpc
5月 16 09:20:04 czk dockerd[26384]: time="2022-05-16T09:20:04.105691220+08:00" level=info msg="ccResolverWrapper...e=grpc
5月 16 09:20:04 czk dockerd[26384]: time="2022-05-16T09:20:04.105707250+08:00" level=info msg="ClientConn switch...e=grpc
5月 16 09:20:04 czk dockerd[26384]: time="2022-05-16T09:20:04.123300048+08:00" level=info msg="Loading container...tart."
5月 16 09:20:04 czk dockerd[26384]: time="2022-05-16T09:20:04.304895261+08:00" level=info msg="Default bridge (d...dress"
5月 16 09:20:04 czk dockerd[26384]: time="2022-05-16T09:20:04.406938879+08:00" level=info msg="Loading containers: done."
5月 16 09:20:04 czk dockerd[26384]: time="2022-05-16T09:20:04.434588069+08:00" level=info msg="Docker daemon" co....10.16
5月 16 09:20:04 czk dockerd[26384]: time="2022-05-16T09:20:04.435389579+08:00" level=info msg="Daemon has comple...ation"
5月 16 09:20:04 czk systemd[1]: Started Docker Application Container Engine.
5月 16 09:20:04 czk dockerd[26384]: time="2022-05-16T09:20:04.455991879+08:00" level=info msg="API listen on /va....sock"
Hint: Some lines were ellipsized, use -l to show in full.
二、docker常用命令
1.docker images 查看你当前是否有镜像源可以启动
repository 镜像的仓库源
tag:镜像id
created:镜像创建时间
size:镜像大小
[root@czk ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dm8 v01 1648764da958 5 days ago 1.72GB
zqingfa/dmserver v1.0 990eef5f5494 3 years ago 1.73GB
2.docker images -q 显示所有的id信息
[root@czk ~]# docker images -q
1648764da958
990eef5f5494
3.docker images --digest 显示摘要信息
[root@czk ~]# docker images --digests
REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE
dm8 v01 <none> 1648764da958 5 days ago 1.72GB
zqingfa/dmserver v1.0 sha256:dedba2bcacc8741b14ab4e6f3dcb6ea5dc6e6dc6fcde2390f41a0e0cfc88158c 990eef5f5494 3 years ago 1.73GB
4.docker images --digests --no-trunc 显示完整摘要信息
[root@czk ~]# docker images --digests --no-trunc
REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE
dm8 v01 <none> sha256:1648764da95834f3534ae67ff3c88bd34dcf4c49b3efc24cbd014eb9796362d4 5 days ago 1.72GB
zqingfa/dmserver v1.0 sha256:dedba2bcacc8741b14ab4e6f3dcb6ea5dc6e6dc6fcde2390f41a0e0cfc88158c sha256:990eef5f5494493235c0ac2b08a04213f5cbf4f6d8230f4cefa962e7d95d68cc 3 years ago 1.73GB
5.docker search tomcat 寻找tomcat镜像
[root@czk ~]# docker search tomcat
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tomcat Apache Tomcat is an open source implementati… 3319 [OK]
tomee Apache TomEE is an all-Apache Java EE certif… 96 [OK]
bitnami/tomcat Bitnami Tomcat Docker Image 44 [OK]
arm32v7/tomcat Apache Tomcat is an open source implementati… 11
rightctrl/tomcat CentOS , Oracle Java, tomcat application ssl… 7 [OK]
arm64v8/tomcat Apache Tomcat is an open source implementati… 7
amd64/tomcat Apache Tomcat is an open source implementati… 4
jelastic/tomcat An image of the Tomcat Java application serv… 3
tomcat2111/pisignage-server PiSignage Server 3 [OK]
cfje/tomcat-resource Tomcat Concourse Resource 2
oobsri/tomcat8 Testing CI Jobs with different names. 2
appsvc/tomcat 1
chenyufeng/tomcat-centos tomcat基于centos6的镜像 1 [OK]
ppc64le/tomcat Apache Tomcat is an open source implementati… 1
tomcatling/jupyterhub_aws 1
softwareplant/tomcat Tomcat images for jira-cloud testing 0 [OK]
6.docker pull tomcat 拉取镜像
[root@czk ~]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
67e8aa6c8bbc: Pull complete
627e6c1e1055: Pull complete
0670968926f6: Pull complete
5a8b0e20be4b: Pull complete
7a93fb438607: Pull complete
400f1e54bef0: Pull complete
f0b65b53f1a4: Downloading [===================> ] 79.46MB/204MB
dc9d1a029c69: Download complete
64b5028636b5: Download complete
1cd304de2423: Download complete
7.删除单个镜像:docker rmi -f hello-world
删除多个镜像:docker rmi -f hello-world nginx
删除全部镜像:docker rmi -f $(docker images -qa)
8.docker ps 查看当前正在运行的容器
[root@czk ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c656457d90e dm8:v01 "/bin/bash /startDm.…" 5 days ago Up 17 hours 0.0.0.0:5236->5236/tcp, :::5236->5236/tcp dm8_01
9.docker ps -l 查看上次运行退出的容器信息
[root@czk ~]# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3dc428524f4d zqingfa/dmserver:v1.0 "/opt/dm/bin/dmserve…" 16 hours ago Exited (1) 16 hours ago nice_hugle
10.docker start dm8_01 启动容器
docker restart dm8_01 重启重启
docker stop dm8_01 停止容器
三、docker安装dm数据库
在docker上安装dm数据库有两种方式,一种是下载达梦官网上docker镜像包,然后导入启动运行,另外一种是拉取仓库里的dm数据库,然后启动运行
方法一:基于达梦官网下载docker镜像包安装dm数据库
1.首先找到官网,然后点击下载 https://eco.dameng.com/download/
2.其次将下载好的dm8_docker.tar包上传到服务器上
3.然后新建一个/dm8目录,将包放到该目录下
4.进入dm8目录,运行docker import dm8_docker.tar dm8:v01 该命令用于导入包到docker中
[root@czk opt]# cd /dm8/
[root@czk dm8]# ll
总用量 1689676
-rw-r--r--. 1 root root 1730224640 5月 10 13:26 dm8_docker.tar
[root@czk dm8]# docker import dm8_docker.tar dm8:v01
sha256:ed4283b673ad2976e7f68007650772a2a8c37dc10edf40ad79405a1d0e7b261f
5.使用docker images查看下是否导入进来了
[root@czk dm8]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dm8 v01 ed4283b673ad 52 seconds ago 1.72GB
6.然后启动dm数据库,启动命令如下:
两条命令都可以启动,任选其一
docker start dm8_01
docker run -itd -p 5236:5236 --name dm8_01 dm8:v01 /bin/bash /startDm.sh
7.启动后查看下是否启动成功
[root@czk ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c656457d90e dm8:v01 "/bin/bash /startDm.…" 5 days ago Up 3 seconds 0.0.0.0:5236->5236/tcp, :::5236->5236/tcp dm8_01
8.也可以通过logs 查看进程启动状态
[root@czk ~]# docker logs -f dm8_01
Starting DmServicePROD: Last login: Fri Nov 12 07:14:47 UTC 2021
[ OK ]
^CStarting DmServicePROD: Last login: Tue May 10 05:30:57 UTC 2022
[ OK ]
Starting DmServicePROD: Last login: Tue May 10 05:47:04 UTC 2022
[ OK ]
Starting DmServicePROD: Last login: Tue May 10 05:50:41 UTC 2022
[ OK ]
^CStarting DmServicePROD: Last login: Sun May 15 08:23:24 UTC 2022
[ OK ]
^CStarting DmServicePROD: Last login: Sun May 15 08:30:44 UTC 2022
[ OK ]
Starting DmServicePROD: Last login: Sun May 15 09:34:14 UTC 2022 on pts/1
Attempting to create directory /home/dmdba/perl5
[ OK ]
方法二:基于仓库安装dm数据库
此方法比较简单,就是去搜索下dm数据库,然后拉取下来就行
1.先search搜寻下,找到其中的达梦数据镜像
[root@czk dm8]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dm8 v01 ed4283b673ad 52 seconds ago 1.72GB
[root@czk dm8]# docker search dmserver
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
dmtc/zhan-shen 战神容器 云深不知处 ddns frpc frps frp 教程h… 30
dmtc/sakura sakura已融合至战神容器,请下载 dmtc/zhan-she… 1
eldosantos/dmserver 0
liangtiansheng/dmserver 0
bicster/dmserverbase CentOS 7 DM Server Base 0
peter4431/dmserver 0
zqingfa/dmserver 达梦数据库的镜像,默认使用/opt/dm/bin/dmserv… 0
dmtc/voice-announcements 云梦,语音合成播报系统 云深不知处 官方企鹅Q… 0
wangzldocker/dmserver 0
lathabp26/dmserver Diona Repositories 0
2.拉取下来
注意,拉取的时候要附带下版本号也就是末尾的v1.0,如果不带上会报错
[root@czk dm8]# docker pull zqingfa/dmserver
Using default tag: latest
Error response from daemon: manifest for zqingfa/dmserver:latest not found: manifest unknown: manifest unknown
[root@czk dm8]# docker pull zqingfa/dmserver:v1.0
v1.0: Pulling from zqingfa/dmserver
03ebf35be0c2: Pull complete
9a97692cf0c0: Pull complete
a7347d25cf1c: Pull complete
2db8c92c6a74: Pull complete
2b1cdac9f6ac: Pull complete
Digest: sha256:dedba2bcacc8741b14ab4e6f3dcb6ea5dc6e6dc6fcde2390f41a0e0cfc88158c
Status: Downloaded newer image for zqingfa/dmserver:v1.0
docker.io/zqingfa/dmserver:v1.0
3.启动dm数据库
docker run -d zqingfa/dmserver:v1.0
四、编辑dm文件以及配置rlwrap环境变量
1.首先编辑的话需要先进入到dm容器里面
docker exec -it dm8_01 /bin/bash
数据文件都在/dm8/data/PROD下面,直接vim就可以编辑
[root@czk ~]# docker exec -it dm8_01 /bin/bash
[root@9c656457d90e /]#
[root@9c656457d90e PROD]# ll
total 332876
drwxr-xr-x. 2 dmdba dinstall 6 Sep 8 2021 bak
drwxr-xr-x. 1 dmdba dinstall 4096 May 16 01:49 ctl_bak
-rw-r--r--. 1 dmdba dinstall 5120 May 16 01:49 dm.ctl
-rw-r--r--. 1 dmdba dinstall 48796 May 10 05:50 dm.ini
-rw-r--r--. 1 dmdba dinstall 795 Sep 8 2021 dminit20210908035151.log
-rw-r--r--. 1 dmdba dinstall 633 Sep 8 2021 dm_service.prikey
drwxr-xr-x. 2 dmdba dinstall 6 Sep 8 2021 HMAIN
-rw-r--r--. 1 dmdba dinstall 134217728 Sep 8 2021 MAIN.DBF
-rw-r--r--. 1 dmdba dinstall 12 Sep 8 2021 rep_conflict.log
-rw-r--r--. 1 dmdba dinstall 134217728 May 16 01:54 ROLL.DBF
-rw-r--r--. 1 dmdba dinstall 479 Sep 8 2021 sqllog.ini
-rw-r--r--. 1 dmdba dinstall 45088768 May 16 01:54 SYSTEM.DBF
-rw-r--r--. 1 dmdba dinstall 27262976 May 16 01:49 TEMP.DBF
drwxr-xr-x. 2 dmdba dinstall 6 Sep 8 2021 trace
[root@9c656457d90e PROD]# pwd
/dm8/data/PROD
2.上传软件包到容器里的话,通过cp命令将本机的内容上传上去即可
[root@czk opt]# docker cp rlwrap-0.42-1.el6.x86_64.rpm dm8_01:/opt
[root@czk opt]# docker exec -it dm8_01 /bin/bash
[root@9c656457d90e /]# cd /opt/
[root@9c656457d90e opt]# ll
total 96
-rw-r--r--. 1 root root 95240 Apr 6 11:45 rlwrap-0.42-1.el6.x86_64.rpm
[root@9c656457d90e opt]#
3.解压软件包
注意解压的时候可能会提示你缺少perl依赖,记得用yum install装下perl相关的内容
[root@9c656457d90e opt]# rpm -ivh rlwrap-0.42-1.el6.x86_64.rpm
warning: rlwrap-0.42-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ################################# [100%]
package rlwrap-0.42-1.el6.x86_64 is already installed
4.配置环境变量
配置完记得source下,source/home/dmdba/.bash_profile
-sh-4.2$ cat /home/dmdba/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/dm8/bin
alias disql="rlwrap disql"
export PATH
5.验证下结果
[root@9c656457d90e opt]# disql SYSDBA/SYSDBA
服务器[LOCALHOST:5236]:处于普通打开状态
登录使用时间 : 5.929(ms)
disql V8
SQL>
总结
如果你还有其他问题,欢迎来提问~