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

来源:互联网 发布:抽奖软件免费下载 编辑:程序博客网 时间:2024/05/16 10:20
 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、[root@localhost ~] useradd tungsten
2、[root@localhost ~] passwd tungsten

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

128主机:
[root@localhost ~] sudo usermod -G mysql tungsten

129主机
[root@localhost ~] sudo usermod -G mongod tungsten

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

[root@localhost ~] chmod 740 /etc/sudoers
[root@localhost ~] vi /etc/sudoers

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

4 切换到 tungsten 用户下

[root@localhost ~] su - tungsten

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

[tungsten@localhost ~] ssh-keygen -t rsa

6 修改 limit 文件

[tungsten@localhost ~] vi /etc/security/limits.conf

添加下面一行:
* - nofile 65535

7 检查修改是否成功

[tungsten@localhost ~] ulimit -n
65535

8 配置hosts

[tungsten@localhost ~] sudo vi /etc/hosts
127.0.0.1 localhost
192.168.67.128 host1
192.168.67.129 host2

9 测试主机

[tungsten@localhost ~] uname -n
host1

10 测试ip地址

[tungsten@localhost ~] hostname –ip-address

11 防火墙设置

[tungsten@localhost ~] iptables -A INPUT -i lo -m state –state NEW -j ACCEPT

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

[tungsten@localhost ~] cp .ssh/id_rsa.pub .ssh/id_rsa /home/tungsten/.ssh

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

[tungsten@localhost ~] cat .ssh/id_rsa.pub >> .ssh/authorized_keys

14 修改权限

[tungsten@localhost ~] chmod 700 ~/.ssh
[tungsten@localhost ~] 600 ~/.ssh/*

15 测试主机间ssh

[tungsten@localhost ~] ssh tungsten@host2

16 修改mysql配置

[tungsten@localhost ~] 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 用户

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

三 安装服务:

1 创建 tungsten-replication 软件主目录

[tungsten@localhost ~] sudo mkdir /opt/continuent/soft
[tungsten@localhost ~] sudo chown -R tungsten /opt/continuent
[tungsten@localhost ~] sudo chmod 700 /opt/continuent

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

[tungsten@localhost ~] cd /opt/continuent/soft
[tungsten@host1 software] ll
[tungsten@host1 software] tungsten-replicator-4.0.0-2667425.tar.gz
[tungsten@host1 software] tar -zxvf tungsten-replicator-4.0.0-2667425.tar.gz
[tungsten@host1 software] cd tungsten-replicator-4.0.0-2667425
[tungsten@host1 tungsten-replicator-4.0.0-2667425]

128主机(mysql)上:

[tungsten@host1 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)上:

[tungsten@host2 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

0 0