實驗keepalived 對2個lvs server進行failover的切換
要求:
1.可以切換過去
2.發送mail
安裝keepalived-1.1.19.tar.gz 目前最新的
./configure
make
make install 三部曲
#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
#mkdir /etc/keepalived
#cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
#cp /usr/local/sbin/keepalived /usr/sbin/
然後便捷.conf文件
! Configuration File for keepalived
global_defs {
notification_email {
yourname@yourdomain //要收到mail的address
}
notification_email_from lvs-machine@lvsdomain 發送
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
state MASTER
smtp_alert #這個是關鍵,如果沒有這個不會發mail!
interface eth0
virtual_router_id 51
priority 150 advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.16.1.240
}
}
virtual_server 172.16.1.240 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 172.16.1.233 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
[root@lvserver keepalived]#
backup
! Configuration File for keepalived
global_defs {
notification_email {
yourname@yourdomain
}
notification_email_from lvs-backup@lvs-domain
smtp_server 127.0.0.1 #default 啟動sendmail 25端口
smtp_connect_timeout 30
router_id LVS_DEVEL
}
# VIP1
vrrp_instance VI_1 {
state BACKUP #.......MASTER..BACKUP
smtp_alert
interface eth0
virtual_router_id 51
priority 99 # ......100..99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.16.1.240
}
}
virtual_server 172.16.1.240 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 172.16.1.233 80 {
weight 3
TCP_CHECK {
connect_timeout 10
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
在default情況下,master 掉了會切換到slave(backup) lvs server, 但是當master 回來的時候會取代slave,還是master.
這個要跟實際應用策略有關係。
要注意就是:
smtp_alert的設置,否則不會收到mail
測試發現他發出來的mail不是太明顯,沒有辦法編輯格式,後來想了一下,可以使用其他的手段做一個mail script.發送。
網上很多資料。不再列舉了
記錄一下,備忘!
參考:
没有评论:
发表评论