DMHS 是达梦的数据同步工具,类似Oracle 的OGG, DMHS 同步服务主要包括四个模块,分别是捕获模块(CPT)、装载模块(LOAD)、传输 模块(NET)以及执行模块(EXEC),这些模块统一由管理模块(MGR)进行管理执行。
本篇我们来看下DMHS 的搭建。 相关规划信息如下:
源端 | 目的端 | |
---|---|---|
ip地址 | 192.168.56.102 | 192.168.56.103 |
数据库 | DM8 | DM8 |
部署地址 | /dm/dmhs/ | /dm/dmhs/ |
数据库端口号 | 5237 | 5237 |
DMHS服务端口 | 5345 | 5345 |
数据接收端口 | / | 5346 |
1 环境说明
2台主机环境配置一样。
操作系统是麒麟V10:
[dave@www.cndba.cn software]# cat /proc/version
Linux version 4.19.90-24.4.v2101.ky10.x86_64 (KYLINSOFT@localhost.localdomain) (gcc version 7.3.0 (GCC)) #1 SMP Mon May 24 12:14:55 CST 2021
[dave@www.cndba.cn software]#
达梦版本:
[dave@www.cndba.cn mnt]$ disql SYSDBA/SYSDBA
Server[LOCALHOST:5236]:mode is normal, state is open
login used time : 5.217(ms)
disql V8
SQL> select id_code();
LINEID ID_CODE()
---------- ----------------------------------------
1 1-2-18-21.11.11-150669-10013-ENT Pack16
used time: 1.929(ms). Execute id is 50600.
SQL> select * from v$version;
LINEID BANNER
---------- -------------------------
1 DM Database Server 64 V8
2 DB Version: 0x7000c
used time: 0.696(ms). Execute id is 50601.
SQL>
2 安装DMHS
DMHS 同步服务主要包括四个模块,分别是捕获模块(CPT)、装载模块(LOAD)、传输模块(NET)以及执行模块(EXEC),这些模块统一由管理模块(MGR)进行管理执行。
2.1 源端安装
DMHS 安装web 管理时需要依赖一个独立的内置数据库,在安装过程中会自动创建,不需要提前创建,如果提前安装了,会导致初始化失败。
当然也可以选择不安装web管理系统,通过命令行操作来配置。
安装DMHS:
[dave@www.cndba.cn software]# chown dmdba:dinstall dmhs*
[dave@www.cndba.cn software]# chmod 755 dmhs*
[dave@www.cndba.cn software]# ll
总用量 4083280
drwxr-xr-x 2 dmdba dinstall 250 11月 2 12:32 dmetl5_V5.0.1.10-Build(2021.02.04-97563)_linux64
-rw-r--r-- 1 dmdba dinstall 2734119547 11月 2 12:26 dmetl5_V5.0.1.10-Build(2021.02.04-97563)_linux64.zip
-rw-r--r-- 1 dmdba dinstall 648 11月 2 12:26 dmetl.key
-rwxr-xr-x 1 dmdba dinstall 648 12月 21 21:59 dmhs9F01077495-new.key
-rwxr-xr-x 1 dmdba dinstall 495760038 12月 21 18:47 dmhs_V4.3.04_dm8_rev122276_rh6_64_veri_20230111_sp1.bin
-rwxr-xr-x 1 dmdba dinstall 951385360 10月 27 22:32 DMInstall.bin
drwxr-xr-x 3 dmdba dinstall 190 11月 2 10:43 DMLOG8.7
[dave@www.cndba.cn software]#
Dmhs 可以通过静默安装,也可以通过图形化安装,我们这里执行图形化安装:
./dmhs_V4.3.04_dm8_rev122276_rh6_64_veri_20230111_sp1.bin
2.2 目标端安装
目标端安装和源端一样,直接选择精简版即可。 两点区别:
- 不需要单独配置内置库,直接使用源端的内置库即可。
- 不需要在安装web客户端,直接使用源端的。
直接运行安装程序:
./dmhs_V4.3.04_dm8_rev122276_rh6_64_veri_20230111_sp1.bin
具体过程略。
3 web配置DMHS
登陆web管理界面:
http://192.168.56.102:8080/manager/
账号:admin
密码:888888
一般先配目标端,再配源端。
3.1 目标端配置
目标端上右击,添加HS 实例信息:
3.2 源端配置
源端上右击,添加HS 实例信息:
根据需要,修改源端同步和过滤规则,在源端的CPT 上右击,修改配置:
3.3 启用目标端和源端的DMHS 服务
DMHS 有服务和模块2个部分,在同步时这2个部分都需要启动。 我们这里在服务名上右击,启动服务:
这些配置信息都保存在dmhs.hs 配置文件中,也可以直接修改这个参数文件:
[dave@www.cndba.cn USTC]$ pwd
/dm/dmhs/INST_HS/USTC
[dave@www.cndba.cn USTC]$ cat dmhs.hs
<?xml version="1.0" encoding="GB2312" standalone="no"?>
<dmhs>
<base>
<lang>ch</lang>
<mgr_port>5345</mgr_port>
<name>USTC</name>
<ckpt_interval>60</ckpt_interval>
<siteid>2</siteid>
<version>2.0</version>
</base>
<cpt>
<enable>1</enable>
<name>cpt</name>
<db_type>DM8</db_type>
<db_server>192.168.56.102</db_server>
<db_user>SYSDBA</db_user>
<db_pwd>SYSDBA</db_pwd>
<db_port>5237</db_port>
<ddl_mask>TABLE:CREATE:DROP:TRUNCATE:ALTER</ddl_mask>
<arch/>
<send>
<ip>192.168.56.103</ip>
<mgr_port>5345</mgr_port>
<data_port>5346</data_port>
<filter>
<enable>
<item>*.*</item>
</enable>
</filter>
</send>
</cpt>
</dmhs>
[dave@www.cndba.cn USTC]$
注意事项:
在启动服务之前,务必确保复制了libdmoci.so依赖包,否则后面的操作无法正常进行,详细说明参考博客:
达梦8 DMHS libdmoci.so 依赖包 问题说明
https://www.cndba.cn/dave/article/116424
4 数据库侧配置
4.1 开启归档和逻辑日志
设置归档标记和逻辑日志标记。 修改dm.ini文件的为如下值:
ARCH_INI = 1
RLOG_APPEND_LOGIC = 1
配置归档文件,在“dm.ini”同目录下创建文件“dmarch.ini”,内容如下:
[ARCHIVE_LOCAL1]
ARCH_TYPE = LOCAL
ARCH_DEST = /dm/dmarch
ARCH_FILE_SIZE = 128
ARCH_SPACE_LIMIT = 2048
重启数据库,使配置参数生效。
检查配置的正确性:
[dave@www.cndba.cn bin]$ disql SYSDBA/SYSDBA@localhost:5237
Server[localhost:5237]:mode is normal, state is open
login used time : 1.461(ms)
disql V8
SQL> SELECT ARCH_DEST, ARCH_FILE_SIZE FROM SYS.V$DM_ARCH_INI WHERE ARCH_TYPE='LOCAL' AND ARCH_IS_VALID='Y';
LINEID ARCH_DEST ARCH_FILE_SIZE
---------- ---------- --------------
1 /dm/dmarch 128
used time: 2.838(ms). Execute id is 500.
SQL> SELECT PARA_VALUE FROM SYS.V$DM_INI WHERE PARA_NAME = 'RLOG_APPEND_LOGIC';
LINEID PARA_VALUE
---------- ----------
1 1
used time: 5.140(ms). Execute id is 501.
SQL>
4.2 配置 DDL
如果要求 DDL 同步,那么需要在源库上创建 DDL 触发器和辅助表。
需要使用SYSDBA用户执行ddl_sql_dm8.sql,该脚本在DMHS 安装目录下 scripts 子目录中。
[dave@www.cndba.cn scripts]$ pwd
/dm/dmhs/scripts
[dave@www.cndba.cn scripts]$ ls
ddl_sql_db2.sql ddl_sql_dm7.sql ddl_sql_pg.sql dmhs_manager.sql setenv.sh
ddl_sql_dm6_v2.sql ddl_sql_dm8.sql delete_data_before_7day.sql readme.txt
ddl_sql_dm6_v3.sql ddl_sql_ora.sql dmhs_grant.sql root
[dave@www.cndba.cn scripts]$
注意,我这里直接在disql 中执行时sql 报错,后来在DMManager 中执行正常。
检查创建的触发器和辅助表是否有效,检查辅助表的语句:
SQL> select owner, table_name from dba_tables where owner = 'SYSDBA' and table_name like 'DMHS%' and status = 'VALID';
LINEID OWNER TABLE_NAME
---------- ------ ----------------
1 SYSDBA DMHS_DDL_COL
2 SYSDBA DMHS_DDL_SQL
3 SYSDBA DMHS_DDL_CONS
4 SYSDBA DMHS_DDL_IDX
5 SYSDBA DMHS_DDL_RENAME
6 SYSDBA DMHS_DDL_SEQ
7 SYSDBA DMHS_DDL_PART
8 SYSDBA DMHS_DDL_COMMENT
9 SYSDBA DMHS_DDL_LOG
9 rows got
used time: 28.742(ms). Execute id is 517.
如果存在以上的查询结果,表示 DMHS 辅助表创建有效。
检查触发器的语句:
SQL> select owner, trigger_name from dba_triggers where owner = 'SYSDBA' and trigger_name like 'DMHS%' and status = 'Y';
LINEID OWNER TRIGGER_NAME
---------- ------ -----------------------
1 SYSDBA DMHS_DDL_TRIGGER_AFTER
2 SYSDBA DMHS_DDL_TRIGGER_BEFORE
3 SYSDBA DMHS_DDL_TRIGGER_GRANT
4 SYSDBA DMHS_DDL_TRIGGER_REVOKE
used time: 2.860(ms). Execute id is 518.
SQL>
如果存在以上的查询结果,表示 DMHS 触发器创建有效。
5 初始装载数据
初始装载是将源端数据库中的初始数据装载到目的端数据库,使 DMHS 同步的时刻源和目的端的同步表数据一致。装载前源端 DMHS 服务、目的端 DMHS 服务和模块都需要启动。
5.1 启动目标端 DMHS 服务和模块:
服务和模块的启动可以通过web界面,也可以通过控制台。 服务在之前的章节已经启动。
命令行启动模块命令如下:
[dave@www.cndba.cn USTC]$ ./dmhs_console
DMHS console tool: V4.1.1-Build(2021.05.17-99696trunc)_D64
Copyright (c) 2020, DMHS. All rights reserved.
Type ? or "help" for help, type "quit" to quit console.
Connected to DMHS: 127.0.0.1:5345
execute success
Dameng HS Server V4.1.1-Build(2021.05.17-99696trunc)_D64
DMHS> exec
capture module information log execute module information
--------------------------------------- ---------------------------------------------
status : quit status : stop
database name : database status : abnormal
site ID : 0 active transactions : 0
log mode : online transactions to be executed : 0
log parse queues : 0 executed times : 0 (0 times/s)
log post queues : 0 committed transactions : 0 (0 times/s)
log page sequence : 0 rollback transactions : 0 (0 times/s)
logs to be parsed : 0 affected rows : 0 (0 rows/s)
logs to be posted : 0 cached lobs : 0
total log pages : 0 (0 pages/s) checkpoint time :
log post times : 0 (0 times/s) cvt state : idle
file IO times : 0 (0 times/s) cvt transactions : 0
total log bytes : 0 B (0 B/s)
archive directory :
current log file :
current log time :
-------------------------------------------------------------------------------------
log sender information log receiver information
--------------------------------------- ---------------------------------------------
status : halt status : halt
filtered logs : 0 total received logs : 0
message send queue : 0 (0.00 percent) message recieved times : 0 times
total sent logs : 0 current log LSN : 0
message sent times : 0 times message sequence : 0
current log LSN : 0 start log LSN : 0
message sequence : 0 received message traffic : 0 B (0 B/s)
start log LSN : 0
sent message traffic : 0 B (0 B/s)
current log time :
apply status : No data
execute success
DMHS> start exec
execute success
DMHS> exec
capture module information log execute module information
--------------------------------------- ---------------------------------------------
status : quit status : idle
database name : database status : abnormal
site ID : 0 active transactions : 0
log mode : online transactions to be executed : 0
log parse queues : 0 executed times : 0 (0 times/s)
log post queues : 0 committed transactions : 0 (0 times/s)
log page sequence : 0 rollback transactions : 0 (0 times/s)
logs to be parsed : 0 affected rows : 0 (0 rows/s)
logs to be posted : 0 cached lobs : 0
total log pages : 0 (0 pages/s) checkpoint time :
log post times : 0 (0 times/s) cvt state : idle
file IO times : 0 (0 times/s) cvt transactions : 0
total log bytes : 0 B (0 B/s)
archive directory :
current log file :
current log time :
-------------------------------------------------------------------------------------
log sender information log receiver information
--------------------------------------- ---------------------------------------------
status : halt status : halt
filtered logs : 0 total received logs : 0
message send queue : 0 (0.00 percent) message recieved times : 0 times
total sent logs : 0 current log LSN : 0
message sent times : 0 times message sequence : 0
current log LSN : 0 start log LSN : 0
message sequence : 0 received message traffic : 0 B (0 B/s)
start log LSN : 0
sent message traffic : 0 B (0 B/s)
current log time :
apply status : No data
execute success
DMHS>
5.2 启动源端 DMHS 服务
[dave@www.cndba.cn USTC]$ pwd
/dm/dmhs/INST_HS/USTC
[dave@www.cndba.cn USTC]$ ./dmhs_server status
DMHS Server is already running at current directory...
[dave@www.cndba.cn USTC]$
以上2步也可以在web页面上操作。
5.3 源端执行初始装载
在源端执行装载,可以在命令行执行dmhs_console 进入控制台,也可以在web页面的实例名上右击调用控制台执行。
命令行调用需要到实例目录下执行,否则会报找不到配置文件:
[dave@www.cndba.cn USTC]$ pwd
/dm/dmhs/INST_HS/USTC
[dave@www.cndba.cn USTC]$
[dave@www.cndba.cn USTC]$ ./dmhs_console
DMHS console tool: V4.1.1-Build(2021.05.17-99696trunc)_D64
Copyright (c) 2020, DMHS. All rights reserved.
Type ? or "help" for help, type "quit" to quit console.
Connected to DMHS: 127.0.0.1:5345
execute success
Dameng HS Server V4.1.1-Build(2021.05.17-99696trunc)_D64
DMHS> copy 0 "sch.name='SYSDBA'" DICT|LSN|CREATE|INSERT
CSL[WARN]: Detect the LSN mask, the mask will be ignored in the log is less than the current LSN all operations, please confirm whether to continue?(Y/N)
Y
copy mask is : |CREATE|INSERT|TABLE|DICT|LSN|OBJID|REP
execute finish, please look up log file of exec module to check data load result
DMHS>
DMHS>
初始加载的时候可能会报如下错误,解决方法如下:
CSL[ERROR]: 加载日志分析模块失败
达梦 DMHS libdmoci.so: cannot open shared object file 错误解决方法
https://www.cndba.cn/dave/article/116421达梦 DMHS dmhs_console 控制台 中文乱码 问题解决方法
https://www.cndba.cn/dave/article/116422
5.4 启动源库捕获模块
DMHS> start cpt
execute success
DMHS> cpt
capture module information log execute module information
--------------------------------------------------------------------------- -------------------------------------------------
status : idle status : idle
database name : 192.168.56.102 database status : normal
site ID : 4 active transactions : 0
log mode : online transactions to be executed : 0
log parse queues : 0 executed times : 0 (0 times/s)
log post queues : 0 committed transactions : 0 (0 times/s)
log page sequence : 4306 rollback transactions : 0 (0 times/s)
logs to be parsed : 0 affected rows : 0 (0 rows/s)
logs to be posted : 1 cached lobs : 0
total log pages : 2065 (0 pages/s) checkpoint time : 2023-02-01 17:34:30
log post times : 85 (0 times/s) cvt state : idle
file IO times : 12 (0 times/s) cvt transactions : 0
total log bytes : 603777 B (0 B/s)
archive directory : /dm/dmarch
current log file : ARCHIVE_LOCAL1_0x7D3270F8[0]_2023-02-01_18-25-19.log
current log time : 2023-02-01 18:25:18
-----------------------------------------------------------------------------------------------------------------------------
log sender information log receiver information
--------------------------------------------------------------------------- -------------------------------------------------
status : waiting for log status : waiting recieve log
filtered logs : 0 total received logs : 120
message send queue : 0 (0.00 percent) message recieved times : 3 times
total sent logs : 119 current log LSN : 0
message sent times : 1 times message sequence : 1
current log LSN : 27664 start log LSN : 0
message sequence : 1 received message traffic : 3501 B (0 B/s)
start log LSN : 0
sent message traffic : 2989 B (0 B/s)
current log time : 2023-02-01 17:40:45
apply status : No data
execute success
DMHS>
这一步也可以web 页面操作。 此时web 页面显示服务和模块都正常:
6 验证数据同步
源库SYSDBA 用户下创建一张测试表:
[dave@www.cndba.cn bin]$ disql SYSDBA/SYSDBA
Server[LOCALHOST:5236]:mode is normal, state is open
login used time : 8.251(ms)
disql V8
SQL> create table cndba(id int,url varchar2(50));
executed successfully
used time: 56.747(ms). Execute id is 1000.
SQL> insert into cndba values(1,'https://www.cndba.cn');
affect rows 1
used time: 0.595(ms). Execute id is 1001.
SQL> commit;
executed successfully
used time: 4.151(ms). Execute id is 1002.
SQL> select * from cndba;
LINEID ID URL
---------- ----------- --------------------
1 1 https://www.cndba.cn
used time: 0.539(ms). Execute id is 1003.
SQL>
目标库查询:
[dave@www.cndba.cn ~]$ disql SYSDBA/SYSDBA
Server[LOCALHOST:5236]:mode is normal, state is open
login used time : 1.795(ms)
disql V8
SQL> select * from cndba;
LINEID ID URL
---------- ----------- --------------------
1 1 https://www.cndba.cn
used time: 4.104(ms). Execute id is 51400.
SQL>
DDL 和 DML 都同步正常。
版权声明:本文为博主原创文章,未经博主允许不得转载。