官方文档:感谢wangbin
https://github.com/session-replay-tools/mysql-replay-module
http://blog.youkuaiyun.com/wangbin579/article/details/8950282
项目需求需要安装tcpcopy在线copy流量,测试测试机mysql性能。
10.0.0.95 线上数据库
10.0.0.96测试数据库
10.0.0.97作为assistant server
搭建过程
10.0.0.97
Installation
Getting intercept installed on the assistant server
git clone git://github.com/session-replay-tools/intercept.git
cd intercept
./configure --with-resp-payload
make
make install
报错的话执行
yum -y install pcre
yum -y install libpcap*
yum install -y zlib
安装完执行
cat /proc/sys/net/ipv4/ip_forward
确保值为0
/usr/local/intercept/sbin/intercept -i eth0 -F 'tcp and src port 3306' -d
这条命令不执行,主库上的tcpcopy起不来
3306是10.0.0.96:3306,经过10.0.0.97过滤网关丢弃,类似与黑洞,测试机结果返回包扔进黑洞
10.0.0.95 线上数据库安装
Getting tcpcopy installed on the online server
git clone git://github.com/session-replay-tools/tcpcopy.git
cd tcpcopy
git clone git://github.com/session-replay-tools/mysql-replay-module.git
./configure --set-protocol-module=mysql-replay-module
make
make install
安装完执行
[root@db95 ~]# cat /usr/local/tcpcopy/conf/plugin.conf
user 用户名@密码;
/usr/local/tcpcopy/sbin/tcpcopy -x 3306-10.0.0.96:3306 -s 10.0.0.97
本机的3306数据库端口,转发到10.0.0.96的3306数据库端口上,-s是经过10.0.0.97过滤
10.0.0.96测试数据库
route add -host 客户端IP或者ip段 gw 10.0.0.97
关键所在
如果需要调整,删除动态网关 route delete -host 10.0.9.34 gw 10.0.0.97
route add -net 10.0.0.0/255.255.0.0 gw 10.0.9.53 有风险,只有10.0.9.53可以ping通,可以连接
就可以在客户端IP 上访问10.0.0.95 线上数据库,然后访问数据包可以实时同步到10.0.0.96上,执行相同的操作。
10.0.0.95线上数据库的日志
[root@mc_a_db95 ~]# tailf /usr/local/tcpcopy/logs/error_tcpcopy.log
10.0.0.97assistant server上的日志
tailf /usr/local/intercept/logs/error_intercept.log
总结:mysql有长连接,如果要完全转发,可以重启主库mysql,刷新链接,让所有链接得到转发。vip也可以转发