使用DMHS进行MYSQL的双向同步

一.配置信息:

主机192.168.3.200192.168.3.201
MySQL版本Server version: 5.6.39-log MySQL Community Server (GPL)Server version: 5.6.39-log MySQL Community Server (GPL)
MYSQL_HS目录/mysql_hs/dmhs/SOURCE/mysql_hs/dmhs/DEST
操作系统版本Red Hat Enterprise Linux Server release 6.9 (Santiago)Red Hat Enterprise Linux Server release 6.9 (Santiago)

二.部署前准备(两节点都需要)

1.首先准备两台mysql数据库(如表格所示)
2.设置数据库本地环境变量

[root@oracle ~]# cat /etc/profile|grep LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64
[root@oracle ~]# source  /etc/profile)

3.安装ODBC(2.3.0 两个服务器都需要)
链接:https://pan.baidu.com/s/1KOWhBOTjYkrTVTZAeYnjBw
提取码:obvx
安装步奏如下:
1)安装ODBC

[root@oracle ODBC]# tar -zxvf unixODBC-2.3.0.tar.gz
[root@oracle ODBC]# cd unixODBC-2.3.0
[root@oracle unixODBC-2.3.0]# export CC=gcc
#######当服务器系统为UNIX/LINUX 64bits时,在./configure之前需执行
[root@oracle unixODBC-2.3.0]# export CFLAGS="-maix64 -DBUILD_REAL_64_BIT_MODE"
[root@oracle unixODBC-2.3.0]# export OBJECT_MODE=64
[root@oracle unixODBC-2.3.0]# ./configure --enable-drivers=no --with-iconv-char-enc=GB18030 --enable-gui=no --enable-iconv=yes
[root@oracle unixODBC-2.3.0]# make
[root@oracle unixODBC-2.3.0]# make install

2)查看odbc配置文件

[root@oracle unixODBC-2.3.0]# odbcinst -j   
unixODBC 2.3.0
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

3)配置ODBC相关配置文件

[root@oracle unixODBC-2.3.0]# cat /usr/local/etc/odbcinst.ini
#Oracle配置源(此处不需要)
[Oracle in OraDb11g_home1]
Description=Oracle ODBC driver for Oracle 11g
Driver=/u01/app/oracle/product/11.2.0.4/db_1/lib/libsqora.so.11.1
Threading=0
UsageCount=2
#mysql配置源
[MySQL ODBC 5.1 Driver]
Driver=/usr/lib64/libmyodbc5.so
UsageCount=2
[root@oracle unixODBC-2.3.0]# cat /usr/local/etc/odbc.ini
#Oracle配置源(此处不需要)
[ORACLE]
Description=ORACLE ODBC DSN
Driver=Oracle in OraDb11g_home1
SERVER=192.168.3.200
UserID=system
Password=oracle
name=oracle
PORT=1521
#mysql配置源
[mysql]
Driver=MySQL ODBC 5.1 Driver
DATABASE=mysql
DESCRIPTION=MYSQL ODBC 5.1 DRIVER
SERVER=127.0.0.1
UID=root
PASSWORD=root

4.安装mysql connect odbc
1)安装包链接如下:
链接:https://pan.baidu.com/s/15fV7FFGq-xGOstqfl_LWjQ
提取码:opwv
2)安装命令

[root@oracle mysql_kit]# rpm -ivh mysql-connector-odbc-5.1.13-1.el6.x86_64.rpm --nodeps --noforce

3)验证通过ODBC是否可以连接数据库

[root@oracle ~]# isql -v mysql root root
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> show databases
SQL> use HSTEST
SQL> show tables

5.修改mysql binlog及binlog format
1)原因分析:
DMHS通过分析MYSQL 数据库的binlog日志来捕获数据库的增量数据,DMHS运行之前,必须将数据库binlog打开,同时将binlog format设置为row模式。修改的参数均涉及数据库初始过程,修改参数后,需重启生效。如需操作,需确认工作环境能停机维护。

2)具体操作过程如下:

[root@oracle ~]# find / -name my.cnf
[root@oracle ~]# vi /usr/my.cnf
log-bin=mysql-bin
binlog_format=row
max_allowed_packet=100M
[root@oracle ~]#  service mysql restart
[root@oracle ~]# mysql -uroot -vroot
mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+
1 row in set (0.00 sec)

mysql> show variables like 'binlog_format';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| binlog_format | ROW   |
+---------------+-------+
1 row in set (0.00 sec)

三.部署DMHS同步软件(两节点都需要操作)

[root@oracle DM_SOFT]# chmod 775 dmhs_V4.0.0_mysql_rev86685_rh6_64_veri_20190709.bin 
[root@oracle DM_SOFT]#./dmhs_V4.0.0_mysql_rev86685_rh6_64_veri_20190709.bin -i
##安装过程根据实际需要进行修改##
[root@oracle DM_SOFT]# cd /mysql_hs/dmhs/
[root@oracle dmhs]# ls
bin  bin2  db  desktop  doc  guard  include  install  jdk  lib  license_en.txt  license.txt  log  samples  scripts  SOURCE  tool
[root@oracle dmhs]#

------------------------------------------------------------------------------备注------------------------------------------------------------------------------
-1-目前HS只能支持满足以下表达式的 SQL的ddl同步:

  • 创建表
  • 修改表
  • 删除表
  • 清空表

