@ 达梦学习进阶-DM8搭建主备切换
达梦学习进阶-DM8搭建主备切换
随着学习深入,单机架构的达梦很少能满足生产环境的灾备要求,而且单机往往测试库用到的比较多,生产环境还是建议搭建主从或者集群,比较稳妥。所以知识储备还是要做好。今天就来冲击一下dm的 主备环境吧,并比较一下,跟Oracle 有啥不通点。
部署规划
主节点1台,备节点1台,监控节点一台,一共规划 3 台虚拟机 搭建,cpu 内存 4核4G 就够了,幸好,不像tidb 那样,一出手就要几十G 内存,让我们难以在自己的笔记本上模拟,所以达梦这样的配置,还是利于入门的:
规划
安装,初始化之类的操作一顿搞
安装
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g’ /etc/selinux/config
vi /etc/security/limits.conf
dmdba soft nice 0
dmdba hard nice 0
dmdba soft as unlimited
dmdba hard as unlimited
dmdba soft fsize unlimited
dmdba hard fsize unlimited
dmdba soft nproc 65536
dmdba hard nproc 65536
dmdba soft nofile 65536
dmdba hard nofile 65536
dmdba soft core unlimited
dmdba hard core unlimited
dmdba soft data unlimited
dmdba hard data unlimited
vi /etc/sysctl.conf
fs.file-max = 6815744
fs.aio-max-nr = 1048576
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
vm.swappiness = 10
vm.dirty_background_ratio = 0
vm.dirty_ratio = 80
vm.dirty_expire_centisecs = 500
vm.dirty_writeback_centisecs = 100
使内核参数生效:
sysctl -p
创建安装用户和组
groupadd -g 10000 dinstall
useradd -u 10001 -g dinstall -m -d /home/dmdba dmdba
echo “123456”|passwd –stdin dmdba
mkdir -p /data/dmdata
mkdir -p /home/dmdba/dmdbms
mkdir -p /dmarch
mkdir -p /dmbak
chown -R dmdba:dinstall /data/dmdata
chown -R dmdba:dinstall /home/dmdba/dmdbms
chown -R dmdba:dinstall /dmarch
chown -R dmdba:dinstall /dmbak
mount -o loop dm8_xxx.iso /mnt
cp /mnt/DMInstall.bin /home/dmdba
chown -R dmdba:dinstall /home/dmdba/DMInstall.bin
su – dmdba
[dmdba@localhost ~]$ ./DMInstall.bin -i
root
/home/dmdba/dmdbms/script/root/root_installer.sh
primary初始化数据
/home/dmdba/dmdbms/bin/dminit path=/data/dmdata page_size=16 extent_size=32 log_size=500 charset=0 case_sensitive=1 length_in_char=0 db_name=dm01
log:
initdb V8
db version: 0x7000c
License will expire on 2022-12-25
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
log file path: /data/dmdata/dm01/dm0101.log
log file path: /data/dmdata/dm01/dm0102.log
write to dir [/data/dmdata/dm01].
create dm database success. 2022-07-05 08:35:47
启动实例
以系统服务方式启动实例,DM 提供脚本将数据库实例注册为操作系统服务。
root 用户下切换到 /home/dmdba/dmdbms/script/root/:
./dm_service_installer.sh -t dmserver -p dm01 -dm_ini /data/dmdata/dm01/dm.ini
[root@primary root]# ./dm_service_installer.sh -t dmserver -p dm01 -dm_ini /data/dmdata/dm01/dm.ini
Created symlink from /etc/systemd/system/multi-user.target.wants/DmServicedm01.service to /usr/lib/systemd/system/DmServicedm01.service.
Finished to create the service (DmServicedm01)
启动 systemctl start DmServicedm01
尝试登录
查阅资料得知,因为在dm安全版中默认开启了SSL加密,所以需要关闭:
SQL> sp_set_para_value(2,‘ENABLE_ENCRYPT’,0);
执行完之后需要重启数据库才能生效。
./DmServicedm01 stop
./DmServicedm01 start
建表,模拟操作 写数据
create table test1 ( snum int );
insert into test1 values (1 );
insert into test1 values (2 );
commit;
primary 开启归档
alter database mount;
alter database add archivelog ‘dest=/dmarch,TYPE=local,FILE_SIZE=1024,SPACE_LIMIT=102400’;
alter database archivelog;
alter database open;
standby 库 也要初始化 ,生成目录结构,控制文件之类的
/home/dmdba/dmdbms/bin/dminit path=/data/dmdata page_size=16 extent_size=32 log_size=500 charset=0 case_sensitive=1 length_in_char=0 db_name=dm01
确认主库 DMAP 服务已启动,执行以下命令:
ps -ef|grep dmap
以下内容开始 搞事情了,在安装完,初始化,写数据,开归档后,正式开始 搭建备份
主库脱机备份
—这个动作我比较吐槽,搭建主备 还有申请时间停机操作呢
停机
dmrman 工具备份主库
./dmrman
backup database ‘/data/dmdata/dm01/dm.ini’ backupset ‘/dmbak/dm01_full’;
传输到 备库 吧,备份 很需要 这份 东西,救命!!!!
scp -r /dmbak/dm01_full root@192.168.118.131:/dmbak —- 传输后 主库还是关闭状态
备库接受到文件后,要做还原数据的操作了,同样也要关闭数据库实例的(初始化后未启动过)
chown -R dmdba.dinstall /dmbak/dm01_full
使用 dmrman 工具还原备库执行 restore。
check backupset ‘/dmbak/dm01_full’;
restore database ‘/data/dmdata/dm01/dm.ini’ from backupset ‘/dmbak/dm01_full’;
recover database ‘/data/dmdata/dm01/dm.ini’ from backupset ‘/dmbak/dm01_full’;
更新db_magic
recover database ‘/data/dmdata/dm01/dm.ini’ update db_magic;
到这步为止, 主备的数据一致了,接下来 是 配置 日志传输,保持同步之类的设置
关键文件
修改主备实例的达梦dm.ini,dmmal.ini,dmarch.ini,dmwatcher.ini文件参数,执行以下命令:
vi /data/dmdata/dm01/dm.ini
primary
dm.ini
INSTANCE_NAME = dm01
PORT_NUM = 5246
DW_INACTIVE_INTERVAL = 60
ALTER_MODE_STATUS = 0
ENABLE_OFFLINE_TS = 2
MAL_INI = 1
ARCH_INI = 1
RLOG_SEND_APPLY_MON = 64
vi /data/dmdata/dm01/dmmal.ini
dmmal.ini
MAL_CHECK_INTERVAL = 5
MAL_CONN_FAIL_INTERVAL = 5
[MAL_INST1]
MAL_INST_NAME = dm01
MAL_HOST = 192.168.118.123
MAL_PORT = 55101
MAL_INST_HOST = 192.168.118.123
MAL_INST_PORT = 5246
MAL_DW_PORT = 65101
MAL_INST_DW_PORT = 45101
[MAL_INST2]
MAL_INST_NAME = dm02
MAL_HOST = 192.168.118.131
MAL_PORT = 55121
MAL_INST_HOST = 192.168.118.131
MAL_INST_PORT = 5246
MAL_DW_PORT = 65121
MAL_INST_DW_PORT = 45121
vi /data/dmdata/dm01/dmarch.ini
dmarch.ini
[ARCHIVE_REALTIME]
ARCH_TYPE = REALTIME
ARCH_DEST = dm02
/*[ARCHIVE_LOCAL1]
ARCH_TYPE = LOCAL
ARCH_DEST = /dm8/arch
ARCH_FILE_SIZE = 128
ARCH_SPACE_LIMIT = 0 */
vi /data/dmdata/dm01/dmwatcher.ini
dmwatcher.ini
[GRP1]
DW_TYPE = GLOBAL
DW_MODE = AUTO
DW_ERROR_TIME = 10
INST_RECOVER_TIME = 60
INST_ERROR_TIME = 10
INST_OGUID = 453331
INST_INI = /data/dmdata/dm01/dm.ini
INST_AUTO_RESTART = 1
INST_STARTUP_CMD = /home/dmdba/dmdbms/bin/dmserver
RLOG_SEND_THRESHOLD = 0
RLOG_APPLY_THRESHOLD = 0
备库修改以下参数值:
standby
vi /data/dmdata/dm01/dm.ini
dm.ini
INSTANCE_NAME = dm02
PORT_NUM = 5246
DW_INACTIVE_INTERVAL = 60
ALTER_MODE_STATUS = 0
ENABLE_OFFLINE_TS = 2
MAL_INI = 1
ARCH_INI = 1
RLOG_SEND_APPLY_MON = 64
vi /data/dmdata/dm01/dmmal.ini
dmmal.ini
MAL_CHECK_INTERVAL = 5
MAL_CONN_FAIL_INTERVAL = 5
[MAL_INST1]
MAL_INST_NAME = dm01
MAL_HOST = 192.168.118.123
MAL_PORT = 55101
MAL_INST_HOST = 192.168.118.123
MAL_INST_PORT = 5246
MAL_DW_PORT = 65101
MAL_INST_DW_PORT = 45101
[MAL_INST2]
MAL_INST_NAME = dm02
MAL_HOST = 192.168.118.131
MAL_PORT = 55121
MAL_INST_HOST = 192.168.118.131
MAL_INST_PORT = 5246
MAL_DW_PORT = 65121
MAL_INST_DW_PORT = 45121
vi /data/dmdata/dm01/dmarch.ini
dmarch.ini
[ARCHIVE_REALTIME]
ARCH_TYPE = REALTIME
ARCH_DEST = dm01
[ARCHIVE_LOCAL1]
ARCH_TYPE = LOCAL
ARCH_DEST = /dmarch
ARCH_FILE_SIZE = 128
ARCH_SPACE_LIMIT = 0
vi /data/dmdata/dm01/dmwatcher.ini
dmwatcher.ini
[GRP1]
DW_TYPE = GLOBAL
DW_MODE = AUTO
DW_ERROR_TIME = 10
INST_RECOVER_TIME = 60
INST_ERROR_TIME = 10
INST_OGUID = 453331
INST_INI = /data/dmdata/dm01/dm.ini
INST_AUTO_RESTART = 1
INST_STARTUP_CMD = /home/dmdba/dmdbms/bin/dmserver
RLOG_APPLY_THRESHOLD = 0
INST_OGUID —一个重要的数字
操作顺序总结
先主后备,都mount
启动主库
./dmserver /data/dmdata/dm01/dm.ini mount (前台启动)
另开窗口执行
disql sysdba/SYSDBA@localhost:5246
SQL>SP_SET_PARA_VALUE(1, ‘ALTER_MODE_STATUS’, 1);
SQL>sp_set_oguid(453331);
SQL>alter database primary;
SQL>SP_SET_PARA_VALUE(1, ‘ALTER_MODE_STATUS’, 0);
以 Mount 方式启动备库
./dmserver /data/dmdata/dm01/dm.ini mount (前台启动)
另开窗口执行
disql sysdba/SYSDBA@localhost:5246
SQL>SP_SET_PARA_VALUE(1, ‘ALTER_MODE_STATUS’, 1);
SQL>sp_set_oguid(453331);
SQL>alter database standby;
SQL>SP_SET_PARA_VALUE(1, ‘ALTER_MODE_STATUS’, 0);
启动守护进程
dmdba 用户下,到数据库安装目录的 bin 下执行(主备库都执行)。
主
dmwatcher /data/dmdata/dm01/dmwatcher.ini (前台启动)
备
dmwatcher /data/dmdata/dm01/dmwatcher.ini (前台启动)
守护进程启动后,会将 Mount 的实例 Open。
部署监控服务器收尾
监控服务器(只安装dm 软件)
vi /data/dmdata/mon/dmmonitor.ini
MON_DW_CONFIRM = 1
MON_LOG_PATH = /data/dmdata/mon/log
MON_LOG_INTERVAL = 60
MON_LOG_FILE_SIZE = 32
MON_LOG_SPACE_LIMIT = 0
[GRP1]
MON_INST_OGUID = 453331
MON_DW_IP = 192.168.118.123:65101
MON_DW_IP = 192.168.118.131:65121
启动监视器,执行以下命令:
/home/dmdba/dmdbms/bin/dmmonitor /data/dmdata/mon/dmmonitor.ini
启动后输入 show 命令查看集群状态。
测试主库
测试备库
以上启动为前台方式启动,仅用户搭建过程中验证配置。配置没问题后需要将实例,守护进程和确认监视器注册为系统服务。使用 root 用户,到数据库安装目录的 script/root 下,执行。
cd /home/dmdba/dmdbms/script/root/
注册守护进程服务(主备库都执行)。
./dm_service_installer.sh -t dmwatcher -p watch01 -watcher_ini /data/dmdata/dm01/dmwatcher.ini
./dm_service_installer.sh -t dmwatcher -p watch02 -watcher_ini /data/dmdata/dm01/dmwatcher.ini
注册数据库实例服务(主备库都执行)。
./dm_service_installer.sh -t dmserver -p dm01 -dm_ini /data/dmdata/dm01/dm.ini –已注册
./dm_service_installer.sh -t dmserver -p dm02 -dm_ini /data/dmdata/dm01/dm.in
注册监视器服务(只需在监视器服务器上执行),执行以下命令:
./dm_service_installer.sh -t dmmonitor -p monitor -monitor_ini /data/dmdata/mon/dmmonitor.ini
以服务方式启动
启动数据库实例,执行以下命令:
[root@localhost data]# systemctl start DmServiceddm01
启动守护进程,执行以下命令:
[root@localhost data]# systemctl start DmWatcherServicewatch01
启动监视器,执行以下命令:
[root@localhost data]# systemctl start DmMonitorServmonitor
这时,你无法登录监视器了,因为监视器没提供端口给你访问
如果设置的是确认监视器(确认监视器只能启动一个)并且已经启动了,
那么可以配置一个非确认监视器进行查看各节点状态,使用
/home/dmdba/dmdbms/bin/dmmonitor /data/dmdata/mon/dmmonitor2.ini
命令进行查看
cat /data/dmdata/mon/dmmonitor2.ini
主备集群重启有顺序要求:
关闭监视器:systemctl stop DmMonitorServmonitor
关闭主库守护进程:systemctl stop DmWatcherServicewatch01
关闭备库守护进程:systemctl stop DmWatcherServicewatch02
关闭主库实例:systemctl stop DmServiceddm01
关闭备库实例:systemctl stop DmServiceddm02
启动主库实例:systemctl start DmServiceddm01
启动备库实例:systemctl start DmServiceddm02
启动主库守护进程:systemctl start DmWatcherServicewatch01
启动备库守护进程:systemctl start DmWatcherServicewatch02
启动监视器:systemctl start DmMonitorServmonitor
与oracle 的 dataguard 比较一下
1 搭建备库过程中需要关闭数据库
2 搭建过程未出现有密码验证阶段
3 搭建过程比 oracle 需要 更多的端口以及配置文件
待续 。。。。。。。。