haproxy + keepalived 安裝配置
備註:
web server:192.168.10.53
web server:192.168.10.81
haproxy + keepalived 1:192.168.10.124
haproxy + keepalived 1:192.168.10.94
-----------------------------------------------
---------------------------------------------------------------------------------------
global
log 127.0.0.1 local0
maxconn 65535 #最大鏈接數
chroot /usr/local/haproxy
uid 500
gid 500
daemon
#debug
#quiet
nbproc 1 #負載均衡的併發進程數
pidfile /var/run/haproxy.pid
defaults
log global
mode http #工做模式,目前支持3種(tcp/http/health)
option httplog #日誌類別
option dontlognull
option redispatch #當serverid對應的服務器宕機後,強制定向到其餘健康的服務器上
log 127.0.0.1 local0
retries 3 #重試次數
maxconn 32000
stats enable
stats uri /haproxy-stats
stats realm Haproxy\ Statistics #提示信息
stats auth admin:admin #用戶認證/用戶名、密碼
stats hide-version #隱藏版本信息
stats refresh 10s #刷新時間
contimeout 5000 #超時時間
clitimeout 50000
srvtimeout 50000
listen appserver *:80
hash-type consistent
balance uri len 100
option httpclose #啓用被動的http鏈接關閉
server web1-53 192.168.10.53 cookie 10 weight 3 check inter 2000 rise 2 fall 3
server web2-81 192.168.10.81 cookie 20 weight 3 check inter 2000 rise 2 fall 3
-----------------------------------------------------------------------------------------------
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg # 啓動haproxy服務
cd /usr/src/keepalived-1.1.19/
./configure --prefix=/usr/local/keepalived
make
make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
mkdir /etc/keepalived
cd /etc/keepalived/
vim keepalived.conf
--------------------------------------------------------------------------------------
global_defs {
notification_email {
2669660794@qq.com
}
notification_email_from
2669660794@qq.com
smtp_server smtp.exmail.qq.com
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER #從爲BACKUP
interface eth0
virtual_router_id 50 #路由ID,可經過#tcpdump vrrp查看。
mcast_src_ip 192.168.10.124
priority 100 #從爲50
advert_int 1 #(VRRP Multicast廣播週期秒數)
garp_master_delay 1 #主從切換時間,單位爲秒。
authentication {
auth_type PASS
auth_pass wameide
}
track_interface {
eth0 #其餘要監測狀態的接口
}
virtual_ipaddress {
192.168.10.204
}
}
virtual_server 192.168.10.204 {
delay_loop 20
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.10.124 80 {
weight 1
TCP_CHECK {
connect_timeout 3
}
}
real_server 192.168.10.83 80 {
weight 1
TCP_CHECK {
connect_timeout 3
}
}
}
-------------------------------------------------------------------------------------------
/etc/init.d/keepalived restart
backup機器在此就不重複了。按照上述文檔裏同樣。只須稍微更改下里面的參數便可。