1.安裝keepalivednginx
下載keepalived-1.2.7.tar.gzvim
tar -zxvf keepalived-1.2.7.tar.gzruby
cd keepalived-1.2.7服務器
./configure --prefix=/opt/keepalived && make && make installtcp
chkconfig --add keepalived #添加系統服務spa
2.配置keepalivedcode
vim /etc/keepalived/keepalived.confrouter
2.1配置keepalived須要檢測的應用程序監測腳本ip
vrrp_script chk_nginx {
script
"/opt/keepalived/check_nginx.sh"
interval
2
weight
2
}
|
2.2 主要配置ci
vrrp_instance
VS_8
{
state
BACKUP
#配置是主仍是備
interface eth0
#網卡
virtual_router_id
59
#router_id主備要同樣,另外,經過tcpdump vrrp查看哪些vrid在使用,不要有衝突
priority
100
#優先級
advert_int
1
authentication {
auth_type
PASS
auth_pass
1111
}
track_interface {
eth0
}
virtual_ipaddress {
10
.
13
.
81
.
8
/
24
dev eth0
#這裏配置虛擬IP
}
track_script {
chk_nginx
}
# 下面是發生切換時的通知腳本
notify_master
"/opt/keepalived/notify.py from_120_keepalived_master_is_up"
notify_backup
"/opt/keepalived/notify.py from_120_keepalived_backup_is_down"
notify_fault
"/opt/keepalived/notify.py from_120_keepalived_fault"
}
|
3. 檢查虛擬IPip -f inet addr 就能夠在主服務器上看到剛纔配置的虛擬IP了。