keepalived:
ipvs---》HA
ipvs---》VIP
vrrp(虛擬路由冗餘協議):
1 master,n backup
rip2,ospf
ipvs:kernel
keepalived+nginx
keepalived+haproxy
配置keepalived+Apache:兩個節點配置一樣(採用DR模型)
node1(master):172.16.100.6
yum intall keepalived
yum install ipvsadm
vim /etc/keepalived.conf
global_defs {
notification_email {br/>root@localhost
}
notification_email_from keepavlied@locahost
smtp_server 127.0.0.1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
adver_int 1
authentication {
auth_type PASS
auth_pass keepalivedpass
}
virtual_ipaddress {
172.16.100.1/16 dev eht0 label eth0:0
}
}
virtual_server 172.16.100.1 80 {
delay_loop
lb_algo rr
lb_kind DR
net_mask 255.255.0.0
protocol TCP
real_server 172.16.100.11 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 2
nb_get_retry 3
delay_before_retry 1
}
}
real_server 172.16.100.12 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 2
nb_get_retry 3
delay_before_retry 1
}
}
}
scp keepalived.conf node2:/etc/keepadlived
node2(slave):
yum install ipvsadm keepalived
vim /etc/keepalived.conf
global_defs {
notification_email {br/>root@localhost
}
notification_email_from keepavlied@locahost
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
adver_int 1
authentication {
auth_type PASS
auth_pass keepalivedpass
}
virtual_ipaddress {
172.16.100.1/16 dev eht0 label eth0:0
}
}
virtual_server 172.16.100.1 80 {
delay_loop
lb_algo rr
lb_kind DR
net_mask 255.255.0.0
protocol TCP
real_server 172.16.100.11 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 2
nb_get_retry 3
delay_before_retry 1
}
}
real_server 172.16.100.12 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 2
nb_get_retry 3
delay_before_retry 1
}
}
}
1.所有的realserver都down,如何處理?
virtual_server 192.168.1.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
net_mask 255.255.255.0
protocol TCP
sorry_server 127.0.0.1 80(加入這行,另一節點同樣配置)
}
2.自寫監控腳本,完成維護模式切換?
vim /etc/keepalive.conf(加入下面的內容,在另一節點配置同樣)
vrrp_script chk_name {
script "[ -e /etc/keepalived/down] && exit 1 || exit 0"
interval 2
weight -5
fail 2
rise 1
}
vrrp_instance VI_1 {
track_script {
chk_name
}
}
測試(在某一節點上面):touch /etc/keepalived/down
3.如何在vrrp事務發生時,發送警告信息
標題:VIP added to HA1
正文:日期 時間,HA1’s state from master to backup
vim /etc/keepalived/notify.sh
#!/bin/bash
#
contact='root@localhost'
Usage() {
echo "Usage:basename $0
{master|backup|fault} VIP"
}
Notify() {
subject="hostname
's state changed to $1"
mailbody="date +%F %T
:hostname
's state change to $1,$VIP floating."
echo $mailbody | mail -s "$subject" $contact
}
[ $# -lt 2 ] && Usage && exit
VIP=$2
case $1 in
master)
Notify master
;;
backup)
NOtify backup
;;
"fault")
Notify fault
;;
*)
Usage
exit 1
;;
esac
scp notify.sh node2:/etc/keepalived/
vim /etc/keepalived.conf(其它節點配置一樣)
vrrp_instance VI_1 {
notify_master "/etc/keepalived/notify.sh master 172.16.100.1"
notify_backup "/etc/keepalived/notify.sh backup 172.16.100.1"
notify_fault "/etc/keepalived/notify.sh fault 172.16.100.1"
}
keepalived
ipvs--》HA
ipvs:--》VIP
vrrp:將多個物理設備冗餘成一個虛擬設備