keeaplived

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:将多个物理设备冗余成一个虚拟设备

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章