2. keepalived雙機主備配置
3. keepalived雙機熱備
4. 將keepalived 註冊為系統服務
5. 配置nginx自動重啟
6. 整合fdfs
yum -y install libnl libnl-devel
tar -zxvf keepalived-2.0.18.tar.gz
cd keepalived-2.0.18
./configure --prefix=/usr/local/keepalived --sysconf=/etc
make
&&make
install
vi /etc/keepalived/keepalived.conf
! configuration file for keepalived
global_defs
# 計算機節點
vrrp_instance vi_1
#虛擬ip
virtual_ipaddress
}
啟動主節點keepalived
/usr/local/keepalived/sbin/keepalived
看下程序是否啟動成功
ps -ef |
grep keepalived
vi /etc/keepalived/keepalived.conf
! configuration file for keepalived
global_defs
# 計算機節點
vrrp_instance vi_1
#虛擬ip
virtual_ipaddress
}
啟動主節點keepalived
/usr/local/keepalived/sbin/keepalived
看下程序是否啟動成功
ps -ef |
grep keepalived
ip addr
將主節點的keepalived的程序殺死,再檢視ip位址情況
虛擬ip已經切換到備節點機器,再將主節點機器keepalived程式啟動,則虛擬ip會回到主節點機器
主節點配置:
global_defs
vrrp_instance vi_1
virtual_ipaddress
}vrrp_instance vi_2
virtual_ipaddress
}
備用節點配置
global_defs
vrrp_instance vi_1
virtual_ipaddress
}vrrp_instance vi_2
virtual_ipaddress
}
cd /opt/soft/keepalived/keepalived-2.0.18/keepalived/etc
cp init.d/keepalived /etc/init.d/
cp sysconfig/keepalived /etc/sysconfig/
systemctl daemon-reload
systemctl enable keepalived
vi /etc/keepalived/check_nginx_alive_or_not.sh
#!/bin/bash a=`
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
chmod +x /etc/keepalived/check_nginx_alive_or_not.sh
! configuration file for keepalived
global_defs
# 執行的指令碼
vrrp_script check_nginx_alive
# 計算機節點
vrrp_instance vi_1
# 追蹤 nginx 指令碼
track_script
#虛擬ip
virtual_ipaddress
}
鏈結
#!/bin/bash
#查詢ngxin程序的數量
ngc=
`ps -c nginx --no-header |
wc -l`
#nginx的pid所在目錄
ngd=
"/var/run/nginx"
#nginx的pid檔案路徑
ngp=
"/var/run/nginx/nginx.pid"
#查詢 fdfs_trackerd 程序的數量
fdfsc=
`ps -c fdfs_trackerd --no-header |
wc -l`
#虛擬機器重啟會刪除/var/run/nginx 這個目錄,導致nginx.pid丟失,需要重新建立
#判斷nginx的pid所在目錄是否存在,不存在則建立if[
[! -d "$ngd"]]
;then
echo
"nginx的pid目錄不存在"
mkdir /var/run/nginx
fi#判斷nginx的pid是否存在,不存在則建立if[
[! -f "$ngp"]]
;then
echo
"nginx的pid檔案不存在"
touch /var/run/nginx/nginx.pid
fi#nginx整合fdfs後,需要依賴fdfs服務,否則啟動nginx會只有master沒有worker,無法正常使用
#判斷fdfs是否存在,不存在則不執行if[
$fdfsc -gt 0 ]
;then
# 判斷nginx是否宕機,如果宕機了,嘗試重啟if[
$ngc -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
fifielse
echo
"fdfs_trackerd 服務不存在"
fi
keepalived安裝部署
上傳伺服器安裝 tar xvf cd keepalived 1.3.5 configure prefix usr local keepalived make make install ln s usr local keepalived sbin usr bin ln s usr local keep...
Keepalived配置安裝
ubuntu 16.04.3系統兩台機器 vipip hostname port 192.168.0.200 192.168.0.129 master wjt ceshiji 80192.168.0.200 192.168.0.129 backup wjt ceshiji22 80wgettar z...
keepalived編譯安裝
直接上乾貨!簡介就不說了,keepalivd做什麼應該已了解。二 編譯步驟 2.1 安裝依賴 yum install y libnl devel libnl3 devel libnfnetlink devel 解壓編譯 tar zxvf keepalived 2.0.19.tar.gz cd kee...