Keepalive01:
! Configuration File for keepalived
global_defs {
notification_email { ##接收郵件的位址;就是說通知郵件應該發送給誰,通常寫自己的位址
root@localhost ##收件人,表示發送給本機的root使用者
}
notification_email_from keepalived@localhost ##發件人
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS #辨別本節點的字條串,通常為hostname,但不一定非得是hostname。故障發生時,郵件通知會用到。
vrrp_mcast_group4 224.0.100.19 ##vrrp協定是通過多點傳播向外發送的;這裡指的是ipv4的多點傳播位址
}
vrrp_instance VI_1 { #自定義名稱:VI_1
state BACKUP
interface ens192
virtual_router_id 51 #主備ID相同
priority 100 ##優先級
nopreempt ##工作于非搶占模式
advert_int 1 ##廣播通告的時間間隔,每隔多長時間向外發送自身的心跳資訊,預設是一秒鐘一次
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.18.117.194 dev ens192
}
}
virtual_server 172.18.117.194 80 { # 定義轉移ip端口80的叢集服務
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 172.18.117.192 80 { # 定義叢集服務包含的RS 1
weight 1 # 權重為1
HTTP_GET { # 定義RS1的健康狀态檢測
url {
path /
status_code 200
}
connect_timeout 1
nb_get_retry 3
delay_before_retry 1
}
}
real_server 172.18.117.193 80 { # 定義叢集服務包含的RS 2
weight 1 # 權重為1
HTTP_GET { # 定義RS2的健康狀态檢測
url {
path /
status_code 200
}
connect_timeout 1
nb_get_retry 3
delay_before_retry 1
}
}
}
Keepalive02:
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS
vrrp_mcast_group4 224.0.100.19
}
vrrp_instance VI_1 {
state BACKUP
interface ens192
virtual_router_id 51
priority 99
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.18.117.194 dev ens192
}
}
virtual_server 172.18.117.194 80 { # 定義轉移ip端口80的叢集服務
delay_loop 3
lb_algo rr
lb_kind DR
protocol TCP
sorry_server 127.0.0.1 80
real_server 172.18.117.192 80 { # 定義叢集服務包含的RS 1
weight 1 # 權重為1
HTTP_GET { # 定義RS1的健康狀态檢測
url {
path /
status_code 200
}
connect_timeout 1
nb_get_retry 3
delay_before_retry 1
}
}
real_server 172.18.117.193 80 { # 定義叢集服務包含的RS 2
weight 1 # 權重為1
HTTP_GET { # 定義RS2的健康狀态檢測
url {
path /
status_code 200
}
connect_timeout 1
nb_get_retry 3
delay_before_retry 1
}
}
}