-2-同时需要注意主键和约束

  • 1) 约束

DMHS 同步过程中,需将将执行端 MYSQL 表中的外键禁用,否则,在对外键引用表进行更新时,可能会引起执行端 MYSQL数据库操作错误。

  • 2) 触发器

DMHS 同步过程中,需将执行端 MYSQL 中的存在 DML 操作的触发器禁用,否则在同步过程中,会对触发器操作的表进行二次操作,导致同步结果错误。


四.创建配置文件dmhs.hs

1.节点一(192.168.3.201)的配置文件dmhs.hs内容:

<?xml version="1.0" encoding="GB2312" standalone="no"?>
<dmhs>
    <base>
        <lang>ch</lang>
        <mgr_port>6345</mgr_port>
        <ckpt_interval>45</ckpt_interval>
        <siteid>2</siteid>
        <version>2.0</version>
    </base>
    <cpt>
        <name>cpt0</name>
        <db_type>mysql</db_type>
        <db_server>127.0.0.1</db_server>
        <db_user>root</db_user>
        <db_pwd>root</db_pwd>
        <db_port>3306</db_port>
        <db_name>HSTEST</db_name>
        <ddl_mask>op:obj</ddl_mask>
        <arch>
            <clear_flag>0</clear_flag>
            <clear_interval>600</clear_interval>
        </arch>
        <send>
            <ip>192.168.3.200</ip>
            <mgr_port>5345</mgr_port>
            <data_port>5346</data_port>
            <filter>
                <enable>
                    <item>HSTEST.*</item>
                </enable>
            </filter>
        </send>
        <jdbc from_password="root" from_type="mysql" from_url="jdbc:mysql://192.168.3.201:3306/HSTEST" from_user="root" to_password="root" to_type="mysql" to_url="jdbc:mysql://192.168.3.200:3306/HSTEST" to_user="root"/>
    </cpt>
    <exec>
        <recv>
            <mgr_port>6345</mgr_port>
            <data_port>6346</data_port>
        </recv>
        <enable>1</enable>
        <db_type>mysql</db_type>
        <db_server>127.0.0.1</db_server>
        <db_user>root</db_user>
        <db_pwd>root</db_pwd>
        <db_port>3306</db_port>
        <db_name>HSTEST</db_name>
        <level>0</level>
        <exec_policy>2</exec_policy>
    </exec>
</dmhs>

2.节点二(192.168.3.200)的配置文件dmhs.hs内容:

<?xml version="1.0" encoding="GB2312" standalone="no"?>
<dmhs>
    <base>
        <lang>ch</lang>
        <mgr_port>5345</mgr_port>
        <ckpt_interval>45</ckpt_interval>
        <siteid>1</siteid>
        <version>2.0</version>
    </base>
    <cpt>
        <enable>1</enable>
        <name>cpt0</name>
        <db_type>mysql</db_type>
        <db_server>127.0.0.1</db_server>
        <db_user>root</db_user>
        <db_pwd>root</db_pwd>
        <db_port>3306</db_port>
        <db_name>HSTEST</db_name>
        <ddl_mask>op:obj</ddl_mask>
        <arch>
            <clear_flag>0</clear_flag>
            <clear_interval>600</clear_interval>
        </arch>
        <send>
            <ip>192.168.3.201</ip>
            <mgr_port>6345</mgr_port>
            <data_port>6346</data_port>
            <filter>
                <enable>
                    <item>HSTEST.*</item>
                </enable>
            </filter>
        </send>
        <jdbc from_password="root" from_type="mysql" from_url="jdbc:mysql://192.168.3.200:3306/HSTEST" from_user="root" to_password="root" to_type="mysql" to_url="jdbc:mysql://192.168.3.201:3306/HSTEST" to_user="root"/>
    </cpt>
    <exec>
        <recv>
            <mgr_port>5345</mgr_port>
            <data_port>5346</data_port>
        </recv>
        <enable>1</enable>
        <db_type>mysql</db_type>
        <db_server>127.0.0.1</db_server>
        <db_user>root</db_user>
        <db_pwd>root</db_pwd>
        <db_port>3306</db_port>
        <db_name>HSTEST</db_name>
        <level>0</level>
        <exec_policy>2</exec_policy>
    </exec>
</dmhs>

五.初始化装载

1.节点一192.168.3.200,首先连接并启动exec:

connect 192.168.3.200:5345
start exec

2.节点二192.168.3.201,连接并启动exec:

connect 192.168.3.201:6345
start exec

3.节点一192.168.3.200,清lsn号并装载字典:

connect 192.168.3.200:5345
clear exec lsn
copy 0 "sch.name='HSTEST'" DICT|REG

4.节点二192.168.3.201,清lsn号并装载字典:

connect 192.168.3.201:5345
clear exec lsn
copy 0 "sch.name='HSTEST'" DICT|REG

5.节点一192.168.3.200启动cpt

connect 192.168.3.200:5345
start cpt

6.节点二192.168.3.201启动cpt

connect 192.168.3.201:5345
start cpt

六.数据验证

1.在192.168.3.200创建表test1,看192.168.3.201是否存在该表,成功后进行下一步。
2.成功后在192.168.3.201的test1表插入数据,看192.168.3.200是否存在刚插入的这条数据。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值