部署高可用keepalived元件

2022-06-08 07:03:08 字數 4283 閱讀 3722

執行 keepalived 和 haproxy 的節點稱為 lb 節點。由於 keepalived 是一主多備執行模式,故至少兩個 lb 節點。

本文件復用 master 節點的三颱機器,haproxy 監聽的埠(8443) 需要與 kube-apiserver 的埠 6443 不同,避免衝突。

keepalived 在執行過程中週期檢查本機的 haproxy 程序狀態,如果檢測到 haproxy 程序異常,則觸發重新選主的過程,vip 將飄移到新選出來的主節點,從而實現 vip 的高可用。

所有元件(如 kubeclt、apiserver、controller-manager、scheduler 等)都通過 vip 和 haproxy 監聽的 8443 埠訪問 kube-apiserver 服務。

source /opt/k8s/bin/environment.sh

for node_ip in $

doecho ">>> $"

ssh root@$ "yum install -y keepalived haproxy"

done

haproxy 配置檔案:

eof下發 haproxy.cfg 到所有 master 節點:

source /opt/k8s/bin/environment.sh

for node_ip in $

doecho ">>> $"

scp haproxy.cfg root@$:/etc/haproxy

done

source /opt/k8s/bin/environment.sh

for node_ip in $

doecho ">>> $"

ssh root@$ "systemctl restart haproxy"

done

source /opt/k8s/bin/environment.sh

for node_ip in $

doecho ">>> $"

ssh root@$ "systemctl status haproxy|grep active"

done

確保狀態為active (running),否則檢視日誌,確認原因:

journalctl -u haproxy
檢查 haproxy 是否監聽 8443 埠:

source /opt/k8s/bin/environment.sh

for node_ip in $

doecho ">>> $"

ssh root@$ "netstat -lnpt|grep haproxy"

done

確保輸出類似於:

tcp        0      0 0.0.0.0:8443            0.0.0.0:*               listen      120583/haproxy
keepalived 是一主(master)多備(backup)執行模式,故有兩種型別的配置檔案。master 配置檔案只有乙份,backup 配置檔案視節點數目而定,對於本文件而言,規劃如下:

master 配置檔案:

source /opt/k8s/bin/environment.sh

cat > keepalived-master.conf <

global_defs

vrrp_script check-haproxy

vrrp_instance vi-kube-master

virtual_router_id 68

advert_int 3

track_script

virtual_ipaddress }}

eof

backup 配置檔案:

source /opt/k8s/bin/environment.sh

cat > keepalived-backup.conf <

global_defs

vrrp_script check-haproxy

vrrp_instance vi-kube-master

virtual_router_id 68

advert_int 3

track_script

virtual_ipaddress }}

eof

下發 master 配置檔案:

scp keepalived-master.conf [email protected]:/etc/keepalived/keepalived.conf
下發 backup 配置檔案:

scp keepalived-backup.conf [email protected]:/etc/keepalived/keepalived.conf

scp keepalived-backup.conf [email protected]:/etc/keepalived/keepalived.conf

source /opt/k8s/bin/environment.sh

for node_ip in $

doecho ">>> $"

ssh root@$ "systemctl restart keepalived"

done

source /opt/k8s/bin/environment.sh

for node_ip in $

doecho ">>> $"

ssh root@$ "systemctl status keepalived|grep active"

done

確保狀態為active (running),否則檢視日誌,確認原因:

journalctl -u keepalived
檢視 vip 所在的節點,確保可以 ping 通 vip:

source /opt/k8s/bin/environment.sh

for node_ip in $

doecho ">>> $"

ssh $ "/usr/sbin/ip addr show $"

ssh $ "ping -c 1 $"

done

Keepalived高可用集群部署

keepalived高可用集群部署 部署三颱linux伺服器,兩台做web伺服器,並部署keepalived高可用軟體,一台作為客戶端主機 client 192.168.10.1 web1 主 192.168.10.10 web2 從 192.168.10.20 部署vip 192.168.4.15...

keepalived高可用部署 單例項 rpm版

配好yum倉庫解決 yum y install keepalived 1.2.7 3.el6.x86 64.rpm 安裝keepalived包 root zys data rpm aq keepalived keepalived 1.2.7 3.el6.x86 64 root zys data et...

Keepalived高可用集群

目錄 keepalived keepalived實現主備 keepalived軟體起初是專為lvs負載均衡軟體設計的,用來管理並監控lvs集群系統中各個伺服器節點的狀態,後來又加入了實現高可用的vrrp功能。因此 keepalived 除了能夠管理lvs軟體外,還可以作為其他服務 例如 nginx ...