达梦主从部署

软件安装参考:

https://www.cnblogs.com/last-one/p/15148441.html

1. 主从部署

1.1. 备份

使用DMRMAN备份主库。

[dmdba@masterserver bin]$ ./dmrman

RMAN> backup database '/home/dmdba/dmdbms/data/dmdw/dm.ini' full backupset '/home/dmdba/dmdbms/data/fullback';

注意:未开归档,备份需要把数据库安全停止。

1.2. 还原

使用DMRMAN还原备库。

[dmdba@masterserver bin]$ ./dmrman

--还原数据库

RMAN> restore database '/home/dmdba/dmdbms/data/dmdw/dm.ini' from backupset '/home/dmdba/dmdbms/data/fullback';

--恢复数据库

RMAN> recover database '/home/dmdba/dmdbms/data/dmdw/dm.ini' from backupset '/home/dmdba/dmdbms/data/fullback';

 

RMAN> recover database '/home/dmdba/dmdbms/data/dmdw/dm.ini' update db_magic;

 

注意:未开归档,还原需要把数据库安全停止。

1.3. 修改dm.ini文件

ALTER_MODE_STATUS               =  0                    #Whether to permit database user to alter database mode and status by SQLs

                ENABLE_OFFLINE_TS               =  2                    #Whether tablespace can be offline

MAL_INI                         =  1                    #dmmal.ini

ARCH_INI                        =  1                    #dmarch.ini

1.4. 配置dmmal文件(所有节点保持一致)

MAL_CHECK_INTERVAL = 5 #MAL 链路检测时间间隔

MAL_CONN_FAIL_INTERVAL = 5 #判定 MAL 链路断开的时间

[MAL_INST1]

MAL_INST_NAME = dmdw1 #实例名,和 dm.ini 中的 INSTANCE_NAME 一致

MAL_HOST = 192.168.10.141 #MAL 系统监听 TCP 连接的 IP 地址 (内部通信地址)

MAL_PORT = 5237 #MAL 系统监听 TCP 连接的端口

MAL_INST_HOST = 192.168.10.141 #实例的对外服务IP地址 (外部通信)

MAL_INST_PORT = 3333 #实例的对外服务端口和dm.ini中的PORT_NUM一致

MAL_DW_PORT = 5238 #实例本地的守护进程监听 TCP 连接的端口  

MAL_INST_DW_PORT = 33141 #实例监听守护进程TCP连接的端口

[MAL_INST2]

MAL_INST_NAME = dmdw2

MAL_HOST = 192.168.10.140 

MAL_PORT = 5237

MAL_INST_HOST =  192.168.10.140

MAL_INST_PORT = 3333

MAL_DW_PORT = 5238

MAL_INST_DW_PORT = 33142

1.5. 配置归档dmarch.ini文件

[ARCHIVE_REALTIME]

ARCH_TYPE = REALTIME #实时归档类型    (REALTIM:主备,timely:读写分离)

ARCH_DEST = dmdw2 #实时归档目标实例名 远程节点的实例名

 

[ARCHIVE_LOCAL1]

ARCH_TYPE = LOCAL #本地归档类型

ARCH_DEST = /home/dmdba/dmdbms/data/arch #本地归档文件存放路径

ARCH_FILE_SIZE = 128 #单位 Mb,本地单个归档文件最大值

ARCH_SPACE_LIMIT = 0 #单位 Mb0 表示无限制,范围 1024~4294967294M

创建归档目录:

Mkdir /home/dmdba/dmdbms/data/arch

1.6. 配置守护进程dmwatcher.ini

[GRP1]

DW_TYPE = GLOBAL #全局守护类型

DW_MODE = AUTO #自动切换模式

DW_ERROR_TIME = 10 #远程守护进程故障认定时间

INST_RECOVER_TIME = 60 #主库守护进程启动恢复的间隔时间

INST_ERROR_TIME = 10 #本地实例故障认定时间

INST_OGUID = 453331 #守护系统唯一OGUID

INST_INI = /home/dmdba/dmdbms/data/dmdw/dm.ini   #dm.ini配置文件路径

INST_AUTO_RESTART = 1 #打开实例的自动启动功能

INST_STARTUP_CMD = /home/dmdba/dmdbms/bin/dmserver #命令行方式启动

RLOG_SEND_THRESHOLD = 0 #指定主库发送日志到备库的时间阀值,默认关闭

RLOG_APPLY_THRESHOLD = 0 #指定备库重演日志的时间阀值,默认关闭

1.7. 修改数据库信息

1、启动数据库到mount状态

[dmdba@masterserver dmdw]$ /home/dmdba/dmdbms/bin/dmserver /home/dmdba/dmdbms/data/dmdw/dm.ini mount

file dm.key not found, use default license!

version info: develop

Use normal os_malloc instead of HugeTLB

