依赖 libpcap

线上服务器安装

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

下载后解压

#--pcap-capture 默认raw socket方式抓包,添加这个参数后改为pcap方式抓包,默认抓包方式不用加-F

#--pcap-send 测试端获取不到流量,iptables的问题,线上服务器又不允许修改时添加

./configure --prefix=/usr/local/tcpcopy --pcap-capture

make && make install

辅助服务器安装

https://github.com/session-replay-tools/intercept.git

下载后解压

./configure --prefix=/usr/local/intercept

make && make install

1.同网段环境

192.168.1.2 线上服务器

192.168.1.3 测试服务器(可以将辅助服务安装到测试服务上面)

192.168.1.4 辅助服务器

#启动http服务

192.168.1.2 192.168.1.3

python -m SimpleHTTPServer 8055

#启动辅助服务

192.168.1.4

/usr/local/intercept/sbin/intercept -i eth0 -F  'tcp and src port 8055' -d

192.168.1.2

#复制流量-c修改访问的ip

/usr/local/tcpcopy/sbin/tcpcopy -F 'tcp and dst port 8055' -x 8055-192.168.1.3:8055 -s 192.168.1.4 -c 172.16.55.x -d

192.168.1.3

#静态路由,将172.16.55的包全部转到辅助服务器

route add -net 172.16.55.0 netmask 255.255.255.0 gw 192.168.1.4

2.跨网段

192.168.1.2 线上服务器

192.168.2.2 测试服务器(可以将辅助服务安装到测试服务上面)

#启动http服务

192.168.1.2 192.168.2.2

python -m SimpleHTTPServer 8055

#启动辅助服务

192.168.2.2

/usr/local/intercept/sbin/intercept -i eth0 -F  'tcp and src port 8055' -d

192.168.1.2

#复制流量-c 包装为tcpcopy服务器上的网段ip,不能是和192.168.2.2通讯的ip,所以这里包装为192.168.1.3

/usr/local/tcpcopy/sbin/tcpcopy -F 'tcp and dst port 8055' -x 8055-192.168.2.2:8055 -s 192.168.2.2 -c 192.168.1.3 -d

3.iptables问题又无法修改,或者tcpcopy丢包、效率低

#注意这里安装时添加了--pcap-send

./configure --prefix=/usr/local/tcpcopy --pcap-capture --pcap-send #测试端获取不到流量,iptables的问题,线上服务器又不允许修改时添加

make && make install

192.168.1.2 线上服务器

192.168.2.2 测试服务器(可以将辅助服务安装到测试服务上面)

#启动http服务

192.168.1.2 192.168.2.2

python -m SimpleHTTPServer 8055

#启动辅助服务

192.168.2.2

/usr/local/intercept/sbin/intercept -i eth0 -F  'tcp and src port 8055' -d

192.168.1.2

#复制流量-c 包装为tcpcopy服务器上的网段ip,不能是和192.168.2.2通讯的ip,所以这里包装为192.168.1.3

#/usr/local/tcpcopy/sbin/tcpcopy -x 线上服务器端口@线上服务器MAC-测试服务器IP:测试服务器端口@线上服务器到测试服务器的下一跳MAC(同网段则是测试服务器MAC,不同网段则是线上服务器下一跳MAC) -o 与测试服务器通讯的接口 -c 包装的IP -s 辅助服务器IP -d

/usr/local/tcpcopy/sbin/tcpcopy -F 'tcp and dst port 8055' -x 8055@00:A3:81:CC:88:BD-192.168.2.2:8055@00:B3:A1:AC:C8:BA -o eth0 -c 192.168.1.3  -s 192.168.2.2 -d

dst是destination的缩写,表目的
src是source的缩写,表源

tcpcopy与intercept的-F写法与tcpdump的过滤方式一样

#参考#https://www.cnblogs.com/phennry/p/6382755.html?utm_source=itdadao&utm_medium=referral
#https://github.com/session-replay-tools/tcpcopy/issues/173
#https://blog.csdn.net/wangbin579/article/details/10148247

