1. 环境描述
实例详情
端口详情
2. 部署步骤
2.1 数据准备
2.1.1主库初始化
[dmdba@ray1 ~]$ cd /dmdba/dmdbms/bin
[dmdba@ray1 bin]$ ./dminit path=/dmdba/data PAGE_SIZE=32 EXTENT_SIZE=32 CASE_SENSITIVE=y CHARSET=1 DB_NAME=GRP1_RT_01 INSTANCE_NAME=GRP1_RT_01 PORT_NUM=32141
initdb V8
db version: 0x7000c
file dm.key not found, use default license!
License will expire on 2025-07-03
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
log file path: /dmdba/data/GRP1_RT_01/GRP1_RT_0101.log
log file path: /dmdba/data/GRP1_RT_01/GRP1_RT_0102.log
write to dir [/dmdba/data/GRP1_RT_01].
create dm database success. 2024-08-16 18:00:23
[dmdba@ray1 ~]$ /dmdba/dmdbms/bin/dmserver /dmdba/data/GRP1_RT_01/dm.ini
2.1.2备库初始化
[dmdba@ray2 ~]$ cd /dmdba/dmdbms/bin
[dmdba@ray2 bin]$ ./dminit path=/dmdba/data PAGE_SIZE=32 EXTENT_SIZE=32 CASE_SENSITIVE=y CHARSET=1 DB_NAME=GRP1_RT_02 INSTANCE_NAME=GRP1_RT_02 PORT_NUM=32142
initdb V8
db version: 0x7000c
file dm.key not found, use default license!
License will expire on 2025-07-03
Normal of FAST
Normal of DEFAULT
Normal of RECYCLE
Normal of KEEP
Normal of ROLL
log file path: /dmdba/data/GRP1_RT_02/GRP1_RT_0201.log
log file path: /dmdba/data/GRP1_RT_02/GRP1_RT_0202.log
write to dir [/dmdba/data/GRP1_RT_02].
create dm database success. 2024-08-16 18:02:13
[dmdba@ray1 ~]$ /dmdba/dmdbms/bin/dmserver /dmdba/data/GRP1_RT_02/dm.ini
2.2备份主库
[dmdba@ray1 ~]$ dmrman
dmrman V8
RMAN> BACKUP DATABASE '/dmdba/data/GRP1_RT_01/dm.ini' FULL TO BACKUP_FILE1 BACKUPSET '/dmdba/dmbak/GRP0816'
BACKUP DATABASE '/dmdba/data/GRP1_RT_01/dm.ini' FULL TO BACKUP_FILE1 BACKUPSET '/dmdba/dmbak/GRP0816'
file dm.key not found, use default license!
Processing backupset /dmdba/dmbak/GRP0816
[Percent:100.00%][Speed:0.00M/s][Cost:00:00:02][Remaining:00:00:00]
backup successfully!
time used: 00:00:03.250
2.3拷贝主库备份集至备机
[dmdba@ray1 ~]$ cd /dmdba/dmbak/
[dmdba@ray1 dmbak]$ ll
total 0
drwxr-xr-x 2 dmdba dmdba 45 Aug 16 15:30 lei0816
[dmdba@ray1 dmbak]$ scp -r lei0816/ 192.168.0.2:/dmdba/dmbak/
2.4备库还原和恢复
[dmdba@ray2 ~]$ dmrman
dmrman V8
RMAN> RESTORE DATABASE '/dmdba/data/GRP1_RT_02/dm.ini' FROM BACKUPSET '/dmdba/dmbak/GRP0816'
RESTORE DATABASE '/dmdba/data/GRP1_RT_02/dm.ini' FROM BACKUPSET '/dmdba/dmbak/GRP0816'
file dm.key not found, use default license!
[Percent:100.00%][Speed:0.00M/s][Cost:00:00:02][Remaining:00:00:00]
restore successfully.
time used: 00:00:02.484
RMAN> RECOVER DATABASE '/dmdba/data/GRP1_RT_02/dm.ini' FROM BACKUPSET '/dmdba/dmbak/GRP0816'
RECOVER DATABASE '/dmdba/data/GRP1_RT_02/dm.ini' FROM BACKUPSET '/dmdba/dmbak/GRP0816'
recover successfully!
time used: 430.147(ms)
RMAN> RECOVER DATABASE '/dmdba/data/GRP1_RT_02/dm.ini' UPDATE DB_MAGIC
RECOVER DATABASE '/dmdba/data/GRP1_RT_02/dm.ini' UPDATE DB_MAGIC
recover successfully!
time used: 00:00:01.074
2.5主库配置dm.ini、dmmal.ini、dmarch.ini
2.5.1主库修改dm.ini
[dmdba@ray1 ~]$ vi /dmdba/data/GRP1_RT_01/dm.ini
添加或修改:
INSTANCE_NAME = GRP1_RT_01
PORT_NUM = 32141
DW_INACTIVE_INTERVAL =60
ALTER_MODE_STATUS = 0
ENABLE_OFFLINE_TS = 2
MAL_INI = 1
ARCH_INI = 1
RLOG_SEND_APPLY_MON = 64
2.5.2主库修改dmmal.ini
[dmdba@ray1 ~]$ vi /dmdba/data/GRP1_RT_01/dmmal.ini
添加:
MAL_CHECK_INTERVAL = 5
MAL_CONN_FAIL_INTERVAL = 5
[MAL_INST1]
MAL_INST_NAME = GRP1_RT_01
MAL_HOST = 10.10.10.1
MAL_PORT = 61141
MAL_INST_HOST = 192.168.0.1
MAL_INST_PORT = 32141
MAL_DW_PORT = 52141
MAL_INST_DW_PORT = 33141
[MAL_INST2]
MAL_INST_NAME = GRP1_RT_02
MAL_HOST = 10.10.10.2
MAL_PORT = 61142
MAL_INST_HOST = 192.168.0.2
MAL_INST_PORT = 32142
MAL_DW_PORT = 52142
MAL_INST_DW_PORT = 33142
2.5.3主库修改dmarch.ini
[dmdba@ray1 ~]$ vi /dmdba/data/GRP1_RT_01/dmarch.ini
添加:
[ARCHIVE_REALTIME]
ARCH_TYPE = REALTIME
ARCH_DEST = GRP1_RT_02
[ARCHIVE_LOCAL1]
ARCH_TYPE = LOCAL
ARCH_DEST = /dmdba/arch/GRP1_RT_01
ARCH_FILE_SIZE = 128
ARCH_SPACE_LIMIT = 0
2.5.4主库修改dmwatcher.ini
[dmdba@ray1 ~]$ vi /dmdba/data/GRP1_RT_01/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 = /dmdba/data/GRP1_RT_01/dm.ini
INST_AUTO_RESTART = 1
INST_STARTUP_CMD = /dmdba/dmdbms/bin/dmserver
RLOG_SEND_THRESHOLD = 0
RLOG_APPLY_THRESHOLD = 0
2.6MOUNT主库
一定要以Mount方式启动数据库实例,否则系统启动时会重构回滚表空间,生成Redo日志。并且,启动后应用可能连接到数据库实例进行操作,破坏主备库的数据一致性。数据守护配置结束后,守护进程会自动Open数据库。
[dmdba@ray1 ~]$ /dmdba/dmdbms/bin/dmserver /dmdba/data/GRP1_RT_01/dm.ini mount
2.7主库设置OGUID
系统通过OGUID值确定一个守护进程组,由用户保证OGUID值的唯一性,并确保数据守护系统中,数据库、守护进程和监视器配置相同的OGUID值。
[dmdba@ray1 ~]$ disql SYSDBA/SYSDBA@192.168.0.1:32141
服务器[192.168.0.1:32141]:处于普通配置状态
登录使用时间 : 2.818(ms)
disql V8
18:39:58 SQL> SP_SET_PARA_VALUE(1, 'ALTER_MODE_STATUS', 1);
DMSQL 过程已成功完成
已用时间: 7.976(毫秒). 执行号:2.
18:40:50 SQL> sp_set_oguid(453331);
DMSQL 过程已成功完成
已用时间: 1.363(毫秒). 执行号:3.
18:40:55 SQL> SP_SET_PARA_VALUE(1, 'ALTER_MODE_STATUS', 0);
DMSQL 过程已成功完成
已用时间: 7.390(毫秒). 执行号:4.
2.8主库修改数据库模式
修改主库模式为PRIMARY。
[dmdba@ray1 ~]$ disql SYSDBA/SYSDBA@192.168.0.1:32141
服务器[192.168.0.1:32141]:处于普通配置状态
登录使用时间 : 2.441(ms)
disql V8
18:44:32 SQL> alter database primary;
操作已执行
已用时间: 6.630(毫秒). 执行号:0.
2.9备库配置dm.ini、dmmal.ini、dmarch.ini
2.9.1备库修改dm.ini
[dmdba@ray2 ~]$ vi /dmdba/data/GRP1_RT_02/dm.ini
添加或修改:
INSTANCE_NAME = GRP1_RT_02
PORT_NUM = 32142
DW_INACTIVE_INTERVAL =60
ALTER_MODE_STATUS = 0
ENABLE_OFFLINE_TS = 2
MAL_INI = 1
ARCH_INI = 1
RLOG_SEND_APPLY_MON = 64
2.9.2备库修改dmmal.ini
[dmdba@ray2 ~]$ vi /dmdba/data/GRP1_RT_02/dmmal.ini
添加:
MAL_CHECK_INTERVAL = 5
MAL_CONN_FAIL_INTERVAL = 5
[MAL_INST1]
MAL_INST_NAME = GRP1_RT_01
MAL_HOST = 10.10.10.1
MAL_PORT = 61141
MAL_INST_HOST = 192.168.0.1
MAL_INST_PORT = 32141
MAL_DW_PORT = 52141
MAL_INST_DW_PORT = 33141
[MAL_INST2]
MAL_INST_NAME = GRP1_RT_02
MAL_HOST = 10.10.10.2
MAL_PORT = 61142
MAL_INST_HOST = 192.168.0.2
MAL_INST_PORT = 32142
MAL_DW_PORT = 52142
MAL_INST_DW_PORT = 33142
2.9.3备库修改dmarch.ini
[dmdba@ray2 ~]$ vi /dmdba/data/GRP1_RT_02/dmarch.ini
添加:
[ARCHIVE_REALTIME]
ARCH_TYPE = REALTIME
ARCH_DEST = GRP1_RT_01
[ARCHIVE_LOCAL1]
ARCH_TYPE = LOCAL
ARCH_DEST = /dmdba/arch/GRP1_RT_02
ARCH_FILE_SIZE = 128
ARCH_SPACE_LIMIT = 0
2.9.4备库修改dmwatcher.ini
[dmdba@ray2 ~]$ vi /dmdba/data/GRP1_RT_02/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 = /dmdba/data/GRP1_RT_02/dm.ini
INST_AUTO_RESTART = 1
INST_STARTUP_CMD = /dmdba/dmdbms/bin/dmserver
RLOG_SEND_THRESHOLD = 0
RLOG_APPLY_THRESHOLD = 0
2.10MOUNT备库
一定要以Mount方式启动数据库实例,否则系统启动时会重构回滚表空间,生成Redo日志。并且,启动后应用可能连接到数据库实例进行操作,破坏主备库的数据一致性。数据守护配置结束后,守护进程会自动Open数据库。
[dmdba@ray2 ~]$ /dmdba/dmdbms/bin/dmserver /dmdba/data/GRP1_RT_02/dm.ini mount
##2.11备库设置OGUID
系统通过OGUID值确定一个守护进程组,由用户保证OGUID值的唯一性,并确保数据守护系统中,数据库、守护进程和监视器配置相同的OGUID值。
[dmdba@ray2 ~]$ disql SYSDBA/SYSDBA@192.168.0.2:32142
服务器[192.168.0.2:32142]:处于普通配置状态
登录使用时间 : 3.223(ms)
disql V8
SQL> SP_SET_PARA_VALUE(1, 'ALTER_MODE_STATUS', 1);
DMSQL 过程已成功完成
已用时间: 8.193(毫秒). 执行号:1.
SQL> sp_set_oguid(453331);
DMSQL 过程已成功完成
已用时间: 1.583(毫秒). 执行号:2.
SQL> SP_SET_PARA_VALUE(1, 'ALTER_MODE_STATUS', 0);
DMSQL 过程已成功完成
已用时间: 6.989(毫秒). 执行号:3.
2.12备库修改数据库模式
修改数据库模式为STANDBY。
[dmdba@ray2 ~]$ disql SYSDBA/SYSDBA@192.168.0.2:32142
服务器[192.168.0.2:32142]:处于普通配置状态
登录使用时间 : 2.461(ms)
disql V8
SQL> alter database standby;
操作已执行
已用时间: 5.541(毫秒). 执行号:0.
2.13配置监视器
修改dmmonitor.ini配置确认监视器,其中MON_DW_IP中的IP和PORT和dmmal.ini中的MAL_HOST和MAL_DW_PORT配置项保持一致。
[dmdba@ray1 ~]$ vi /dmdba/monitor/dmmonitor.ini
添加:
MON_DW_CONFIRM = 1
MON_LOG_PATH = /dmdba/data/log
MON_LOG_INTERVAL = 60
MON_LOG_FILE_SIZE = 32
MON_LOG_SPACE_LIMIT = 0
[GRP1]
MON_INST_OGUID = 453331
MON_DW_IP = 10.10.10.1:52141
MON_DW_IP = 10.10.10.2:52142
2.14启动守护进程
守护进程启动后,进入Startup状态,此时实例都处于Mount状态。守护进程开始广播自身和其监控实例的状态信息,结合自身信息和远程守护进程的广播信息,守护进程将本地实例Open,并切换为Open状态。
2.14.1主库启动守护进程
[dmdba@ray1 ~]$ /dmdba/dmdbms/bin/dmwatcher /dmdba/data/GRP1_RT_01/dmwatcher.ini
DMWATCHER[4.0] V8
DMWATCHER[4.0] IS READY
2.14.2备库启动守护进程
[dmdba@ray2 ~]$ /dmdba/dmdbms/bin/dmwatcher /dmdba/data/GRP1_RT_02/dmwatcher.ini
DMWATCHER[4.0] V8
DMWATCHER[4.0] IS READY
2.15启动监视器
[dmdba@ray1 ~]$ /dmdba/monitor/dmmonitor /dmdba/data/GRP1_RT_01/dmmonitor.ini
3数据同步测试
主库创建测试表,插入数据,检查备库是否有数据生成。
login
用户名:SYSDBA
密码:
如上图,首先查询确认主备库均无t表,连接主库创建t表,并插入5条数据commit,主库查询到数据已经落盘。同时连接备库查询到t表存在,并且数据与主库数据保持一致,数据同步正常。
4主备切换测试
4.1模拟主库主机故障,备库自动接管
[dmdba@ray1 ~]$ dmmonitor /dmdba/monitor/dmmonitor1.ini
show global info
4.1.1关闭主库服务器
[root@ray2 ~]# init 0
[root@ray1 ~]# ping ray2
PING ray2 (192.168.0.2) 56(84) bytes of data.
From ray1 (192.168.0.1) icmp_seq=10 Destination Host Unreachable
From ray1 (192.168.0.1) icmp_seq=11 Destination Host Unreachable
From ray1 (192.168.0.1) icmp_seq=12 Destination Host Unreachable
From ray1 (192.168.0.1) icmp_seq=13 Destination Host Unreachable
From ray1 (192.168.0.1) icmp_seq=14 Destination Host Unreachable
4.1.2查看监视器,备库自动接管服务
主库关闭后监视器显示主库连接超时,备库自动切换为主库。
4.1.3启动原主库,加入集群
启动原主库后,自动加入集群,角色为standby。
4.2手工主备切换
执行手工主备切换测试后,主备角色对调,GRP1_RT_01由standby变为primary,GRP1_RT_02由primary变为standby。