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

[导读]  java

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

 

tungsten-relicator介绍linux

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

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

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

 

方案设计数据库

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

       一、中止从库的主从同步,导出从库中的全部数据,清空从库;ruby

       二、配置从库和第二从库的同步服务器

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

       四、将从库导出的数据重新导入从库

      五、重启启动主从同步。

部署完成后的图解

                                 同步图

 

 

搭建tungsten-relicator同步

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

首先配置主服务器(192.168.0.1)

一、安装基础环境 JAVA  RUBY

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

二、修改系统的最大连接数

1)查看 ulimit -n

2)更改

vim /etc/security/limits.conf

* soft nofile 65535

* hard nofile 65535

3)重启linux

      reboot

三、修改mysql配置

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

四、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  --  同步的数据库库名

 

五、查看tungsten 同步状态

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

 

 

配置从服务器(192.168.0.2)

一、安装基础环境 JAVA  RUBY

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

二、修改系统的最大连接数

1)查看 ulimit -n

2)更改

vim /etc/security/limits.conf

* soft nofile 65535

* hard nofile 65535

3)重启linux

      reboot

三、配置免密码登陆(从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 

四、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  --  主服务地址

五、查看tungsten 同步状态

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

六、启动mysql同步数据了

start slave;

 

 

 

运营篇

一、查看同步工具的日志

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

二、查看同步的状态

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

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

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

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

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

 

 

若是在运行一段时间后,由于某些缘由须要将数据抹掉从新同步的话,能够安装一下的步骤

       一、中止从库的主从同步,导出从库中的全部数据,清空从库;

       二、删除mysql从库的tungsten_mysql2mongodb库

       三、删除mongo的 tungsten_mysql2mongodb库

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

       五、将从库导出的数据重新导入从库

        六、启动mysql主从同步。

相关文章
相关标签/搜索