使用代理复制 TCP 流量

发布于 2024-12-02 07:20:01 字数 498 浏览 1 评论 0原文

我需要从一台机器(端口)发送(重复)流量到两台不同的机器(端口)。我还需要处理 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

慢慢从新开始 2024-12-09 07:20:01

我为此目的创建了一个代理。

https://github.com/chrislusf/teeproxy

用法

./teeProxy -l :8888 -a localhost:9000 -b localhost:9001

tee-proxy 是一个反向代理。对于每个传入请求,它将请求克隆为 2 个,然后将它们转发到 2 个服务器。来自服务器 a 的结果照常返回,但来自服务器 b 的结果被忽略。

tee-proxy 处理 GETPOST 和其他 HTTP 方法。

I have created a proxy just for this purpose.

https://github.com/chrislusf/teeproxy

Usage

./teeProxy -l :8888 -a localhost:9000 -b localhost:9001

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 server b is ignored.

tee-proxy handles both GET, POST, and other HTTP methods.

圈圈圆圆圈圈 2024-12-09 07:20:01

iptables 实验性 ROUTE 目标 怎么样?它有一个用于镜像流量的“tee”选项:

http:// /www.netfilter.org/projects/patch-o-matic/pom-external.html#pom-external-ROUTE

这可以让你用类似的方式镜像流量:

iptables -A PREROUTING -t mangle -p tcp --dport 80 -j ROUTE --gw 1.2.3.4 --tee
iptables -A POSTROUTING -t mangle -p tcp --sport 80 -j ROUTE --gw 1.2.3.4 --tee

第二台机器需要位于同一台机器上子网并且会需要监听目标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:

iptables -A PREROUTING -t mangle -p tcp --dport 80 -j ROUTE --gw 1.2.3.4 --tee
iptables -A POSTROUTING -t mangle -p tcp --sport 80 -j ROUTE --gw 1.2.3.4 --tee

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.

爱*していゐ 2024-12-09 07:20:01

尝试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.

帅的被狗咬 2024-12-09 07:20:01

我还使用 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.

感受沵的脚步 2024-12-09 07:20:01

我需要一些可以处理 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文