使用redhat 6.5配置keepalived+haproxy,
node主:master
node备:backup
后端服务器1:web
后端服务器2:web2
虚拟Ip
两个节点的keepalived配置文件如下:
! Configuration File for keepalived
vrrp_script chk_http_port {
script "/etc/keepalived/check_haproxy.sh"
interval 2
weight 2
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
mcast_src_ip 10.10.13.248
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_http_port
}
virtual_ipaddress {
10.10.13.252
}
}
}
两个节点#!/bin/bash
A=`ps -C haproxy --no-header |wc -l`
if [ $A -eq 0 ];then
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
sleep 3
if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
/etc/init.d/keepalived stop
fi
fi
的脚本文件如下:
两节点的haproxy配置文件如下:
global
log 127.0.0.1 local3 err
maxconn 4096
user nobody
group nobody
daemon
nbproc 1
pidfile /usr/local/haproxy/logs/haproxy.pid
defaults
maxconn 2000
contimeout 5000
clitimeout 30000
srvtimeout 30000
mode http
log global
log 127.0.0.1 local3 err
stats uri /admin?stats
option forwardfor
frontend www
bind *:80
acl test.domain.com hdr_dom(host) -i test.domain.com
acl test.com hdr_dom(host) -i test.com
use_backend web if test.domain.com
use_backend web2 if test.com
backend web
#balance roundrobin
mode http
balance roundrobin
option httpchk /index.html
server web 10.10.13.239:80 check inter 5000 fall 3
backend web2
mode http
balance roundrobin
#balance source
option httpchk /index.html
server web2 10.10.13.238:80 check inter 5000 fall 3
当然主从相应的位置都会更改相应的值。现在问题是这样:
主节点上ping两台web服务器都能通,但是telnet web服务器的80端口不通,然后haproxy的监控页面的状态那都是down
haproxy的日志如下:
2016-09-07T16:43:17+08:00 localhost haproxy[54509]: Server web/web is DOWN, reason: Layer7 wrong status , code: 405, info: "Not Allowed", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions a ctive, 0 requeued, 0 remaining in queue.
2016-09-07T16:43:17+08:00 localhost haproxy[54509]: Server web/web is DOWN, reason: Layer7 wrong status , code: 405, info: "Not Allowed", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions a ctive, 0 requeued, 0 remaining in queue.
2016-09-07T16:43:17+08:00 localhost haproxy[54509]: backend web has no server available!
2016-09-07T16:43:17+08:00 localhost haproxy[54509]: backend web has no server available!
2016-09-07T16:43:19+08:00 localhost haproxy[54510]: Server web2/web2 is DOWN, reason: Layer7 wrong stat us, code: 405, info: "Not Allowed", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
2016-09-07T16:43:19+08:00 localhost haproxy[54510]: Server web2/web2 is DOWN, reason: Layer7 wrong stat us, code: 405, info: "Not Allowed", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
2016-09-07T16:43:19+08:00 localhost haproxy[54510]: backend web2 has no server available!
2016-09-07T16:43:19+08:00 localhost haproxy[54510]: backend web2 has no server available!
node主:master
node备:backup
后端服务器1:web
后端服务器2:web2
虚拟Ip
两个节点的keepalived配置文件如下:
! Configuration File for keepalived
vrrp_script chk_http_port {
script "/etc/keepalived/check_haproxy.sh"
interval 2
weight 2
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
mcast_src_ip 10.10.13.248
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
chk_http_port
}
virtual_ipaddress {
10.10.13.252
}
}
}
两个节点#!/bin/bash
A=`ps -C haproxy --no-header |wc -l`
if [ $A -eq 0 ];then
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
sleep 3
if [ `ps -C haproxy --no-header |wc -l` -eq 0 ];then
/etc/init.d/keepalived stop
fi
fi
的脚本文件如下:
两节点的haproxy配置文件如下:
global
log 127.0.0.1 local3 err
maxconn 4096
user nobody
group nobody
daemon
nbproc 1
pidfile /usr/local/haproxy/logs/haproxy.pid
defaults
maxconn 2000
contimeout 5000
clitimeout 30000
srvtimeout 30000
mode http
log global
log 127.0.0.1 local3 err
stats uri /admin?stats
option forwardfor
frontend www
bind *:80
acl test.domain.com hdr_dom(host) -i test.domain.com
acl test.com hdr_dom(host) -i test.com
use_backend web if test.domain.com
use_backend web2 if test.com
backend web
#balance roundrobin
mode http
balance roundrobin
option httpchk /index.html
server web 10.10.13.239:80 check inter 5000 fall 3
backend web2
mode http
balance roundrobin
#balance source
option httpchk /index.html
server web2 10.10.13.238:80 check inter 5000 fall 3
当然主从相应的位置都会更改相应的值。现在问题是这样:
主节点上ping两台web服务器都能通,但是telnet web服务器的80端口不通,然后haproxy的监控页面的状态那都是down
haproxy的日志如下:
2016-09-07T16:43:17+08:00 localhost haproxy[54509]: Server web/web is DOWN, reason: Layer7 wrong status , code: 405, info: "Not Allowed", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions a ctive, 0 requeued, 0 remaining in queue.
2016-09-07T16:43:17+08:00 localhost haproxy[54509]: Server web/web is DOWN, reason: Layer7 wrong status , code: 405, info: "Not Allowed", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions a ctive, 0 requeued, 0 remaining in queue.
2016-09-07T16:43:17+08:00 localhost haproxy[54509]: backend web has no server available!
2016-09-07T16:43:17+08:00 localhost haproxy[54509]: backend web has no server available!
2016-09-07T16:43:19+08:00 localhost haproxy[54510]: Server web2/web2 is DOWN, reason: Layer7 wrong stat us, code: 405, info: "Not Allowed", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
2016-09-07T16:43:19+08:00 localhost haproxy[54510]: Server web2/web2 is DOWN, reason: Layer7 wrong stat us, code: 405, info: "Not Allowed", check duration: 0ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
2016-09-07T16:43:19+08:00 localhost haproxy[54510]: backend web2 has no server available!
2016-09-07T16:43:19+08:00 localhost haproxy[54510]: backend web2 has no server available!
编辑回复