1.環境準備
1.兩臺服務器 2,都安裝上nginx 3,以及keeplived
2.keeplived的安裝
yum install keepalived-y
安裝之後在etc/keepalived 有文件keepalived.conf
3.配置文件的修改
3.1 修改/etc/keepalived/keepaliveed.conf配置文件
global_defs{
notification_email{
[email protected]
[email protected]
[email protected]
}
notification_email_from Alexandre.Cassen @firewall.loc
smtpserver 192.168.17.129
smtp_connect_timeout30
router_id LVS_DEVEL
}
vrrp_script chk_http_port{
script"/usr/local/src/nginx_check.sh"
interval2#(檢測腳本執行的間隔)
weight2
}
vrrp_instance VL_1{
state BACKUP#備份服務器上將MASTER改爲BACKUP
interface ens33/網卡
virtual_router_id51#主、備機的virtual_router_id必須相同
priority90#主、備機取不同的優先級,主機值較大,備份機值較小
advert_int 1
authentication{
auth_type PASS
auth_pass1111
virtual_ipaddress{
192.168.17.50//VRRPH虛擬地址
}
}
3.2 在/usr/local/src 添加檢測腳本
#!/bin/bash A='ps-C nginx -no-header wc-1
if [$A-eq 0];then
/usr/local/nginx/sbin/nginx sleep2
if [ps-C nginx --no-header |wc -1'-eq 0];then killall keepalived fifi
4.測試
訪問如果沒有問題 將主服務器宕機,看是否訪問成功,如果成功代表沒有問題。