tcpcopy+mysql压力测试


声明:本文转载自https://my.oschina.net/u/3023401/blog/1791695,转载目的在于传递更多信息,仅供学习交流之用。如有侵权行为,请联系我,我会及时删除。

一、tcpcopy工具介绍

tcpcopy 是一个分布式在线压力测试工具,可以将线上流量拷贝到测试机器,实时的模拟线上环境,达到在程序不上线的情况下实时承担线上流量的效果,尽早发现 bug,增加上线信心。

tcpcopy 的优势在于其实时性及真实性,除了少量的丢包,完全拷贝线上流量到测试机器,真实的模拟线上流量的变化规律。

 

二、tcpcopy原理

 

tcpcopy新版架构图

tcpcopy包含三部分:online server、assistant server、target server

tcpcopy拷贝一次流量访问的步骤如下

1、一个访问请求到达线上内核后端机; 2、socket 包在 IP 层被拷贝了一份传给tcpcopy 进程; 3、tcpcopy 修改包的目的及源地址,发给测试内核后端机; 4、拷贝的包到达测试内核后端机; 5、测试内核后端机的推荐内核处理访问,并返回结果; 6、返回结果在 IP 层被截获、丢弃,由 intercept 拷贝返回结果的 IP header 返回; 7、IP header 被发送给线上内核后端机的 tcpcopy 进程。

 

三、tcpcopy搭建

3.1  服务器规划

角色 主机名 mysql端口
online server test00 3308(5.6)
assistant server offline01  
target server offline02 3318(5.7)

3.2  tcpcopy安装及配置

安装依赖

# yum -y install libpcap-devel

intercept安装

# git clone git://github.com/session-replay-tools/intercept.git # cd intercept # ./configure # make && make install

tcpcopy安装

# git clone git://github.com/session-replay-tools/tcpcopy.git # cd tcpcopy # ./configure # make && make install 

 

四、开启tcpcopy流量复制

4.1  target server上操作:

# route add -net 10.0.0.8 netmask 255.255.252.0 gw 10.0.0.0

 

成功后可以看到

# ss -an |head State      Recv-Q Send-Q        Local Address:Port          Peer Address:Port LISTEN     0      0                 127.0.0.1:199                      *:*     LISTEN     512    0                         *:80                       *:*     ESTAB   0      0              192.168.0.230:80           10.10.10.1:62602 ESTAB   0      0              192.168.0.230:80           10.10.10.4:54595 ESTAB   0      0              192.168.0.230:80           10.10.10.3:53566 ESTAB   0      0              192.168.0.230:80           10.10.10.6:49260 ESTAB   0      0              192.168.0.230:80           10.10.10.8:57598 ESTAB   0      0              192.168.0.230:80           10.10.10.7:64454

4.2  assistant server上操作(root privilege):

# cd /usr/local/intercept/sbin/ # ./intercept -i bond1 -F 'tcp and src port 3318' -d

成功后可以看到

# ss -an |grep 36524 LISTEN     0      5                         *:36524                    *:*      ESTAB      0      66             192.168.0.219:36524           192.168.0.8:49034  ESTAB      0      0              192.168.0.219:36524           192.168.0.8:49035  ESTAB      0      66             192.168.0.219:36524           192.168.0.8:49032  ESTAB      0      0              192.168.0.219:36524           192.168.0.8:49033

4.3  online source server 上操作(root privilege):

# cd /usr/local/tcpcopy/sbin/ # ./tcpcopy -x 3308-10.0.0.1:3318 -s 10.0.0.2 -c 10.0.0.8 -d

成功后可以看到

#ss -an|grep 192.168.0.219 ESTAB      0      0                192.168.0.8:49034         192.168.0.219:36524  ESTAB      0      0                192.168.0.8:49035         192.168.0.219:36524  ESTAB      0      0                192.168.0.8:49032         192.168.0.219:36524  ESTAB      0      0                192.168.0.8:49033         192.168.0.219:36524

 

五、tcpcopy遇到的坑

1、tcpcopy log日志提示many connections cant established

把tcpcopy指定的-c 伪装客户端ip换成和线上一致的,可以ping通的网段就可以

2、大多数云环境设置了安全限制,一个网卡无法绑定2个IP,所以online server则会拒绝发送复制包,在线上抓包就会显示

# tcpdump -i eth0 -nn port 3306 and host 1.1.1.4  11:53:58.573735 IP 10.0.0.1.https > 10.0.0.2.37121: Flags [R.], seq 0, ack 2906947315, win 0, length 0 11:53:58.573774 IP 10.0.0.2.37121 > 10.0.0.1.http: Flags [.], ack 2906947314, win 1024, length 0 11:53:58.573812 IP 10.0.0.1.http > 10.0.0.2.37121: Flags [R], seq 2906947314, win 0, length 0 

 

参考:

https://mfcheer.github.io/20170228-index.html

http://ju.outofmemory.cn/entry/106907

http://www.itts-union.com/2814.html

http://www.361way.com/tcpcopy-online-offline/3510.html

https://github.com/session-replay-tools/tcpcopy

为了方便大家交流,本人开通了微信公众号和QQ群,QQ群:291519319,喜欢技术的一起来交流吧

本文发表于2018年04月09日 22:38
(c)注:本文转载自https://my.oschina.net/u/3023401/blog/1791695,转载目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如有侵权行为,请联系我们,我们会及时删除.

阅读 2230 讨论 0 喜欢 0

抢先体验

扫码体验
趣味小程序
文字表情生成器

闪念胶囊

你要过得好哇,这样我才能恨你啊,你要是过得不好,我都不知道该恨你还是拥抱你啊。

直抵黄龙府,与诸君痛饮尔。

那时陪伴我的人啊,你们如今在何方。

不出意外的话,我们再也不会见了,祝你前程似锦。

这世界真好,吃野东西也要留出这条命来看看

快捷链接
网站地图
提交友链
Copyright © 2016 - 2021 Cion.
All Rights Reserved.
京ICP备2021004668号-1