Source: http://www.cnblogs.com/ityouknow/p/4918164.html
[導讀]
隨著公司業務的快速發展數據量也迅速的增大,基于用戶各個維度深度分析,關系型數據壓力越來越大;因此急于尋找一些解決方案;調研了很久最后采用了 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主從同步。
![]() |
不含病毒。www.avast.com |