我目前正在尝试将 HAProxy 配置为使用虚拟 IP 在两台服务器之间进行路由。
为了测试,我创建了两个实例,172.16.4.130 和 172.16.4.131。然后我创建一个虚拟 IP 地址 172.16.4.99,使用keepalived 来桥接两台服务器。这两个服务器都在运行 apache2,它托管了一个简单的 index.html 登录页面进行测试。以上所有都在运行。
当我转到 172.16.4.99 时,页面没有加载,我也没有重定向到 index.html 页面中的任何一个。但是,我可以 ping 这个 IP 地址。我觉得这是一个简单的配置问题,由于我对 HAproxy 不是很有经验,所以我需要一些帮助。下面是我的 haproxy.cfg 文件,以及 keepalived。
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
#debug
#quiet
user haproxy
group haproxy
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen webfarm 172.16.4.99:80
mode http
stats enable
stats auth user:password
balance roundrobin
cookie JSESSIONID prefix
option httpclose
option forwardfor
option httpchk HEAD /check.txt HTTP/1.0
server webA 172.16.4.130:8080 cookie A check
server webB 172.16.4.131:8080 cookie B check
172.16.4.130 上的 keepalived.conf
vrrp_script chk_haproxy { # Requires keepalived-1.1.13
script "killall -0 haproxy" # cheaper than pidof
interval 2 # check every 2 seconds
weight 2 # add 2 points of prio if OK
}
vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101 # 101 on master, 100 on backup
virtual_ipaddress {
172.16.4.99
}
track_script {
chk_haproxy
}
}
172.16.4.131 上的 keepalived.conf:
vrrp_script chk_haproxy { # Requires keepalived-1.1.13
script "killall -0 haproxy" # cheaper than pidof
interval 2 # check every 2 seconds
weight 2 # add 2 points of prio if OK
}
vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 100 # 101 on master, 100 on backup
virtual_ipaddress {
172.16.4.99
}
track_script {
chk_haproxy
}
}