linux上安裝keepalived+nginx
阿新 • • 發佈:2019-01-13
一、準備:
1:和機房溝通好,哪臺機器和哪些ip需要漂移,並且保證漂移的ip,漂移後能外網訪問這個漂移的ip
2:yum -y install keepalived nignx
二、主設定: cp /etc/keepalived/keepalived.conf keepalived.conf-back vim /etc/keepalived/keepalived.conf ! Configuration File for keepalived global_defs { notification_email { [email protected] [email protected]
---三個收件的郵箱(可不動) [email protected] } notification_email_from [email protected] ---傳送的郵箱(可不動) smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL vrrp_skip_check_adv_addr #vrrp_strict ---------註釋掉,要不然ping不通vip vrrp_garp_interval 0 vrrp_gna_interval 0 } ~~~~~~~~~~~~~~~~~上面其他的都可以不動~~~~~~~~~~~~~~~~~~~~~~~~~ vrrp_instance VI_1 { state MASTER -------------主 interface eth0 ---注意填寫外網,網絡卡名稱 virtual_router_id 51 priority 100 ------------優先順序(主不用動) advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 202.60.230.94 --vip地址可以配置一個,也可以配置多個 202.60.230.95 202.60.230.97 202.60.230.99 202.60.230.101 202.60.230.107 } } 下面全面刪除
三、從設定:
cp /etc/keepalived/keepalived.conf keepalived.conf-back
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected] ---三個收件的郵箱(可不動)
[email protected]
}
notification_email_from [email protected] ---傳送的郵箱(可不動)
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
#vrrp_strict ---------註釋掉,要不然ping不通vip
vrrp_garp_interval 0
vrrp_gna_interval 0
}
~~~~~~~~~~~~~~~~~上面其他的都可以不動~~~~~~~~~~~~~~~~~~~~~~~~~
vrrp_instance VI_1 {
state BACKUP -------------從
interface eth0 ---注意填寫外網,網絡卡名稱
virtual_router_id 51
priority 80 ------------優先順序(比主低)
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
202.60.230.94 --vip地址可以配置一個,也可以配置多個
202.60.230.95
202.60.230.97
202.60.230.99
202.60.230.101
202.60.230.107
}
}
下面全面刪除
四、書寫指令碼自我檢查
vim /mnt/keep-chenk.sh
#!/bin/bash
for i in `seq 20`
do
AA=`ps -ef | grep /usr/local/nginx/sbin/nginx | grep -v grep | wc -l`
if [ $AA == 0 ];then
systemctl stop keepalived
fi
sleep 3
done
五、啟動服務
先啟動主keepalived,再啟動從keepalived
六、故障處理
列如:主keepalived的nginx掛了,自動檢查就會停掉keepalived(ip會自動漂移到另外一臺nginx上)
需要把ip再漂移回來,只需啟動主的nginx後再systemctl restart keepalievd就可以看到ip又漂回來了