keepalived的做用:
web
主要用做RealServer的健康狀態檢查以及vim
LoadBalance主機和BackUP主機之間failover的實現。服務器
使用keepalived軟件部署網站HA集羣: 可以實現任意單故障節點的高可用集羣網絡
1、前期準備
ide
一、在兩臺網站服務器上安裝keepalived軟件(4.51,4.52)oop
二、查看配置的路徑: rpm -qc keepalived 測試
/etc/keepalived/keepalived.conf網站
/etc/sysconfig/keepalivedspa
2、修改服務的主配置文件: vim /etc/keepalived/keepalived.conform
一、下面的是更改的配置文件
15 vrrp_instance haweb {
16 state MASTER
17 interface eth0
18 virtual_router_id 51
19 priority 150
20 advert_int 1
21 authentication {
22 auth_type PASS
23 auth_pass 123456
24 }
25 virtual_ipaddress {
26 192.168.4.253
27 }
28 }
二、修改備服務器的主配置文件:vim /etc/keepalived/keepalived.conf
把優先級調低:priority 100
三、分別重啓兩臺服務器的keepalived服務
四、查看是否獲取到VIP地址:
ip addr show | grep 192.168.4.
五、測試:當4.51的網站服務停掉時,VIP不會釋放,需監控網站服務.
使用keepalived+lvs作高可用HA集羣
1、前期準備工做:
一、準備四臺主機,兩臺作web,兩臺作LVS+keepalived
二、分別安裝httpd軟件和ipvsadm
2、網站服務器爲4.51和4.52:
一、修改網絡接口運行參數,
cd /proc/sys/net/ipv4/conf/
echo 1 > lo/arp_ignore //忽略廣播包
echo 2 > lo/arp_announce //兄弟接口接收和發送arp包
echo 1 > all/arp_ignore
echo 2 > all/arp_announce
如需開機自動配置,需寫在vim /etc/sysctl.conf
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
sysctl -p 讀一下,使其生效
二、綁定VIP地址:4.253 vim /etc/rc.d/rc.local ifconfig lo:1 192.168.4.253/32
2、配置分發器:4.53和4.54
一、安裝軟件ipvsadm
二、在主機上都安裝keepalived軟件
三、修改4.53服務器的主配置文件: vim /etc/keepalived/keepalived.conf
vrrp_instance VI_3 {
state MASTER
interface eth0
virtual_router_id 53
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.4.253
}
}
virtual_server 192.168.4.253 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
protocol TCP
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
real_server 192.168.4.51 80 {
weight 1
}
real_server 192.168.4.52 80 {
weight 1
}
}
四、修改4.54服務器的配置文件: vim /etc/keepalived/keepalived.conf
state BACKUP
priority 100
五、重啓服務,驗證.