一、Keepalived軟件前期用來管理並監控LVS集羣系統中各個服務節點的狀態;服務器
二、後期加入了實現高可用的VRRP功能。所以能夠爲lvs負載均衡提供高可用功能,也能夠爲其餘服務提供高可用。。負載均衡
實驗鏡像:Centos 8.1.1911curl
草圖:(待補)oop
一、兩個real server 安裝配置測試
在keepalived Master上測試無問題。this
[root@HA1 ~]# curl http://192.168.94.140 this is real 1 server [root@HA1 ~]# curl http://192.168.94.141 this is real 2 server [root@HA1 ~]#
二、安裝keepalived、ipvsadmurl
yum install ipvsadm keepalived -yspa
使用keepalived便可完成real server的添加。code
配置文件在/etc/keepalived下router
[root@HA1 keepalived]# pwd /etc/keepalived [root@HA1 keepalived]# ls keepalived.conf [root@HA1 keepalived]# cp keepalived.conf keepalived.conf.bak [root@HA1 keepalived]# echo "" > keepalived.conf [root@HA1 keepalived]#
三、keepalived文件配置
MASTER
! Configuration File for keepalived
# 全局
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@server.com
smtp_connect_timeout 3
smtp_server 127.0.0.1
router_id LVS_DEVEL
}
# 一個keepalived服務器,MASTER爲主的進行服務提供
vrrp_instance VI_1 {
interface ens33
state MASTER
priority 101
virtual_router_id 51
garp_master_delay 1
authentication {
auth_type PASS
auth_pass password
}
# VIP 地址
virtual_ipaddress {
192.168.94.200 dev ens33 label ens33:0
}
}
# VIP 關聯兩個real server
virtual_server 192.168.94.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
# 兩個real server 都故障,提供服務的地址
sorry_server 192.168.94.138 80
# 定義real server 1
real_server 192.168.94.140 80 {
weight 1
# real server 存活檢測,檢測url的code
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
# 定義real server 2
real_server 192.168.94.141 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
把配置文件複製到HA2上
BACKUP
! Configuration File for keepalived
# 全局
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@server.com
smtp_connect_timeout 3
smtp_server 127.0.0.1
router_id LVS_DEVEL
}
# 一個keepalived服務器,MASTER爲主的進行服務提供
vrrp_instance VI_1 {
interface ens33
state BACKUP priority 100
virtual_router_id 51
garp_master_delay 1
authentication {
auth_type PASS
auth_pass password
}
# VIP 地址
virtual_ipaddress {
192.168.94.200 dev ens33 label ens33:0
}
}
# VIP 關聯兩個real server
virtual_server 192.168.94.200 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
# 兩個real server 都故障,提供服務的地址
sorry_server 192.168.94.139 80
# 定義real server 1
real_server 192.168.94.140 80 {
weight 1
# real server 存活檢測,檢測url的code
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
# 定義real server 2
real_server 192.168.94.141 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
一、高可用
兩個節點(MASTER、BACKUP)都啓動服務。
查看地址ifconfig –a
VIP只會啓動在MASTER上,當MASTER服務故障後,則BACKUP提供服務。
二、real server 資源管理
real server 節點故障後,keepalived會自動在ipvs中進行刪除。再上線後也會從新加進來。
個人配置文件可能有點問題,測試的時候有些奇怪,有時間在檢查吧。
讀書和健身總有一個在路上