Install Haproxy Keppalived on CentOS 6.5
Haproxy/Keepalived Server1: 192.168.20.12
Haproxy/Keepalived Server2: 192.168.20.13
Haproxy/Keepalived VIP: 192.168.20.10
disable selinux and iptables
service iptables stop
chkconfig iptables off; chkconfig ip6tables off
setenforce 0
vi /etc/selinux/config
SELINUX=disabled
Haproxy/Keepalived Server1:
1. echo "net.ipv4.ip_nonlocal_bind = 1" >> /etc/sysctl.conf
sysctl -p
yum -y install keepalived haproxy
2. cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.bak
vi /etc/keepalived/keepalived.conf
global_defs {
router_id centos65-2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.20.10
}
}
下面的都删除
1). Priority value will be higher on Master server
2). virtual_router_id should be same on both servers
3). By default single vrrp_instance support up to 20 virtual_ipaddress
3. service keepalived start; chkconfig keepalived on
ip addr show eth0
4. vi /etc/haproxy/haproxy.cfg
注释原有的frontend和backend
listen stats 192.168.20.12:80
mode http
stats enable
stats uri /stats
stats realm HAProxy\ Statistics
stats auth admin:password
service haproxy start; chkconfig haproxy on
Haproxy/Keepalived Server2:
1. echo "net.ipv4.ip_nonlocal_bind = 1" >> /etc/sysctl.conf
sysctl -p
yum -y install keepalived haproxy
2. cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.bak
vi /etc/keepalived/keepalived.conf
global_defs {
router_id centos65
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.20.10
}
}
下面的都删除
3. service keepalived start; chkconfig keepalived on
ip addr show eth0
4. vi /etc/haproxy/haproxy.cfg
注释原有的frontend和backend
listen stats 192.168.20.13:80
mode http
stats enable
stats uri /stats
stats realm HAProxy\ Statistics
stats auth admin:password
service haproxy start; chkconfig haproxy on
Haproxy使用自己的log:
vi /etc/rsyslog.conf
# Provides UDP syslog reception
$ModLoad imudp
$UDPServerRun 514
local2.* /var/log/haproxy.log
*.info;mail.none;authpriv.none;cron.none;!local2 /var/log/messages
service rsyslog restart
service haproxy restart
针对Apache的haproxy配置:
listen apache 192.168.20.10:80
balancesource
capturecookie vgnvisitor= len 32
cookieSERVERID insert indirect nocache
modehttp
optionforwardfor
optionhttpchk
optionhttpclose
rspidel^Set-cookie:\ IP=
server web01 192.168.20.35:80 cookie web01 check inter 2000 rise 3 fall 3
server web02 192.168.20.36:80 cookie web02 check inter 2000 rise 3 fall 3
页:
[1]