Use normal os_malloc instead of HugeTLB

DM Database Server x64 V8.1.0.147-Build(2019.03.27-104581)ENT  startup...

License will expire on 2021-07-14

ckpt lsn: 36609

ndct db load finished

ndct fill fast pool finished

nsvr_startup end.

aud sys init success.

aud rt sys init success.

systables desc init success.

ndct_db_load_info success.

SYSTEM IS READY.

1、修改数据库的oguid

[dmdba@masterserver bin]$ ./disql sysdba/SYSDBA:3333

 

服务器[LOCALHOST:3333]:处于普通配置状态

登录使用时间: 6.776(毫秒)

disql V8.1.0.147-Build(2019.03.27-104581)ENT

SQL>

SQL>

SQL> sp_set_oguid(453331);

DMSQL 过程已成功完成

已用时间: 40.387(毫秒). 执行号:1.

SQL> alter database primary;     ---主库

SQL> alter database standby;     ---备库

 

 

1.8. 配置监视器dmmonitor.ini 

监视器在主库发生故障时,能够自动通知实时备库接管为新的主库,具有自动故障处理的功能。监视器建议部署在其它非数据库节点的服务器上。

MON_DW_CONFIRM = 1 #确认监视器模式

MON_LOG_PATH = /home/dmdba/dmdbms/data/monitor_log #监视器日志文件存放路径

MON_LOG_INTERVAL = 60 #每隔 60s 定时记录系统信息到日志文件

MON_LOG_FILE_SIZE = 32 #每个日志文件最大 32M

MON_LOG_SPACE_LIMIT = 0 #不限定日志文件总占用空间

 

[GRP1]

MON_INST_OGUID = 453331 #GRP1 的唯一 OGUID #以下配置为监视器到组 GRP1 的守护进程的连接信息,以“IP:PORT”的形式配置

 

#IP 对应 dmmal.ini 中的 MAL_HOSTPORT 对应 dmmal.ini 中的 MAL_DW_PORT

MON_DW_IP = 192.168.10.140:5238

MON_DW_IP = 192.168.10.141:5238

 

1.9. 切换测试

1.9.1. 手工切换

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

 

switchover DMDW2

[monitor]         2021-06-30 16:17:21: 未登录监视器或服务器公钥发生变化,请重新登录!

 

login

用户名:SYSDBA

密码:

[monitor]         2021-06-30 16:17:52: 登录监视器成功!

 

switchover DMDW2

[monitor]         2021-06-30 16:18:04: 开始切换实例DMDW2

[monitor]         2021-06-30 16:18:04: 通知守护进程DMDW1切换SWITCHOVER状态

[monitor]         2021-06-30 16:18:04: 守护进程(DMDW1)状态切换 [OPEN-->SWITCHOVER]

[monitor]         2021-06-30 16:18:04: 切换守护进程DMDW1SWITCHOVER状态成功

.......

 

 

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

 

[monitor]         2021-06-30 16:18:10: 清理守护进程(DMDW1)请求成功

[monitor]         2021-06-30 16:18:10: 实例DMDW2切换成功

 

[monitor]         2021-06-30 16:18:13: 守护进程(DMDW2)状态切换 [OPEN-->RECOVERY]

                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN            

                  2021-06-30 16:18:13  RECOVERY       OK        DMDW2            OPEN        PRIMARY   VALID    5        56702           56702           

 

[monitor]         2021-06-30 16:18:17: 守护进程(DMDW2)状态切换 [RECOVERY-->OPEN]

                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN            

                  2021-06-30 16:18:17  OPEN           OK        DMDW2            OPEN        PRIMARY   VALID    5        56702           56702           

 

show

2021-06-30 16:18:59

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

1.9.2. 模拟故障切换

把主库的服务器关掉。

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

 

[monitor]         2021-06-30 16:22:28: 接收守护进程(DMDW2)消息超时

                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN            

                  2021-06-30 16:22:17  ERROR          OK        DMDW2            OPEN        PRIMARY   VALID    5        56702           56702           

 

[monitor]         2021-06-30 16:22:32: 检测到PRIMARY实例故障,开始对组(GRP1)执行自动接管

 

[monitor]         2021-06-30 16:22:32: 通知组(GRP1)当前活动的守护进程设置MID

[monitor]         2021-06-30 16:22:32: 通知组(GRP1)当前活动的守护进程设置MID成功

[monitor]         2021-06-30 16:22:32: 开始使用实例DMDW1接管

[monitor]         2021-06-30 16:22:32: 通知守护进程DMDW1切换TAKEOVER状态

[monitor]         2021-06-30 16:22:32: 守护进程(DMDW1)状态切换 [OPEN-->TAKEOVER]

[monitor]         2021-06-30 16:22:32: 切换守护进程DMDW1TAKEOVER状态成功

