keepalived指令碼 高可用(非搶占模式)

2021-10-05 10:41:25 字數 2158 閱讀 5159

首先安裝nginx,然後配置nginx

a主機:

#!/bin/bash

#keepalived安裝

yum -y install keepalived &>/dev/null

echo 「keepalived 安裝 ok」

rm -rf /etc/keepalived/keepalived.conf

echo 「刪除keepalived.cof 成功」

cat>>/etc/keepalived/keepalived.conf<<\eof

! configuration file for keepalived

global_defs

vrrp_script chk_nginx

vrrp_instance vi_1

track_script

virtual_ipaddress

}eof

echo 「」

echo 「keepalived.conf 編寫成功」

cat>>/etc/keepalived/check_port.sh<<\eof

chk_port=1if

[−n"

1 if [ -n "

1if[−n

"chk_port" ];then

port_process=ss -lntp|grep $chk_port|wc -l

if [ $port_process -eq 0 ];then

echo 「port $chk_port is not used,end.」

systemctl stop keepalived.service

fielse

echo 「check port cant be empty!」

fieof

#讓keepalived 預設可以使用stop停掉keepalived高可用

sed -i 『s/killmode=process/#killmode=process/』 /usr/lib/systemd/system/keepalived.service

systemctl start keepalived.service

b主機:

#!/bin/bash

#keepalived安裝

yum -y install keepalived &>/dev/null

echo 「keepalived 安裝 ok」

rm -rf /etc/keepalived/keepalived.conf

echo 「刪除keepalived.cof 成功」

cat>>/etc/keepalived/keepalived.conf<<\eof

! configuration file for keepalived

global_defs

vrrp_script chk_nginx

vrrp_instance vi_1

track_script

virtual_ipaddress

}eof

echo 「」

echo 「keepalived.conf 編寫成功」

cat>>/etc/keepalived/check_port.sh<<\eof

chk_port=1if

[−n"

1 if [ -n "

1if[−n

"chk_port" ];then

port_process=ss -lntp|grep $chk_port|wc -l

if [ $port_process -eq 0 ];then

echo 「port $chk_port is not used,end.」

systemctl stop keepalived.service

fielse

echo 「check port cant be empty!」

fieof

#讓keepalived 預設可以使用stop停掉keepalived高可用

sed -i 『s/killmode=process/#killmode=process/』 /usr/lib/systemd/system/keepalived.service

systemctl start keepalived.service

Keepalived高可用集群

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

keepalived高可用集群

1.keepalived服務概念說明 keepalived軟體能幹什麼?keepalived軟體起初是專為lvs負載均衡軟體設計的,用來管理並監控lvs集群系統中各個服務節點的狀態,後來又加入了可以實現高可用的vrrp功能 keepalived軟體主要是通過vrrp協議實現高可用功能的。vrrp是v...

高可用集群 Keepalived

1.vrrp熱備 ftp,mysql,httpd,nginx,lvs 2.自動配置lvs規則 3.健康檢查 使用keepalived實現web伺服器的高可用 web伺服器ip位址分別為192.168.4.100和192.168.4.200 web伺服器的浮動vip位址為192.168.4.80 客戶...