使用 tungsten-replicator4 实现 mysql -- > monogo 数据同步

来源:转载

 tungsten-replicator 是基于binlog的开源同步工具,其大概原理是 从mysql 端抓取 binlog日志,写到自己的 thl (transaction history log)中,再由 thl 发送到 nosql(mongo) 主机上thl 中,nosql 主机上的 thl 再写到 nosql 中

一 规划主机:

1、192.168.67.128 #mysql主机 (事先安装好,安装步骤详见 前一篇博客 )
2、192.168.67.129 #mongodb主机 (事先安装好,安装步骤详见 前一篇博客)

二 前置条件:(128和129)

1 创建tungsten用户

1、[[email protected] ~] useradd tungsten
2、[[email protected] ~] passwd tungsten

2 将tungsten账户添加到 mysql 用户组里

128主机:
[[email protected] ~] sudo usermod -G mysql tungsten

129主机
[[email protected] ~] sudo usermod -G mongod tungsten

3 修改sudoers权限,并且让 tungsten 用户使用 sudo 命令时免密码

[[email protected] ~] chmod 740 /etc/sudoers
[[email protected] ~] vi /etc/sudoers

添加如下一行:
tungsten ALL=(ALL) NOPASSWD: ALL

4 切换到 tungsten 用户下

[[email protected] ~] su - tungsten

5 切换到 tungsten 用户后,创建密钥对。默认在/home/tungsten/.ssh 目录下

[[email protected] ~] ssh-keygen -t rsa

6 修改 limit 文件

[[email protected] ~] vi /etc/security/limits.conf

添加下面一行:
* - nofile 65535

7 检查修改是否成功

[[email protected] ~] ulimit -n
65535

8 配置hosts

[[email protected] ~] sudo vi /etc/hosts
127.0.0.1 localhost
192.168.67.128 host1
192.168.67.129 host2

9 测试主机

[[email protected] ~] uname -n
host1

10 测试ip地址

[[email protected] ~] hostname –ip-address

11 防火墙设置

[[email protected] ~] iptables -A INPUT -i lo -m state –state NEW -j ACCEPT

12 把生成的公钥和私钥拷贝到 tungsten用户的主目录下 。默认就在用户主目录

[[email protected] ~] cp .ssh/id_rsa.pub .ssh/id_rsa /home/tungsten/.ssh

13 把公钥放到 .ssh/authorized_keys文件中,128 的公钥放到 129,129 的公钥放到 128

[[email protected] ~] cat .ssh/id_rsa.pub >> .ssh/authorized_keys

14 修改权限

[[email protected] ~] chmod 700 ~/.ssh
[[email protected] ~] 600 ~/.ssh/*

15 测试主机间ssh

[[email protected] ~] ssh [email protected]

16 修改mysql配置

[[email protected] ~] vi /etc/my.cnf
server-id = 128
open_files_limit = 65535
log-bin = mysql-bin
sync_binlog = 1
max_allowed_packet = 52m
default-storage-engine = InnoDB
innodb_flush_log_at_trx_commit = 2
binlog-format = row
binlog-row-image = full

17 登录mysql,创建用户 tungsten 复制的 mysql 用户

[[email protected] ~] /usr/bin/mysql
mysql> grant all privileges on . to [email protected]’%’ identified by ‘ts’ with grant options;
mysql> flush privileges;

三 安装服务:

1 创建 tungsten-replication 软件主目录

[[email protected] ~] sudo mkdir /opt/continuent/soft
[[email protected] ~] sudo chown -R tungsten /opt/continuent
[[email protected] ~] sudo chmod 700 /opt/continuent

2 把下载好的 tungsten-replicator-4.0.0-2667425.tar.gz 包上传到 soft 目录

[[email protected] ~] cd /opt/continuent/soft
[[email protected] software] ll
[[email protected] software] tungsten-replicator-4.0.0-2667425.tar.gz
[[email protected] software] tar -zxvf tungsten-replicator-4.0.0-2667425.tar.gz
[[email protected] software] cd tungsten-replicator-4.0.0-2667425
[[email protected] tungsten-replicator-4.0.0-2667425]

128主机(mysql)上:

[[email protected] tungsten-replicator-4.0.0-2667425] ./tools/tpm install alpha /
–info /
–master=192.168.67.128 /
–datasource-mysql-conf=/etc/my.cnf /
–enable-heterogenous-master=true /
–replication-user=tungsten_alpha /
–replication-password=ts /
–install-directory=/opt/continuent/alpha /
–start-and-report

129主机(mongo)上:

[[email protected] tungsten-replicator-4.0.0-2667425]./tools/tpm install alpha /
–info /
–datasource-type=mongodb /
–master=192.168.67.128 /
–members=192.168.67.129 /
–enable-heterogenous-slave=true /
–topology=master-slave /
–install-directory=/opt/continuent/alpha /
–start-and-report
3 如果两个主机的 state 都是 online 说明 两个主机的 tungsten-replicator 都正常运行了

4 在mysql 主机上的 tungsten_alpha 库中 创建一张表,然后在mongo主机中查看 同步是否成功

转载于:http://my.oschina.net/wanglin123/blog/524123



分享给朋友:
您可能感兴趣的文章:
随机阅读: