目录
DMHS实现Mysql到DM8的同步
1、准备介质
2、安装
3、准备源端Mysql和目标端DM8
软件安装
数据库创建
打开归档
开启附加日志
创建辅助表
Mysql客户端驱动
Mysql端安装ODBC
检查依赖包
创建连接用户
创建测试表
4、同步配置
修改服务配置
Mysql到Dm单向同步配置
Dm到Mysql单向同步配置
5、启动DMHS服务
初始装载
装载数据
启动exec模块
启动cpt模块
6、查看信息
7、报错处理
DMHS实现Mysql到DM8的同步
源端:Mysql8.0.35,RH7.5
目标端:DM8,麒麟V10
介质:
1、准备介质
2、安装
3、准备源端Mysql和目标端DM8
软件安装
略
数据库创建
没有数据库可参考该步骤创建,否则略过。
Mysql端:
略
DM端:
dmdba用户:
dminit path=/dm/data PAGE_SIZE=32 EXTENT_SIZE=32 CASE_SENSITIVE=y CHARSET=1 DB_NAME=HS02 INSTANCE_NAME=HS02 PORT_NUM=5239
root用户:
cd /home/dmdba/dmdbms/script/root/
./dm_service_installer.sh -t dmserver -dm_ini /dm/data/HS02/dm.ini -p HS02
打开归档
Mysql端:
Mysql开启binlog
mysql> show variables like 'log_bin';
mysql> show variables like 'binlog_format';
目标端:
ALTER DATABASE MOUNT;
ALTER DATABASE ADD ARCHIVELOG 'TYPE = LOCAL,DEST = /dm/data/HS02/arch,FILE_SIZE = 128,SPACE_LIMIT = 1024';
ALTER DATABASE ARCHIVELOG;
ALTER DATABASE OPEN;
select para_value from v$dm_ini where para_name in ('ARCH_INI');
开启附加日志
DM端:
SP_SET_PARA_VALUE(1,'RLOG_APPEND_LOGIC',1);
select para_value from v$dm_ini where para_name in ('RLOG_APPEND_LOGIC');
创建辅助表
DM端执行:
set define off
set char_code utf8
start /dmhs/scripts/ddl_sql_dm8.sql
共9个辅助表,4个触发器:
select owner, table_name from dba_tables where owner = 'SYSDBA' and table_name like 'DMHS%' and status = 'VALID';
select owner, trigger_name from dba_triggers where owner = 'SYSDBA' and trigger_name like 'DMHS%' and status = 'Y';
Mysql客户端驱动
下载:MySQL :: Download MySQL Connector/ODBC (Archived Versions)
tar -zxvf mysql-connector-odbc-8.0.28-linux-el7-x86-64bit.tar.gz
Mysql端安装ODBC
tar -xzvf unixODBC-2.3.0.tar.gz
cd unixODBC-2.3.0
./configure
make
make install
cd /usr/local/etc
vim odbcinst.ini
[MySQL ODBC driver]
Description = ODBC for MySQL
Driver = /opt/mysql-connector-odbc-8.0.28-linux-el7-x86-64bit/lib/libmyodbc5w.so
UsageCount = 1
vim odbc.ini
[mysql]
Description = ODBC for MySQL
Driver = MySQL ODBC driver
DATABASE=testdb
SERVER = 192.168.64.129
UserID = root
Password = xxxxxx
PORT = 31306
连接
odbcinst -j
isql mysql -v
Mysql端:
unixodbc动态库加到环境变量:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
创建软连接:
ln -s /usr/local/lib/libodbc.so.2 /usr/local/lib/libodbc.so.1
ln -s /usr/local/lib/libodbcinst.so.2 /usr/local/lib/libodbcinst.so.1
DM端:
需要下载DMDCI的包
把libdmoci.so上传到DM端的/dmhs/bin目录下
检查依赖包
源端
ldd libcpt_mysql.so
目的端
ldd libdmhs_exec.so
创建连接用户
源端执行:
CREATE USER HSEXEC@'%' IDENTIFIED WITH 'mysql_native_password' BY 'HSEXEC';
grant all privileges on *.* to HSEXEC;
flush privileges;
目标端执行:
CREATE TABLESPACE HSEXEC DATAFILE 'HSEXEC.DBF' size 128;
CREATE USER HSEXEC IDENTIFIED by "HSEXEC" DEFAULT TABLESPACE HSEXEC DEFAULT INDEX TABLESPACE HSEXEC;
GRANT VTI TO HSEXEC;
GRANT PUBLIC TO HSEXEC;
GRANT RESOURCE TO HSEXEC;
GRANT DBA TO HSEXEC;
创建测试表
略
源端:
create database testdb;
create table testdb.t_mysql_dm (id int ,name varchar(10));
insert into testdb.t_mysql_dm VALUES(1,'TEST');
COMMIT;
4、同步配置
修改服务配置
节点一:
cd /dmhs/bin
cp TemplateDmhsService DmhsService
vim DmhsService
节点二:
同上
Mysql到Dm单向同步配置
源端:
cd /dmhs/bin
vim dmhs.hs
exec_policy=2表示执行事务出错时,忽略出错的操作后继续执行;ddl_continue=1表示DDL操作同步出错时,继续往下操作。
注意:mysql端的item表名用小写,DM端的用户名表名必须用大写
<?xml version="1.0" encoding="GB2312"?>
<dmhs>
<base>
<lang>en</lang>
<mgr_port>5345</mgr_port>
<ckpt_interval>60</ckpt_interval>
<siteid>11</siteid>
</base>
<cpt>
<db_type>mysql</db_type>
<db_server>192.168.64.129</db_server>
<db_port>31306</db_port>
<db_name>testdb</db_name>
<db_user>HSEXEC</db_user>
<db_pwd>HSEXEC</db_pwd>
<char_code>PG_UTF8</char_code>
<ddl_mask>op:obj</ddl_mask>
<driver>MySQL ODBC driver</driver>
<arch>
<clear_interval>600</clear_interval>
<clear_flag>0</clear_flag>
<dir></dir>
</arch>
<send>
<ip>192.168.64.132</ip>
<mgr_port>5345</mgr_port>
<data_port>5346</data_port>
<filter>
<enable>
<item>testdb.t_mysql_dm</item>
</enable>
<disable>
</disable>
</filter>
<map>
<item>testdb.t_mysql_dm==HSTEST1.T_MYSQL_DM</item>
</map>
</send>
</cpt>
</dmhs>
目标端:
cd /dmhs/bin
vim dmhs.hs
<?xml version="1.0" encoding="GB2312" standalone="no"?>
<dmhs>
<base>
<lang>en</lang>
<mgr_port>5345</mgr_port>
<chk_interval>3</chk_interval>
<ckpt_interval>60</ckpt_interval>
<siteid>22</siteid>
</base>
<recv>
<mgr_port>5345</mgr_port>
<data_port>5346</data_port>
<exec>
<db_type>DM8</db_type>
<db_server>192.168.64.132</db_server>
<db_user>HSEXEC</db_user>
<db_pwd>HSEXEC</db_pwd>
<db_port>5239</db_port>
<char_code>PG_UTF8</char_code>
<level>0</level>
<exec_thr>4</exec_thr>
<exec_sql>1024</exec_sql>
<exec_trx>5000</exec_trx>
<exec_rows>250</exec_rows>
<case_sensitive>1</case_sensitive>
<toggle_case>0</toggle_case>
<exec_policy>2</exec_policy>
<commit_policy>1</commit_policy>
<enable_merge>1</enable_merge>
<affect_row>0</affect_row>
</exec>
</recv>
</dmhs>
Dm到Mysql单向同步配置
源端:
<?xml version="1.0" encoding="utf-8"?>
<dmhs>
<base>
<lang>en</lang>
<mgr_port>5345</mgr_port>
<chk_interval>2</chk_interval>
<siteid>22</siteid>
<version>2.0</version>
</base>
<cpt>
<db_type>dm8</db_type>
<db_server>192.168.64.132</db_server>
<db_user>HSEXEC</db_user>
<db_pwd>HSEXEC</db_pwd>
<db_port>5239</db_port>
<char_code>PG_UTF8</char_code>
<ddl_mask>op:obj</ddl_mask>
<parse_thr>1</parse_thr>
<arch>
<clear_interval>600</clear_interval>
<clear_flag>1</clear_flag>
<bak_dir></bak_dir>
</arch>
<send>
<ip>192.168.64.129</ip>
<mgr_port>5345</mgr_port>
<data_port>5346</data_port>
<level>0</level>
<trigger>0</trigger>
<constraint>0</constraint>
<identity>0</identity>
<net_turns>0</net_turns>
<filter>
<enable>
<item>HSTEST1.T_MYSQL_DM</item>
</enable>
<disable>
</disable>
</filter>
<map>
<item>HSTEST1.T_MYSQL_DM==testdb.t_mysql_dm</item>
</map>
</send>
</cpt>
</dmhs>
目标端:
<?xml version="1.0" encoding="utf-8"?>
<dmhs>
<base>
<lang>en</lang>
<mgr_port>5345</mgr_port>
<chk_interval>20</chk_interval>
<siteid>11</siteid>
<version>2.0</version>
</base>
<exec>
<char_code>PG_UTF8</char_code>
<recv>
<mgr_port>5345</mgr_port>
<data_port>5346</data_port>
</recv>
<driver>{MySQL ODBC driver}</driver>
<db_type>mysql</db_type>
<db_server>192.168.64.129</db_server>
<db_name>testdb</db_name>
<db_user>HSEXEC</db_user>
<db_pwd>HSEXEC</db_pwd>
<db_port>31306</db_port>
<exec_thr>4</exec_thr>
<exec_sql>512</exec_sql>
<exec_trx> 5000 </exec_trx>
<exec_rows>250</exec_rows>
<exec_policy>2</exec_policy>
</exec>
</dmhs>
5、启动DMHS服务
节点一:
cd /dmhs/bin
./DmhsService start
或者
./dmhs_server dmhs.hs
ps -ef |grep dmhs
节点二:
cd /dmhs/bin
./DmhsService start
或者
./dmhs_server dmhs.hs
ps -ef |grep dmhs
初始装载
目的端:
./dmhs_console
DMHS> connect
DMHS> start exec
源端:
./dmhs_console
DMHS> connect
DMHS> clear exec lsn
装载字典
copy 0 "sch.name = 'testdb'" DICT
装载数据
源端:
装载建表语句
copy 0 "sch.name = 'testdb'" CREATE
装载数据
copy 0 "sch.name = 'HSTEST'" INSERT|THREAD|2
装载某个表的数据
copy 0 "sch.name = 'HSTEST' and tab.name in ('T_ORA_DM')" INSERT|THREAD|2
copy 0 "sch.name='EDM_BASE' and tab.name in('VW_CHANNEL_TR_STATUS')" DICT|CREATE|INSERT|THREAD|16|FAST|200|group|32
启动exec模块
目标端:
cd /dmhs/bin
./dmhs_console
DMHS> start exec
DMHS> state
启动cpt模块
源端:
源端cpt启动,目标端exec会自动启动
DMHS> start cpt
DMHS> state
6、查看信息
查看日志:
cd /dmhs/bin/log
tail -100f dmhs_202408.log
目标端:
Exec
thr
trx
源端:
cpt
7、报错处理
1、获取不到映射表的字段信息
ODBC client版本过小,更换版本为8.0
2、start cpt 报解析日志失败
修改配置文件,增加字符集UTF8:
<char_code>PG_UTF8</char_code>
3、LSN清空卡住
如果执行卡住,删除bin/log下的日志以及bin目录下的dmhs_cpt.tmp
然后重启dmhs_server,再执行clear exec lsn
达梦技术社区:达梦数据库 - 新一代大型通用关系型数据库 | 达梦在线服务平台