注册
达梦8守护集群搭建分享
专栏/培训园地/ 文章详情 /

达梦8守护集群搭建分享

沉默是金 2024/01/30 853 0 0
摘要

一 环境规划:

--1.1 主机规划

主库:192.168.56.11 (dm8node1)
备库:192.168.56.12 (dm8node2)
监视器:192.168.56.15 (dwmon)

数据库名:DMDW
实例名: DMDW1/DMDW2

--1.2 端口规划

实例名(INS_NAME) 端口号(PORT_NUM) 守护主机IP(MAL_HOST) 守护主机端口(MAL_PORT) 守护本地监听端口(MAL_DW_PORT) 守护实例监听端口(MAL_INST_DW_PORT)
DMDW1 5236 192.168.56.11 5237 5238 5239
DMDW2 5236 192.168.56.12 5237 5238 5239

二 数据库软件安装

(略)

三 主库初始化并备份

--3.1 主库初始化
su - dmdba
dminit path=/dm8/dmdbms/ DB_NAME=DMDW INSTANCE_NAME=DMDW1 PORT_NUM=5236

initdb V8
db version: 0x7000c
file dm.key not found, use default license!
License will expire on 2024-11-08
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL

log file path: /dm8/dmdbms/DMDW/DMDW01.log

log file path: /dm8/dmdbms/DMDW/DMDW02.log

write to dir [/dm8/dmdbms/DMDW].
create dm database success. 2024-01-20 13:40:31

--3.2 主库注册服务并启动

--注册服务
/dm8/dmdbms/script/root/dm_service_installer.sh -t dmserver -dm_ini /dm8/dmdbms/DMDW/dm.ini -p DMDW

Created symlink /etc/systemd/system/multi-user.target.wants/DmServiceDMDW.service → /usr/lib/systemd/system/DmServiceDMDW.service.
创建服务(DmServiceDMDW)完成

--服务启动实例
service DmSerivceDMDW start

--3.3 主库备份并传输到备库
service DmServiceDMDW stop
su - dmdba
mkdir /dm8/backup
dmrman ctlstmt="backup database '/dm8/dmdbms/DMDW/dm.ini' backupset '/dm8/backup'"

dmrman V8
backup database '/dm8/dmdbms/DMDW/dm.ini' backupset '/dm8/backup'
file dm.key not found, use default license!
Database mode = 0, oguid = 0
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
EP[0]'s cur_lsn[41653], file_lsn[41653]
Processing backupset /dm8/backup
[Percent:100.00%][Speed:0.00M/s][Cost:00:00:02][Remaining:00:00:00]
backup successfully!
time used: 00:00:03.220

