Rho*_*ron 5 transparent-proxy haproxy
好的,所以我有一个安装了 HAProxy 的服务器盒,我需要它将流量转发到两个 MySQL 服务器。它们都位于完全不同的数据中心。当我从配置中删除它时它会起作用:
source 0.0.0.0 usesrc clientip
但是,启用后我无法从 MySQL 服务器获得响应。
我在 HAProxy 服务器上有这些 IPTables 规则:
iptables -t mangle -N DIVERT
iptables -t mangle -A PREROUTING -p tcp -m socket -j DIVERT
iptables -t mangle -A DIVERT -j MARK --set-mark 111
iptables -t mangle -A DIVERT -j ACCEPT
ip rule add dev eth0 fwmark 111 lookup 100
ip route add local 0.0.0.0/0 dev lo table 100
并且无法建立连接。但是,当我添加此内容时:
iptables -A POSTROUTING -t nat -j MASQUERADE
它可以工作,但没有发送客户端 IP,只是发送代理 IP。
MySQL 服务器配置为将 HAProxy 服务器的 ip 作为其默认网关。
我不确定这是否可能,我已经被这个问题困扰了好几天了。
我的 HAProxy 配置:
global
log 127.0.0.1 local0 debug
daemon
defaults
log global
retries 2
#option dontlognull
option tcp-smart-accept
option tcp-smart-connect
option tcplog
option log-health-checks
timeout connect 3000
timeout server 5000
timeout client 5000
frontend mysql-frontend
bind 100.111.111.111:3306 transparent
default_backend mysql-backend
backend mysql-backend
mode tcp
source 0.0.0.0 usesrc clientip
option mysql-check user haproxy_check
server mysql1 192.111.111.111:3306 check
server mysql2 200.111.111.111:3306 check
Run Code Online (Sandbox Code Playgroud)
其中一台 MySQL 服务器的路由表:
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 100.111.111.111 0.0.0.0 UG 2 0 0 eth0
100.111.111.111 0.0.0.0 255.255.255.255 UH 2 0 0 eth0
192.111.111.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
HAProxy 框的 Sysctl:
net.ipv4.ip_forward = 1
net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.all.accept_redirects = 1
net.ipv4.conf.all.send_redirects = 1
net.ipv4.conf.eth0.send_redirects = 1
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.conf.default.rp_filter = 2
net.ipv4.conf.default.accept_source_route = 0
TProxy 模块也被编译到 HAProxy 中,并且所需的内核模块也被启用。
也只有一个接口,eth0。
请让我知道我做错了什么,或者这是否可能!
谢谢!
归档时间: |
|
查看次数: |
10696 次 |
最近记录: |