haproxy透明代理配置.pdfVIP

  • 62
  • 0
  • 约3.12千字
  • 约 3页
  • 2015-07-22 发布于河北
  • 举报
Haproxy使用tproxy实现透明代理 实验环境 Server1为代理服务器,有两个网卡 eth0:5 用于对外服务 eth1: gw 54 用于内网通讯 Server2为应用服务器,一块网卡 eth0: gw service的网关一定要配成service的内 IP 准备工作 1.检查系统内科是否已支持tproxy 2.安装haproxy 编译参数 make TARGET=linux26 USE_LINUX_TPROXY=1 make install PREFIX=/usr/local/haproyx 安装完成后,检查haproxy是否支持tproxy Haproxy.cfg global daemon statssocket/var/run/haproxy.statmode600 log local4 maxconn40000 ulimit-n80013 pidfile/var/run/haproxy.pid defaults logglobal mode http contimeout 4000 clitimeout 42000 srvtimeout 43000 balanceroundrobin listen VIP-222 bind 22:80 mode http option forwardfor sourceusesrcclientip cookie SERVERIDinsertnocacheindirect serverserver1 :80weight 1cookieserver1check server backup :80backup optionredispatch 在server1上配置网络、iptables及内核参数(可加入/etc/rc.local) net.ipv4.ip_forward= 1 net.ipv4.conf.all.send_redirects= 1 net.ipv4.conf.default.send_redirects= 1 net.ipv4.conf.all.forwarding= 1 iptables-t mangle -N DIVERT #在mangle 中新建一条规则链DIVERT iptables-t mangle -A PREROUTING -p tcp -m socket -j DIVERT #凡进入PREROUTING链的报文都跳转去新定义的DIVERT链 iptables-t mangle -A DIVERT -j MARK --set-mark 1 #凡进入DIVERT链的报文均使用mangle表的标记功能标记上1标记 iptables-t mangle -A DIVERT -j ACCEPT #进入 DIVERT链的报文均导入路由 ip rule add fwmark 1 lookup 100 #添加100策略路由表,并将由 iptables打了标记1的数据报文从100路由表规定路由流动 可以在/etc/iproute2/rt_tables查看或者使用此命令查看 ip rule sh本机的所有路由表 ip route add local/0 dev lotable 100 #由于到达本地的数据包要想成功到达,必须要找到一条 local路由(类型对即可,无需非要 在 local表),因此为路由表100确定默认路由,进入环流 最后启动相关软件即可 Linux路由查找流程 在Linux中,内置了三张路由表: local,main,default,其中 local路由表的优先级最高,并且不能被替换,在有数据包进 来的时候,首先无条件的查找 local路由表,如果找到了路由,则数据包就是发往本机的, 如果找不到,则接着在其它的路由表中进行查找。使用 iproute lstable local命令可以 看到 local表的内容,比如机器的eth0网卡上配有,则在local表中会有如 下的路由: local dev eth0

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档