使用代理复制 TCP 流量
我需要从一台机器(端口)发送(重复)流量到两台不同的机器(端口)。我还需要处理 TCP 会话。
在开始时我使用了 em-proxy ,但在我看来,开销是相当大的大(占用 CPU 的 50% 以上)。 然后我安装了 haproxy 并设法重定向流量(不重复)。开销是合理的(低于 5%)。
问题是我无法在 haproxy 配置文件中说出以下内容:
- 监听特定地址:端口以及您发现的在两个不同的地址上发送的任何内容 机器:端口并丢弃其中一台的答案。
Em-proxy 代码非常简单,但在我看来,EventMachine 生成 很多开销。
在我挖掘 haproxy 代码并尝试更改(重复流量)之前,我想 知道那里有类似的东西吗?
谢谢。
I need to send (duplicate) traffic from one machine (port) and to two different machines (ports). I need to take care of TCP session as well.
In the beginnig I used em-proxy, but it seems to me that the overhead is quite large (it goes over 50% of cpu).
Then I installed haproxy and I managed to redirect traffic (not to duplicate). The overhead is reasonable (less than 5%).
The problem is that I could not say in haproxy config file the following:
- listen on specific address:port and whatever you find send on the two different
machines:ports and discard the answers from one of them.
Em-proxy code for this is quite simple, but it seems to me that EventMachine generates
a lot of overhead.
Before I dig in haproxy code and try to change (duplicate traffic) I would like
to know is there something similar out there?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我为此目的创建了一个代理。
https://github.com/chrislusf/teeproxy
用法
tee-proxy 是一个反向代理。对于每个传入请求,它将请求克隆为 2 个,然后将它们转发到 2 个服务器。来自服务器
a
的结果照常返回,但来自服务器b
的结果被忽略。tee-proxy 处理
GET
、POST
和其他 HTTP 方法。I have created a proxy just for this purpose.
https://github.com/chrislusf/teeproxy
Usage
tee-proxy is a reverse proxy. For each incoming request, it clones the request into 2 and then forwards them to 2 servers. The results from server
a
is returned as usual, but the results from serverb
is ignored.tee-proxy handles both
GET
,POST
, and other HTTP methods.iptables 实验性
ROUTE 目标
怎么样?它有一个用于镜像流量的“tee”选项:http:// /www.netfilter.org/projects/patch-o-matic/pom-external.html#pom-external-ROUTE
这可以让你用类似的方式镜像流量:
第二台机器需要位于同一台机器上子网并且会需要监听目标IP地址(并且不回复arps)或者混杂监听。
How about the iptables experimental
ROUTE target
? It has a "tee" option for mirroring traffic:http://www.netfilter.org/projects/patch-o-matic/pom-external.html#pom-external-ROUTE
Which would let you mirror traffic with something like:
The second machine would need to be on the same subnet and would either need to listen on the target IP address (and not reply to arps) or listen promiscuously.
尝试https://github.com/agnoster/duplicator。
我尝试了 teeproxy 但除了 GET 之外的一些请求得到了奇怪的结果。
Try https://github.com/agnoster/duplicator.
I tried teeproxy but got strange results with some requests other than GET's.
我还使用 Node.js 编写了一个反向代理/负载均衡器,用于类似的目的(它只是为了好玩,目前尚未准备好用于生产)。
https://github.com/losnir/ampel
非常有主见,目前支持:
GET
使用循环选择 (1:1)POST
使用请求拆分。没有“主”和“影子”的概念——第一个响应的后端将为客户端请求提供服务,然后所有其他响应都将被丢弃。如果有人发现它有用,那么我可以改进它以使其更加灵活。
I have also written a reverse proxy / load balancer for a similar purpose with Node.js (it is just for fun, not production ready at the moment).
https://github.com/losnir/ampel
It is very opinionated, and currently supports:
GET
Using round-robin selection (1:1)POST
Using request splitting. There is no concept of "master" and "shadow" -- the first backend that responds is the one that will serve the client request, and then all of the other responses will be discarded.If someone finds it useful then I can improve it to be more flexible.
我需要一些可以处理 TCP 流量的东西,但不具有侵入性,因此无法在中间放置一些东西作为反向代理。
我所做的基本上就是使用 tcpdump/wireshark 逻辑(数据包嗅探)将其包装在 Go 进程中,您可以配置该进程来执行一些操作。
对于可能有帮助的人,可以在这里找到代码:https://github.com/RobinUS2/teecp
I needed something that could tee the TCP traffic as well, but being not intrusive, thus not being able to put something in-between as a reverse proxy for example.
What I did is basically did is use the tcpdump/wireshark logic (packet sniffing) wrap it in a Go process that you can configure to do some things.
For whom it may be helpful the code can be found here: https://github.com/RobinUS2/teecp