keeplive linux平台下,Linux下搭建keepalive+nginx
一、?安裝nginx(略)
二、?安裝keepalive
安裝依賴包?yum install –y popt* gcc* openssl* nmap
tar fvxz keepalived-1.2.15.tar.gz
cd keepalived-1.2.15
./configure –prefix=/usr/local/keepalived
make && make installmkdir /etc/keepalived??##為keepalived創(chuàng)建配置文件目錄,默認(rèn)配置文件從/etc/keepalived下讀取
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ ##復(fù)制keepalived的二進(jìn)制命令
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/??##提供啟動(dòng)腳本
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/ ##keepalived的主
cp /usr/local/keepalived/ety/sysconfig/keepalived /usr/sysconfig/
三、?配置keepalive
1.??打開配置文件vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
liumingtao@zhanghetianxia.com
lmt122900@sina.com
}
notification_email_from pub@easymobi.cn
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/opt/nginx.sh"??#檢測(cè)nginx是否存活腳本位置(下面會(huì)有定義腳本名)
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER #?主???(備用?BACKUP)
interface eth0???????#本機(jī)ip網(wǎng)卡名稱
virtual_router_id 10??#?每組keepalive routeid相同,不同組不能一樣
mcast_src_ip 192.168.102.79??#本機(jī)ip?備機(jī)用備機(jī)ip
priority 100??#權(quán)重?備機(jī)數(shù)值要比主的數(shù)值小
advert_int 1??#?檢查間隔
authentication {
auth_type PASS
auth_pass 1111222
}
track_script {
chk_http_port??#定義nginx檢測(cè)腳本名稱
}
virtual_ipaddress {
192.168.102.89??#虛擬ip
}
}
啟動(dòng)主備的keepalived驗(yàn)證
nginx.sh?腳本?備機(jī)可以不用定義腳本相關(guān)選項(xiàng)
#!/bin/sh
# check nginx server status
NGINX=/usr/local/nginx/sbin/nginx
PORT=80
nmap localhost -p $PORT | grep "$PORT/tcp open"
#echo $?
if [ $? -ne 0 ];then
$NGINX -s stop
$NGINX
sleep 3
nmap localhost -p $PORT | grep "$PORT/tcp open"
[ $? -ne 0 ] && /etc/init.d/keepalived stop
fi
把腳本加上執(zhí)行權(quán)限后放到/opt/目錄下
總結(jié)
以上是生活随笔為你收集整理的keeplive linux平台下,Linux下搭建keepalive+nginx的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Visio绘图记录(1)
- 下一篇: matlab假设网格颜色,MATLAB