-配置keepalived 雙機熱備-
mkdir /usr/local/keepalived/
tar -zxvf keepalived-2.0.6.tar.gz -c /usr/local/keepalived
cd /usr/local/keepalived/keepalived-2.0.6
./configure
make
make install
cp -r keepalived /etc/init.d/keepalived
mkdir /etc/keepalived/
cd /usr/local/keepalived/keepalived-2.0.6/keepalived/etc/keepalived
cp keepalived.conf /etc/keepalived/
cd /usr/local/keepalived/keepalived-2.0.6/keepalived/etc/sysconfig/
cp keepalived /etc/sysconfig/keepalived
cp /usr/local/keepalived/keepalived-2.0.6/bin/keepalived /usr/sbin
vi /etc/keepalived/keepalived.conf #以下是配置的內容
vrrp_instance vi_1
virtual_ipaddress
}以上修改了如下三項
1.priority 101 #master值要大於bakcup
2.更改網路介面
vrrp_instance vi_1 中inte***ce:ens33(ip addr命令中的網路)
3.192.168.67.100 是虛擬ip
啟動keepalived
service keepalived start或者systemctl start keepalived
備用排程伺服器 只有一項不同
priority 100
同樣配置完畢後啟動keepalived
注意:#vrrp_strict #這個注釋掉,否則可能造成物理機的瀏覽器無法訪問應用
啟動keepalived
service keepalived start
設定開機自啟動
systemctl enable keepalived.service
如果nginx死掉,虛擬ip不會自動切換,如果要nginx停止執行後虛擬ip自動切換,需要設定指令碼:
vi /etc/keepalived/keepalived.conf
如下:
! configuration file for keepalived
global_defs
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
vrrp_garp_interval 0
vrrp_gna_interval 0
} vrrp_script chk_nginx
vrrp_instance vi_1
virtual_ipaddress
track_script
}
建立 vi /root/nginx_chk.sh,輸入指令碼
#!/bin/bash
if [ "$(ps aux | grep "nginx: master process"|grep -v grep)" == "" ]
then
#/etc/init.d/keepalived/keepalived stop
service keepalived stop
fi
指令碼要賦予x許可權 Keepalived雙機熱備
準備兩台虛擬機器 192.168.80.100 主伺服器 192.168.80.102 備份伺服器 在80.100虛擬機器上 systemctl stop firewalld 關閉防火牆 setenforce 0 關閉selinux 1 keepalived軟體安裝 yum install keep...
Keepalived做雙機熱備
解壓以及編譯 tar xzf keepalived 1.2.7.tar.gz configure prefix opt keepalived make make install 配置keepalived 建立keepalived配置檔案keepalived.conf 只有虛擬ip功能,其他功能,例如...
Keepalived實現雙機熱備
一 主機從機都安裝keepalived 1.安裝 yum install y keepalived 2.備份 cd etc keepalived cp keepalived.conf keepalived.conf.back 二 主機配置並啟動 1.建立配置檔案 echo configuration...