Keepalived部署雙主熱備

2021-10-04 18:10:58 字數 3441 閱讀 4146

二、配置keepalived主和從

2.2、配置keepalived - 從

2.3、啟動keepalived

三、keepalived註冊為系統服務

四、keepalived配置nginx自動重啟

五、配置keepalived雙主熱備

# 上傳壓縮包

scp ./keppalived.tar.gz [email protected]:/home/software

# 解壓

tar -zxvf keppalived.tar.gz

./configure --prefix=/usr/local/keepalived --sysconf=/etc
警告

make

&&make

install

進入/etc/keepalived,該目錄下為keepalived核心配置檔案

2.1.1、通過命令vim keepalived.conf開啟配置檔案,檔案位置/etc/keepalived資料夾下

global_defs 

# 計算機節點

vrrp_instance vi_1

virtual_ipaddress

}

ip addr 命令可以檢視自己的ip和網絡卡位址

2.1.2、啟動keepalived
# 進去啟動目錄

cd /usr/local/keeplived/sbin

# 啟動

./keepalived

# 檢視程序

ps -ef|

grep keepalived

# 檢視虛擬ip

ip addr

2.2.1、通過命令vim keepalived.conf開啟配置檔案,檔案位置/etc/keepalived資料夾下
global_defs 

# 計算機節點

vrrp_instance vi_1

virtual_ipaddress

}

ip addr 命令可以檢視自己的ip和網絡卡位址

# 進去啟動目錄

cd /usr/local/keeplived/sbin

# 啟動

./keepalived

# 檢視程序

ps -ef|

grep keepalived

# 檢視虛擬ip

ip addr

# 進入解壓目錄

cd /home/software/keepalived-2.0.18

# 進入keepalived目錄

cd keepalived

# 進入etc目錄

cd etc

# 拷貝配置檔案到系統etc下的init.d資料夾下

cp init.d/keepalived /etc/init.d/

# 拷貝配置檔案到系統etc下的sysconfig資料夾下

cp sysconfig/keepalived /etc/sysconfig/

# 重新整理配置

systemctl daemon-reload

# 啟動keepalived服務

systemctl start keepalived.service

# 檢測keepalived服務狀態,兩種方法都可以

systemctl status keepalived.service

ps -ef|

grep keepalived

# 停止keepalived服務

systemctl stop keepalived.service

# 重啟keepalived服務

systemctl restart keepalived.service

vim /etc/keepalived/check_nginx_alive_or_not.sh

#!/bin/basha=`

ps -c nginx --no-header |

wc -l`

# 判斷nginx是否宕機,如果宕機了,嘗試重啟if[

$a -eq 0 ]

;then

/usr/local/nginx/sbin/nginx

# 等待一小會再次檢查nginx,如果沒有啟動成功,則停止keepalived,使其啟動備用機

sleep 3

if[`

ps -c nginx --no-header |

wc -l`

-eq 0 ]

;then

killall keepalived

fifi

vrrp_script check_nginx_alive
這段**配置在/etc/keepalived/keepalived.conf指令碼中』

track_script
systemctl restart keepalived
global_defs 

vrrp_script check_nginx_alive

# 計算機節點

vrrp_instance vi_1

track_script

virtual_ipaddress

}

vrrp_script check_nginx_alive 

# 計算機節點

vrrp_instance vi_1

track_script

virtual_ipaddress

}vrrp_instance vi_2

virtual_ipaddress

}

global_defs 

# 計算機節點

vrrp_instance vi_1

virtual_ipaddress

}vrrp_instance vi_2

virtual_ipaddress

}

systemctl restart keepalived.service

Nginx 配置Keepalived雙主熱備

我們配置兩個虛擬ip192.168.1.161和192.168.1.162 分別指向兩台nginx192.168.1.171和192.168.1.172 然後讓兩台nginx互為主備 global defs vrrp instance vi 1 虛擬出來的ip,可以有多個 vip virtual i...

keepalived雙主雙從配置

機器ip位址為自己本身機器的ip請勿使用博主的ip 配置過程時間有點長,比較多,配置的時候請看清 加油,打工人 配置環境 keepalived1 192.66.66.101 keepalived2 192.66.66.102 web1 192.66.66.103 web2 192.66.66.104...

KeepAlived 安裝部署 主節點

概念 一 keepalived 工作原理,tcp會在空閒了一定時間後傳送資料給對方 1.如果主機可達,對方就會響應ack應答,就認為是存活的。2.如果可達,但應用程式退出,對方就發fin應答,傳送tcp撤消連線。3.如果可達,但應用程式崩潰,對方就發rst訊息。4.如果對方主機不響應ack rst,...