scp /dm8/backup/* 192.168.56.12:/dm8/backup/

四 备库初始化

su - dmdba
mkdir /dm8/dmdbms/arch
dminit path=/dm8/dmdbms/ DB_NAME=DMDW INSTANCE_NAME=DMDW2 PORT_NUM=5236

五 主备参数配置

--4.1 配置dm.ini

INSTANCE_NAME=DMDW1
PORT_NUM=5236
ALTER_MODE_STATUS=0
ENABLE_OFFLINE_TS=2
MAL_INI=1
ARCH_INI=1

--4.2 配置dmmal.ini

MAL_CHECK_INTERVAL=5
MAL_CONN_FAIL_INTERVAL=5
[MAL_INST1]
MAL_INST_NAME=DMDW1
MAL_HOST=192.168.56.11
MAL_PORT=5237
MAL_INST_HOST=192.168.56.11
MAL_INST_PORT=5236
MAL_DW_PORT=5238
MAL_INST_DW_PORT=5239
[MAL_INST2]
MAL_INST_NAME=DMDW2
MAL_HOST=192.168.56.12
MAL_PORT=5237
MAL_INST_HOST=192.168.56.12
MAL_INST_PORT=5236
MAL_DW_PORT=5238
MAL_INST_DW_PORT=5239

--4.3 配置dmarch.ini

[ARCHIVE_REALTIME]
ARCH_TYPE=REALTIME
ARCH_DEST=DMDW2
[ARCHIVE_LOCAL1]
ARCH_TYPE=LOCAL
ARCH_DEST=/dm8/dmdbms/arch
ARCH_FILE_SIZE=128
ARCH_SPACE_LIMIT=0

--4.4 配置dmwatcher.ini

[GRP1]
DW_TYPE = GLOBAL
DW_MODE = AUTO
DW_ERROR_TIME = 10
INST_RECOVER_TIME = 60
INST_ERROR_TIME = 10
INST_OGUID = 8888
INST_INI = /dm8/dmdbms/DMDW/dm.ini
INST_AUTO_RESTART = 1
INST_STARTUP_CMD = /dm8/dmdbms/bin/dmserver
RLOG_SEND_THRESHOLD = 0
RLOG_APPLY_THRESHOLD = 0

--4.5 参数拷贝到备库并修改

scp /dm8/dmdbms/DMDW/dmmal.ini /dm8/dmdbms/DMDW/dmarch.ini /dm8/dmdbms/DMDW/dmwatcher.ini 192.168.56.12:/dm8/dmdbms/DMDW/

dm.ini: INSTANCE_NAME=DMDW2
dmarch.ini: ARCH_DEST=DMDW2

六 恢复备库

su - dmdba
ls -lth /dm8/backup
dmrman ctlstmt="restore database '/dm8/dmdbms/DMDW/dm.ini' from backupset '/dm8/backup'"
dmrman ctlstmt="recover database '/dm8/dmdbms/DMDW/dm.ini' from backupset '/dm8/backup'"
dmrman ctlstmt="recover database '/dm8/dmdbms/DMDW/dm.ini' update db_magic"

七 主备库修改OGUID和主备模式

--7.1 主备启动到mount状态

dmserver /dm8/dmdbms/DMDW/dm.ini mount

--7.2 主库修改OGUID和PRIMARY
disql SYSDBA/SYSDBA
SP_SET_PARA_VALUE(1,'ALTER_MODE_STATUS',1);
sp_set_oguid(8888);
alter database primary;
SP_SET_PARA_VALUE(1,'ALTER_MODE_STATUS',0);

--7.3 备库修改OGUID和STANDBY
disql SYSDBA/SYSDBA
SP_SET_PARA_VALUE(1,'ALTER_MODE_STATUS',1);
sp_set_oguid(8888);
alter database standby;
SP_SET_PARA_VALUE(1,'ALTER_MODE_STATUS',0);

八 启动主备库守护进程

--前台启动
dmwatcher /dm8/dmdbms/DMDW/dmwatcher.ini

DMWATCHER[4.0] V8
DMWATCHER[4.0] IS READY

tail -100 /dm8/dmdbms/log/dm_dmwatcher_DMDW1_202401.log

--查看数据库状态转换(主库/备库打开)

[dmdba@dw8node1 ~]$ disql SYSDBA/SYSDBA

服务器[LOCALHOST:5236]:处于主库打开状态
登录使用时间 : 2.230(ms)
disql V8
SQL>

[dmdba@dw8node2 ~]$ disql SYSDBA/SYSDBA

服务器[LOCALHOST:5236]:处于备库打开状态
登录使用时间 : 3.303(ms)
disql V8
SQL>

九 配置启动监视器

--9.1 配置参数dmmonitor.ini

su - dmdba
mkdir /dm8/monitor/log

vi /dm8/monitor/dmmonitor.ini
--dmmonitor.ini
MON_DW_CONFIRM=1
MON_LOG_PATH=/dm8/monitor/log
MON_LOG_INTERVAL=60
MON_LOG_FILE_SIZE=32
MON_LOG_SPACE_LIMIT=0
[GRP1]
MON_INST_OGUID=8888
MON_DW_IP=192.168.56.11:5239
MON_DW_IP=192.168.56.12:5239

--9.2 启动监视器

dmmonitor /dm8/monitor/dmmonitor.ini

[monitor] 2024-01-20 15:56:47: DMMONITOR[4.0] V8
[monitor] 2024-01-20 15:56:48: DMMONITOR[4.0] IS READY.

[monitor] 2024-01-20 15:56:48:
#--------------------------------------------------------------------------------#
GET MONITOR CONNECT INFO FROM DMWATCHER(DMDW1), THE FIRST LINE IS SELF INFO.

DW_CONN_TIME MON_CONFIRM MID MON_IP MON_VERSION
2024-01-20 15:56:48 TRUE 1947372224 ::ffff:192.168.56.15 DMMONITOR[4.0] V8

#--------------------------------------------------------------------------------#

[monitor] 2024-01-20 15:56:48: 收到守护进程(DMDW1)消息
WTIME WSTATUS INST_OK INAME ISTATUS IMODE RSTAT N_OPEN FLSN CLSN
2024-01-20 15:56:48 OPEN OK DMDW1 OPEN PRIMARY VALID 3 41821 41821

[monitor] 2024-01-20 15:56:49: 收到守护进程(DMDW2)消息
WTIME WSTATUS INST_OK INAME ISTATUS IMODE RSTAT N_OPEN FLSN CLSN
2024-01-20 15:56:49 OPEN OK DMDW2 OPEN STANDBY VALID 3 41821 41821

--此界面直接登录查看状态:
login
用户名:SYSDBA
密码:
[monitor] 2024-01-20 16:00:14: 登录监视器成功!

SHOW

2024-01-20 16:00:17
#================================================================================#
GROUP OGUID MON_CONFIRM MODE MPP_FLAG
GRP1 8888 TRUE AUTO FALSE

<>
DW_IP MAL_DW_PORT WTIME WTYPE WCTLSTAT WSTATUS INAME INST_OK N_EP N_OK ISTATUS IMODE DSC_STATUS RTYPE RSTAT
192.168.56.11 5238 2024-01-20 16:00:16 GLOBAL VALID OPEN DMDW1 OK 1 1 OPEN PRIMARY DSC_OPEN REALTIME VALID

EP INFO:
INST_IP INST_PORT INST_OK INAME ISTATUS IMODE DSC_SEQNO DSC_CTL_NODE RTYPE RSTAT FSEQ FLSN CSEQ CLSN DW_STAT_FLAG
192.168.56.11 5236 OK DMDW1 OPEN PRIMARY 0 0 REALTIME VALID 4835 41823 4835 41823 NONE

<>
DW_IP MAL_DW_PORT WTIME WTYPE WCTLSTAT WSTATUS INAME INST_OK N_EP N_OK ISTATUS IMODE DSC_STATUS RTYPE RSTAT
192.168.56.12 5238 2024-01-20 16:00:16 GLOBAL VALID OPEN DMDW2 OK 1 1 OPEN STANDBY DSC_OPEN REALTIME VALID

EP INFO:
INST_IP INST_PORT INST_OK INAME ISTATUS IMODE DSC_SEQNO DSC_CTL_NODE RTYPE RSTAT FSEQ FLSN CSEQ CLSN DW_STAT_FLAG
192.168.56.12 5236 OK DMDW2 OPEN STANDBY 0 0 REALTIME VALID 4835 41823 4835 41823 NONE

DATABASE(DMDW2) APPLY INFO FROM (DMDW1), REDOS_PARALLEL_NUM (1), WAIT_APPLY[FALSE]:
DSC_SEQNO[0], (RSEQ, SSEQ, KSEQ)[4835, 4835, 4835], (RLSN, SLSN, KLSN)[41823, 41823, 41823], N_TSK[0], TSK_MEM_USE[0]
REDO_LSN_ARR: (41823)

#================================================================================#

--主备切换
Switchover

[monitor] 2024-01-20 16:10:18: 开始切换实例DMDW2
[monitor] 2024-01-20 16:10:18: 通知守护进程DMDW1切换SWITCHOVER状态
[monitor] 2024-01-20 16:10:18: 守护进程(DMDW1)状态切换 [OPEN-->SWITCHOVER]
[monitor] 2024-01-20 16:10:19: 切换守护进程DMDW1为SWITCHOVER状态成功
[monitor] 2024-01-20 16:10:19: 通知守护进程DMDW2切换SWITCHOVER状态
[monitor] 2024-01-20 16:10:19: 守护进程(DMDW2)状态切换 [OPEN-->SWITCHOVER]
[monitor] 2024-01-20 16:10:20: 切换守护进程DMDW2为SWITCHOVER状态成功
[monitor] 2024-01-20 16:10:20: 实例DMDW1开始执行SP_SET_GLOBAL_DW_STATUS(0, 6)语句
[monitor] 2024-01-20 16:10:21: 实例DMDW1执行SP_SET_GLOBAL_DW_STATUS(0, 6)语句成功
[monitor] 2024-01-20 16:10:21: 实例DMDW2开始执行SP_SET_GLOBAL_DW_STATUS(0, 6)语句
[monitor] 2024-01-20 16:10:21: 实例DMDW2执行SP_SET_GLOBAL_DW_STATUS(0, 6)语句成功
[monitor] 2024-01-20 16:10:21: 实例DMDW1开始执行ALTER DATABASE MOUNT语句
[monitor] 2024-01-20 16:10:21: 实例DMDW1执行ALTER DATABASE MOUNT语句成功
[monitor] 2024-01-20 16:10:21: 实例DMDW2开始执行SP_APPLY_KEEP_PKG()语句
[monitor] 2024-01-20 16:10:22: 实例DMDW2执行SP_APPLY_KEEP_PKG()语句成功
[monitor] 2024-01-20 16:10:22: 实例DMDW2开始执行ALTER DATABASE MOUNT语句
[monitor] 2024-01-20 16:10:22: 实例DMDW2执行ALTER DATABASE MOUNT语句成功
[monitor] 2024-01-20 16:10:22: 实例DMDW1开始执行ALTER DATABASE STANDBY语句
[monitor] 2024-01-20 16:10:23: 实例DMDW1执行ALTER DATABASE STANDBY语句成功
[monitor] 2024-01-20 16:10:23: 实例DMDW2开始执行ALTER DATABASE PRIMARY语句
[monitor] 2024-01-20 16:10:24: 实例DMDW2执行ALTER DATABASE PRIMARY语句成功
[monitor] 2024-01-20 16:10:24: 通知实例DMDW2修改所有归档状态无效
[monitor] 2024-01-20 16:10:24: 修改所有实例归档为无效状态成功
[monitor] 2024-01-20 16:10:24: 实例DMDW1开始执行ALTER DATABASE OPEN FORCE语句
[monitor] 2024-01-20 16:10:24: 实例DMDW1执行ALTER DATABASE OPEN FORCE语句成功
[monitor] 2024-01-20 16:10:24: 实例DMDW2开始执行ALTER DATABASE OPEN FORCE语句
[monitor] 2024-01-20 16:10:26: 实例DMDW2执行ALTER DATABASE OPEN FORCE语句成功
[monitor] 2024-01-20 16:10:26: 实例DMDW1开始执行SP_SET_GLOBAL_DW_STATUS(6, 0)语句
[monitor] 2024-01-20 16:10:26: 实例DMDW1执行SP_SET_GLOBAL_DW_STATUS(6, 0)语句成功
[monitor] 2024-01-20 16:10:26: 实例DMDW2开始执行SP_SET_GLOBAL_DW_STATUS(6, 0)语句
[monitor] 2024-01-20 16:10:26: 实例DMDW2执行SP_SET_GLOBAL_DW_STATUS(6, 0)语句成功
[monitor] 2024-01-20 16:10:26: 通知守护进程DMDW1切换OPEN状态
[monitor] 2024-01-20 16:10:26: 守护进程(DMDW1)状态切换 [SWITCHOVER-->OPEN]
[monitor] 2024-01-20 16:10:27: 切换守护进程DMDW1为OPEN状态成功
[monitor] 2024-01-20 16:10:27: 通知守护进程DMDW2切换OPEN状态
[monitor] 2024-01-20 16:10:27: 守护进程(DMDW2)状态切换 [SWITCHOVER-->OPEN]
[monitor] 2024-01-20 16:10:28: 切换守护进程DMDW2为OPEN状态成功
[monitor] 2024-01-20 16:10:28: 通知组(GRP1)的守护进程执行清理操作
[monitor] 2024-01-20 16:10:28: 清理守护进程(DMDW1)请求成功
[monitor] 2024-01-20 16:10:28: 清理守护进程(DMDW2)请求成功
[monitor] 2024-01-20 16:10:28: 实例DMDW2切换成功

2024-01-20 16:10:28
#================================================================================#
GROUP OGUID MON_CONFIRM MODE MPP_FLAG
GRP1 8888 TRUE AUTO FALSE

<>
DW_IP MAL_DW_PORT WTIME WTYPE WCTLSTAT WSTATUS INAME INST_OK N_EP N_OK ISTATUS IMODE DSC_STATUS RTYPE RSTAT
192.168.56.12 5238 2024-01-20 16:10:28 GLOBAL VALID OPEN DMDW2 OK 1 1 OPEN PRIMARY DSC_OPEN REALTIME VALID

EP INFO:
INST_IP INST_PORT INST_OK INAME ISTATUS IMODE DSC_SEQNO DSC_CTL_NODE RTYPE RSTAT FSEQ FLSN CSEQ CLSN DW_STAT_FLAG
192.168.56.12 5236 OK DMDW2 OPEN PRIMARY 0 0 REALTIME VALID 4842 42009 4842 42009 NONE

<>
DW_IP MAL_DW_PORT WTIME WTYPE WCTLSTAT WSTATUS INAME INST_OK N_EP N_OK ISTATUS IMODE DSC_STATUS RTYPE RSTAT
192.168.56.11 5238 2024-01-20 16:10:28 GLOBAL VALID OPEN DMDW1 OK 1 1 OPEN STANDBY DSC_OPEN REALTIME INVALID

EP INFO:
INST_IP INST_PORT INST_OK INAME ISTATUS IMODE DSC_SEQNO DSC_CTL_NODE RTYPE RSTAT FSEQ FLSN CSEQ CLSN DW_STAT_FLAG
192.168.56.11 5236 OK DMDW1 OPEN STANDBY 0 0 REALTIME INVALID 4840 41824 4840 41824 NONE

DATABASE(DMDW1) APPLY INFO FROM (DMDW2), REDOS_PARALLEL_NUM (1), WAIT_APPLY[FALSE]:
DSC_SEQNO[0], (RSEQ, SSEQ, KSEQ)[4840, 4840, 4840], (RLSN, SLSN, KLSN)[41824, 41824, 41824], N_TSK[0], TSK_MEM_USE[0]
REDO_LSN_ARR: (41824)

#================================================================================#

[monitor] 2024-01-20 16:10:30: 守护进程(DMDW2)状态切换 [OPEN-->RECOVERY]
WTIME WSTATUS INST_OK INAME ISTATUS IMODE RSTAT N_OPEN FLSN CLSN
2024-01-20 16:10:30 RECOVERY OK DMDW2 OPEN PRIMARY VALID 4 42009 42009

[monitor] 2024-01-20 16:10:32: 守护进程(DMDW2)状态切换 [RECOVERY-->OPEN]
WTIME WSTATUS INST_OK INAME ISTATUS IMODE RSTAT N_OPEN FLSN CLSN
2024-01-20 16:10:32 OPEN OK DMDW2 OPEN PRIMARY VALID 4 42009 42009

十 数据同步测试

--10.1 主库创建测试数据
create user test identified by Test123456;
create table t1(id int,name varchar(30));
insert into t1 values(1,'aaa');
insert into t1 values(2,'bbb');
commit;
select * from t1;
 
--10.2 备库检查验证数据
select username from dba_users where username='TEST';
select * from t1;

--10.3 监视器做SWITCHOVER

--10.4 主库新增测试数据
insert into t1 values(3,'ccc');
insert into t1 values(4,'ddd');
commit;
select * from t1;
 
--10.5 备库检查验证数据
select * from t1;

十一 守护进程和数据库实例服务注册

--12.1 注册守护进程服务
/dm8/dmdbms/script/root/dm_service_installer.sh -t dmwatcher -watcher_ini /dm8/dmdbms/DMDW/dmwatcher.ini -p DMDW

--12.2 注册实例服务
/dm8/dmdbms/script/root/dm_service_installer.sh -t dmserver -dm_ini /dm8/dmdbms/DMDW/dm.ini -p DMDW

ls -lth /dm8/dmdbms/bin/Dm*
-rwxr-xr-x 1 dmdba dinstall 15K 1月 20 16:24 /dm8/dmdbms/bin/DmWatcherServiceDMDW
-rwxr-xr-x 1 dmdba dinstall 18K 1月 20 13:58 /dm8/dmdbms/bin/DmServiceDMDW
-rwxr-xr-x 1 dmdba dinstall 15K 1月 20 12:35 /dm8/dmdbms/bin/DmAPService
-rwxr-xr-x 1 dmdba dinstall 15K 1月 20 12:35 /dm8/dmdbms/bin/DmInstanceMonitorService
-rwxr-xr-x 1 dmdba dinstall 16K 1月 20 12:35 /dm8/dmdbms/bin/DmAuditMonitorService
-rwxr-xr-x 1 dmdba dinstall 15K 1月 20 12:35 /dm8/dmdbms/bin/DmJobMonitorService

十二 服务启动与关闭顺序

--12.1 关闭

1)关闭监视器
2)关闭备库守护进程,再关闭主库守护进程
3)关闭主库实例,再关闭备库实例

--12.2 启动

1)启动主库守护进程,再启动备库守护进程
2)因dmwatcher.ini配置了INST_AUTO_RESTART=1,守护进程会自动拉起数据库实例;

--12.3 服务器重启

先重启主库服务器,在注册守护进程服务和数据库实例服务前提下,主库守护进程和数据库实例会自动启动,且数据库实例是MOUNT配置状态
再重启备份服务器,启动后,主库守护进程和数据库实例会自动启动,数据库实例状态会转为主库/备库打开状态

评论
后发表回复

作者

文章

阅读量

获赞

扫一扫
联系客服