[monitor]         2021-06-30 16:22:32: 实例DMDW1开始执行SP_SET_GLOBAL_DW_STATUS(0, 7)语句

[monitor]         2021-06-30 16:22:32: 实例DMDW1执行SP_SET_GLOBAL_DW_STATUS(0, 7)语句成功

[monitor]         2021-06-30 16:22:32: 实例DMDW1开始执行SP_APPLY_KEEP_BUF()语句

[monitor]         2021-06-30 16:22:32: 实例DMDW1执行SP_APPLY_KEEP_BUF()语句成功

[monitor]         2021-06-30 16:22:32: 实例DMDW1开始执行ALTER DATABASE MOUNT语句

[monitor]         2021-06-30 16:22:34: 实例DMDW1执行ALTER DATABASE MOUNT语句成功

[monitor]         2021-06-30 16:22:34: 实例DMDW1开始执行ALTER DATABASE PRIMARY语句

[monitor]         2021-06-30 16:22:34: 实例DMDW1执行ALTER DATABASE PRIMARY语句成功

[monitor]         2021-06-30 16:22:37: 通知实例DMDW1修改所有归档状态无效

[monitor]         2021-06-30 16:22:37: 修改所有实例归档为无效状态成功

[monitor]         2021-06-30 16:22:37: 通知守护进程(DMDW1)增加CTL记录

[monitor]         2021-06-30 16:22:37: 通知守护进程(DMDW1)增加CTL记录成功

[monitor]         2021-06-30 16:22:37: 实例DMDW1开始执行ALTER DATABASE OPEN FORCE语句

[monitor]         2021-06-30 16:22:39: 实例DMDW1执行ALTER DATABASE OPEN FORCE语句成功

[monitor]         2021-06-30 16:22:39: 实例DMDW1开始执行SP_SET_GLOBAL_DW_STATUS(7, 0)语句

[monitor]         2021-06-30 16:22:39: 实例DMDW1执行SP_SET_GLOBAL_DW_STATUS(7, 0)语句成功

[monitor]         2021-06-30 16:22:39: 通知守护进程DMDW1切换OPEN状态

[monitor]         2021-06-30 16:22:39: 守护进程(DMDW1)状态切换 [TAKEOVER-->OPEN]

[monitor]         2021-06-30 16:22:39: 切换守护进程DMDW1OPEN状态成功

[monitor]         2021-06-30 16:22:39: 通知组(GRP1)的守护进程执行清理操作

[monitor]         2021-06-30 16:22:39: 清理守护进程(DMDW1)请求成功

[monitor]         2021-06-30 16:22:39: 使用实例DMDW1接管成功

 

[monitor]         2021-06-30 16:22:39: (GRP1)使用实例DMDW1自动接管成功

1.9.3. 故障服务器重新添加到集群

手工启动dmwatcher守护进程。通过监视器进程自动把故障服务器添加到集群中。

 

监视器把故障服务器添加到集群,并自动切换为备库添加到集群。

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

 

[monitor]         2021-06-30 16:31:46: 守护进程(DMDW2)状态切换 [NONE-->STARTUP]

[monitor]         2021-06-30 16:32:10: 守护进程(DMDW2)状态切换 [STARTUP-->UNIFY EP]

                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN            

                  2021-06-30 16:32:10  UNIFY EP       OK        DMDW2            MOUNT       PRIMARY   VALID    5        56702           56702           

 

[monitor]         2021-06-30 16:32:10: 守护进程(DMDW2)状态切换 [UNIFY EP-->STARTUP]

                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN            

                  2021-06-30 16:32:10  STARTUP        OK        DMDW2            MOUNT       STANDBY   INVALID  5        56702           56702           

 

[monitor]         2021-06-30 16:32:10: 守护进程(DMDW2)状态切换 [STARTUP-->UNIFY EP]

                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN            

                  2021-06-30 16:32:10  UNIFY EP       OK        DMDW2            MOUNT       STANDBY   INVALID  5        56702           56702           

 

[monitor]         2021-06-30 16:32:11: 守护进程(DMDW2)状态切换 [UNIFY EP-->STARTUP]

                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN            

                  2021-06-30 16:32:11  STARTUP        OK        DMDW2            OPEN        STANDBY   INVALID  5        56702           56702           

 

[monitor]         2021-06-30 16:32:11: 守护进程(DMDW2)状态切换 [STARTUP-->OPEN]

                  WTIME                WSTATUS        INST_OK   INAME            ISTATUS     IMODE     RSTAT    N_OPEN   FLSN            CLSN            

                  2021-06-30 16:32:11  OPEN           OK        DMDW2            OPEN        STANDBY   INVALID  5        56702           56702 

达梦技术社区:https://eco.dameng.com

24小时免费服务热线:400 991 6599

posted @ 2021-08-16 16:27  last_0ne  阅读(535)  评论(0编辑  收藏  举报