tcpcopy 流量复制的更多相关文章

  1. TCPCopy 线上流量复制工具

    TCPCopy是一种重放TCP流的工具,使用真实环境来测试互联网服务器上的应用程序. 一.描述: 虽然真实的实时流量对于Internet服务器应用程序的测试很重要,但是由于生产环境中的情况很负责,测试 ...

  2. goreplay HTTP-HTTPS流量复制工具

    goreplay相比tcpcopy只能复制HTTP和HTTPS的流量 goreplay编译很麻烦,就直接使用编译好的版本 gor_0.10.1_x64.tar.gz 支持centos5,测试的是cen ...

  3. 高并发 Nginx+Lua OpenResty系列(11)——流量复制/AB测试/协程

    流量复制 在实际开发中经常涉及到项目的升级,而该升级不能简单的上线就完事了,需要验证该升级是否兼容老的上线,因此可能需要并行运行两个项目一段时间进行数据比对和校验,待没问题后再进行上线.这其实就需要进 ...

  4. gor实现线上HTTP流量复制压测引流

    一.使用背景 gor 是一款go语言实现的简单的http流量复制工具,它的主要目的是使你的生产环境HTTP真实流量在测试环境和预发布环境重现.只需要在 代理例如nginx入口服务器上执行一个进程,就可 ...

  5. Nginx流量复制

    1. 需求 将生产环境的流量拷贝到预上线环境或测试环境,这样做有很多好处,比如: 可以验证功能是否正常,以及服务的性能: 用真实有效的流量请求去验证,又不用造数据,不影响线上正常访问: 这跟灰度发布还 ...

  6. 使用traefik进行流量复制

    文章转载自:https://mp.weixin.qq.com/s/nMMN7hAJK6SFn1V1YyxvHA Traefik 2.0 还引入了镜像服务,一种可以将流入流量复制并同时将其发送给其他服务 ...

  7. nginx mirror/post_action+gor实现https流量复制

    关于gor: 参考: https://www.cnblogs.com/jinjiangongzuoshi/p/11773070.html https://github.com/buger/gorepl ...

  8. nginx_mirror_module流量复制在项目中的应用

    参考文档:https://my.oschina.net/andChow/blog/2873870 https://blog.csdn.net/lancerh/article/details/88645 ...

  9. 使用tcpcopy拷贝线上流量压测测试环境

    tcpcopy项目地址:https://github.com/session-replay-tools/tcpcopy 作者地址:http://blog.csdn.net/wangbin579 1:环 ...

随机推荐

  1. [洛谷P2495][SDOI2011]消耗战

    题目大意:有一棵$n(n\leqslant2.5\times10^5)$个节点的带边权的树,$m$个询问,每次询问给出$k(\sum\limits_{i=1}^mk_i\leqslant5\times ...

  2. BZOJ5338:[TJOI2018]异或——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=5338 现在有一颗以1为根节点的由n个节点组成的树,树上每个节点上都有一个权值vi. 现在有Q 次操 ...

  3. BUG:Open quote is expected for attribute "{1}" associated with an element type "id".

    BUG原因:Mybatis的xml文件中id缺少双引号: 正确的应该是:

  4. Codeforces Round #345 (Div. 2) C (multiset+pair )

    C. Watchmen time limit per test 3 seconds memory limit per test 256 megabytes input standard input o ...

  5. HDU 1535 SPFA 前向星存图优化

    Invitation Cards Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  6. POJ 2289 最大流

    Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 7624   Accepted: ...

  7. java集合之深入分析ArrayList

    ArrayList特点: ArrayList方法实现: 扩容方法的实现: 源码: private void ensureCapacityInternal(int minCapacity) { //如果 ...

  8. [LeetCode] Sort Colors 对于元素取值有限的数组,只遍历一遍的排序方法

    Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...

  9. sqlserver 个人整理

    1.创建临时表(临时表的生命周期是当前回话中) //创建临时表是使用#+表名 //判断临时表是否存在 if object_id('tempdb..#ttt1') is not null Begin d ...

  10. Bzoj3481 DZY Loves Math III

    Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 310  Solved: 65 Description Input Output Sample Input ...