lvs的配置我使用了lvs+keepalived,本文不讨论lvs的配置。lvs的real server的IP为Haproxy的实际IP。当然Haproxy上还需配置虚拟IP。
一、安装
http://blog.sina.com.cn/s/blog_704836f401011u3x.htmlglobal
maxconn 32768
#chroot /usr/share/haproxy
user root
group root
daemon
nbproc 1
#debug
#quiet
defaults
log global
log 127.0.0.1:514 local3 info #我的log配置好像还有点问题。
retries 3
option redispatch
maxconn 32768
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen demo_site1
bind *:80
mode http
option httplog
balance source
source 0.0.0.0 usesrc clientip #配置全透明代理
server web_node1 192.168.1.21:80 weight 3 check
server web_node2 192.168.1.22:80 weight 3 check
option httpchk GET /robots.txt
option forwardfor
listen demo_site2
bind *:5080
mode tcp #注意一定不能使mode http
option tcplog
balance source #session保持的一种方法
source 0.0.0.0 usesrc clientip
server vod_node1 192.168.1.21:5080 weight 3 check
server vod_node2 192.168.1.22:5080 weight 3 check
2、在lo接口上配置VIP地址,ARP隐藏。
http://fengzhilinux.blog.51cto.com/1343279/373716/(关于arp_ignore介绍的较清楚)
arp_announce:
Assume that a linux box X has three interfaces - eth0, eth1 and eth2. Each interface has an IP address IP0, IP1 and IP2. When a local application tries to send an IP packet with IP0 through the eth2. Unfortunately, the target node’s mac address is not resolved. Thelinux box X will send the ARP request to know the mac address of the target(or the gateway). In this case what is the IP source address of the “ARP request message”? The IP0- the IP source address of the transmitting IP or IP2 - the outgoing interface? Until now(actually just 3 hours before) ARP request uses the IP address assigned to the outgoing interface(IP2 in the above example) However the linux’s behavior is a little bit different. Actually the selection of source address in ARP request is totally configurable bythe proc variable “arp_announce” .
方案实施工程中也发现了一些问题,最明显的就是用户通过Haproxy来访问邮件系统后真正达到邮件系统的地址都是Haproxy的地址,这就导致了一个问题,在垃圾邮件过滤的时候就无法实现基于IP的过滤,并且也无法记录IP地址信息。
注意:
1、务必参考:http://blog.sina.com.cn/s/blog_704836f401011e17.html将Haproxy配置的像个NAT: