HighAvailable
1、 需要心跳機制探測後端RS是否提供服務。
a) 探測down,需要從lvs中刪除該RS
b) 探測發送從down到up,需要從lvs中再次添加RS。
2、 Lvs DR,需要主從(HA)
Keepalived : 提供高可用
vrrp協議,實現IP的漂移
Zookeeper:
選舉、心跳機制提供接管
Keepalived安裝:
至少兩臺服務器需要安裝
Yuminstall keepalived
Keepalived 配置文件
至少兩臺服務器
1、 地址:/etc/keepalived.conf
2、 幫助手冊:man keepalived.conf
3、 編輯之前,需要備份:cp –a keepalived.conf backup. keepalived.conf
4、 編輯:
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost#發送提醒郵件的目標地址可有多個
}
notification_email_from test@localhost#發送郵件的from地址,可以隨意寫,郵件地址不存在都無所謂
smtp_server 127.0.0.1#郵件服務的地址,一般寫本地
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP# MASTER主和從
interface eth0#VIP需要綁定的網卡名稱
virtual_router_id 51
priority 101#優先級 主的優先級要高
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.200/24 dev eth0 label eth0:0 #設置VIP
}
}
virtual_server 192.168.1.200 80 {#設置虛擬lvs服務,VIP PORT
delay_loop 6
lb_algo rr#調度算法wrr
lb_kind DR#lvs的模式
nat_mask 255.255.255.0
persistence_timeout 50 同一個IP地址在50秒內lvs轉發給同一個後端服務器
protocol TCP
real_server 192.168.1.139 80 {#設置真實服務器的心跳機制 RID PORT
weight 1#權重
HTTP_GET {#心跳檢測的方式
url {
path /#心跳檢查的地址
status_code 200#心跳檢查返回的狀態
}
connect_timeout 2 #超時時間
nb_get_retry 3#重複檢查3次
delay_before_retry 1#每隔1秒鐘再次檢查
}
}
real_server 192.168.1.134 80 {#第二個真實服務器設置
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 2
nb_get_retry 3
delay_before_retry 1
}
}
}
Keepalived的啓動和日誌
Service keepalived start啓動
keepalived 的配置文件配置(keepalived.conf)
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from hello@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script check_nginx {
script "/home/check_nginx.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 199
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.239.100/24 dev eth0 label eth0:1
}
track_script {
check_nginx
}
}