keepalived+lvs SMTP_CHECK功能,在rs重啟后不停發通知郵件
網上下載的最新的 keepalived-1.1.19
ipvsadm用的是redhat EL 5.4 自帶的rpm包
因為後端是郵件伺服器,就用了 SMTP_CHECK 功能,但目前的問題是:
先啟動RS的mail服務,再起keepalived,一切正常。
然後停止RS的mail服務,keepalived也能正常發現並將node踢出。但是:
再啟動RS的mail服務,keepalived就不停的發通知郵件,告知我後端smtp server succeed on service.只有重啟keepalived才可以解決。
不知道為什麼?
配置文件如下:
# Configuration File for keepalived
global_defs {
notification_email {
[email protected] }
notification_email_from
[email protected] smtp_server xxx.xxx.241.95
smtp_connect_timeout 20
lvs_id LVS_MAIL_02
}
vrrp_sync_group lvs_mail {
group {
MAIL_IP
MAIL_GW
}
}
vrrp_instance MAIL_IP {
state BACKUP
interface eth0.401
lvs_sync_daemon_interface eth0.123
#virtual_router_id must between 1 and 255
virtual_router_id 10
priority 100
advert_int 2
smtp_alert
authentication {
auth_type PASS
auth_pass Mail_Sync
}
virtual_ipaddress {
xxx.xxx.241.85
}
}
vrrp_instance MAIL_GW {
state BACKUP
interface eth0.123
lvs_sync_daemon_interface eth0.123
#virtual_router_id must between 1 and 255
virtual_router_id 11
priority 100
advert_int 2
smtp_alert
authentication {
auth_type PASS
auth_pass Mail_Sync
}
virtual_ipaddress {
192.168.123.10
}
}
virtual_server xxx.xxx.241.85 0 {
delay_loop 20
# lb_algo sh
# lc means Less Connection
lb_algo lc
lb_kind NAT
# persistence_timeout 300
persistence_timeout 600
virtualhost mail.mydomain.com
protocol TCP
real_server 192.168.123.21 0 {
weight 1
SMTP_CHECK {
host {
connect_ip 192.168.123.21
connect_port 25
}
#按照下列演算法,最長需要29秒才能確認伺服器已down掉
connect_timeout 5 #超時時長
retry 2 #重試次數
delay_before_retry 2 #重試前等待秒數
helo_name lvs4mail-node2.mydomain.com
}
TCP_CHECK {
connect_port 110
connect_timeout 8
}
}
real_server 192.168.123.22 0 {
weight 1
SMTP_CHECK {
host {
connect_ip 192.168.123.22
connect_port 25
}
#按照下列演算法,最長需要29秒才能確認伺服器已down掉
connect_timeout 8 #超時時長
retry 2 #重試次數
delay_before_retry 2 #重試前等待秒數
helo_name lvs4mail-node2.mydomain.com
}
TCP_CHECK {
connect_port 110
connect_timeout 8
}
}
}
《解決方案》
剛才花時間跟蹤了一下
keepalived啟動但RS不啟動的狀態,LVS正常運行,RS也沒有在ipvsadm -l裡面。
# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP xxx.xxx.241.85:0 lc persistent 600
然後啟動mail-node1上的mail 服務,keepalived在丟了4分鐘的「Remote SMTP server succeed on service.」后,丟出:
Feb 23 09:44:19 lvs4mail-node2 Keepalived_healthcheckers: Adding service to VS
Feb 23 09:44:19 lvs4mail-node2 Keepalived_healthcheckers: Gained quorum 1+0=1 <= 1 for VS
# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP xxx.xxx.241.85:0 lc persistent 600
-> 192.168.123.21:0 Masq 1 0 0
但我啟動mail-node2上的mail服務后,卻一直報「Remote SMTP server succeed on service.」,就是不
Add service 192.168.123.22 to VS
太妖異了!!!