大数据实践-数据同步篇tungsten-relicator(mysql->mongo)

[导读] 

           随着公司业务的快速发展数据量也迅速的增大,基于用户各个维度深度分析,关系型数据压力越来越大;因此急于寻找一些解决方案;调研了很久最后采用了 golang+mongod集群的这个方案,使用mongo做数据分析的存储端,数据同步就成为一个问题,目前网上主流的工具和解决方案都比较少,唯一一个稍微多点的文章就是tungsten-relicator,最后技术选型也才用了它,目前也使用了快一年了,遇到过很多问题,但基本还算比较稳定。

 

tungsten-relicator介绍

Tungsten Replicator 是一个高性能、开源的数据复制引擎,用于 MySQL、Postgres 和 Oracle 数据库。这是 Continuent 最先进的集群解决方案的核心组件之一。

第三方数据复制引擎--Tungsten-Replicator 主要特点:

1 支持高版本MySQL向低版本复制,5.1-->5.0
2 支持跨数据库系统的复制,MySQL-->PgSQL
3 支持多主库向单台Slave的复制,Multi-Master-->Slave
4 G-Replicator提取数据的更新记录写到MySQL 队列表Queue;基于这个队列,可以为其他应用服务提供便利

 

方案设计

           公司以前使用着mysql的主从,为了不影响正常业务,又添加了一个从库;从第二个从库同步到mongo集群中;本文不在描述mysql集群和monggo集群搭建,重点讨论tungsten-relicator同步和部署

       1、停止从库的主从同步,导出从库中的所有数据,清空从库;

       2、配置从库和第二从库的同步

       3、搭建tungsten-relicator同步(mysql-mongo)

       4、将从库导出的数据从新导入从库

      5、重启启动主从同步。

部署完成后的图解

                                 同步图

 

 

搭建tungsten-relicator同步

tungsten-relicator需要部署到两条服务器,主服务负责读mysql binlog日志解析后传送给从服务器,从服务器接收数据并同步到mongo

首先配置主服务器(192.168.0.1)

1、安装基础环境 JAVA  RUBY

yum -y install java-1.7.0-openjdk*
yum -y install ruby

2、修改系统的最大链接数

1)查看 ulimit -n

2)更改

vim /etc/security/limits.conf

* soft nofile 65535

* hard nofile 65535

3)重启linux

      reboot

3、修改mysql配置

vi /etc/my.cnf
最下面添加
binlog_format=row
max_allowed_packet = 52M
log_slave_updates = 1
同时停止同步
slave stop;

4、tungsten主程序配置

解压 
tar -zxvf tungsten-replicator-2.2.1-403.tar.gz
cd tungsten-replicator-2.2.1-403
启动 
  ./tools/tpm install mysql2mongodb \
    --master=192.168.0.1 \
    --install-directory=/opt/continuent \
    --replication-user=root\
    --replication-password=root\
    --enable-heterogenous-master=true \
    --repl-svc-extractor-filters=replicate \
    --property=replicator.filter.replicate.do=zhongxin \
    --property=replicator.filter.pkey.addColumnsToDeletes=true \
    --property=replicator.filter.pkey.addPkeyToInserts=true  \
    --start

master  --  主服务器Ip地址

replication-user  --  myslq用户名

replication-password  --  mysql密码

property=replicator.filter.replicate.do  --  同步的数据库库名

 

5、查看tungsten 同步状态

/opt/continuent/tungsten/tungsten-replicator/bin/trepctl status
state    : ONLINE 表示服务启动正常

 

 

配置从服务器(192.168.0.2)

1、安装基础环境 JAVA  RUBY

yum -y install java-1.7.0-openjdk*
yum -y install ruby

2、修改系统的最大链接数

1)查看 ulimit -n

2)更改

vim /etc/security/limits.conf

* soft nofile 65535

* hard nofile 65535

3)重启linux

      reboot

3、配置免密码登录(从tungsten从服务器免密码登录主服务器)

  ssh-keygen -t rsa    一路回车
  cd .ssh/
  cp id_rsa.pub authorized_keys
  chmod 600 authorized_keys
  scp authorized_keys root@192.168.0.2:/root/.ssh
  chmod 700 -R .ssh
 
  验证无密码登录:ssh 192.168.0.1 

4、tungsten从服务程序配置

解压 
tar -zxvf tungsten-replicator-2.2.1-403.tar.gz
cd tungsten-replicator-2.2.1-403
启动 
  ./tools/tungsten-installer --master-slave -a  \
     --datasource-type=mongodb \
     --datasource-port=27001 \
     --master-host=192.168.0.1     \
     --service-name=mysql2mongodb  \
     --home-directory=/opt/continuent \
     --java-file-encoding=UTF8 \
     --svc-parallelization-type=none \
     --start-and-report

mongodb安装在本地

master-host  --  主服务地址

5、查看tungsten 同步状态

/opt/continuent/tungsten/tungsten-replicator/bin/trepctl status
state    : ONLINE 表示服务启动正常

6、启动mysql同步数据了

start slave;

 

 

 

运营篇

1、查看同步工具的日志

tail -300f  /opt/continuent/tungsten/tungsten-replicator/log/trepsvc.log
tail -30f /opt/continuent/service_logs/trepsvc.log

2、查看同步的状态

/opt/continuent/tungsten/tungsten-replicator/bin/trepctl status
/opt/continuent/tungsten/tungsten-replicator/bin/trepctl services

3、当同步出错后,解决问题后,执行命令重新同步

/opt/continuent/tungsten/tungsten-replicator/bin/trepctl -service mysql2mongodb online
/opt/continuent/tungsten/tungsten-replicator/bin/trepctl status

4、当一些表里面存在特殊符号可能会导致同步出错,可以在从服务器启动的时候加上一下参数跳过同步的表

--property=replicator.filter.replicate.ignore=zhongxin.zx_notice_req_log \

 

 

如果在运行一段时间后,因为某些原因需要将数据抹掉重新同步的话,可以安装一下的步骤

       1、停止从库的主从同步,导出从库中的所有数据,清空从库;

       2、删除mysql从库的tungsten_mysql2mongodb库

       3、删除mongo的 tungsten_mysql2mongodb库

       4、重启启动tungsten的主从同步(安装启动命令)

       5、将从库导出的数据从新导入从库

        6、启动mysql主从同步。

posted @ 2015-10-28 18:21  纯洁的微笑  阅读(6991)  评论(1编辑  收藏  举报