keepalived是什么?
Keepalived軟件起初是專為LVS負(fù)載均衡軟件設(shè)計(jì)的,用來管理并監(jiān)控LVS集群系統(tǒng)中各個(gè)服務(wù)節(jié)點(diǎn)的狀態(tài),后來又加入了可以實(shí)現(xiàn)高可用的VRRP功能。因此,Keepalived除了能夠管理LVS軟件外,還可以作為其他服務(wù)(例如:Nginx、Haproxy、MySQL等)的高可用解決方案軟件。
Keepalived軟件主要是通過VRRP協(xié)議實(shí)現(xiàn)高可用功能的。VRRP是Virtual Router RedundancyProtocol(虛擬路由器冗余協(xié)議)的縮寫,VRRP出現(xiàn)的目的就是為了解決靜態(tài)路由單點(diǎn)故障問題的,它能夠保證當(dāng)個(gè)別節(jié)點(diǎn)宕機(jī)時(shí),整個(gè)網(wǎng)絡(luò)可以不間斷地運(yùn)行。
所以,Keepalived 一方面具有配置管理LVS的功能,同時(shí)還具有對(duì)LVS下面節(jié)點(diǎn)進(jìn)行健康檢查的功能,另一方面也可實(shí)現(xiàn)系統(tǒng)網(wǎng)絡(luò)服務(wù)的高可用功能。
keepalived官網(wǎng)http://www.keepalived.org
1.1 keepalived的相關(guān)的文件
keepalived的執(zhí)行命令:/data/apps/keepalived/sbin/keepalived
keepalived的配置文件:/data/apps/keepalived/etc/keepalived/keepalived.conf
keepalived的Pid文件:/data/apps/keepalived/run/keepalived.pid
1.2 keepalived的啟停止方式
注意:不要去修改/data/apps/keepalived/etc/sysconfig/keepalived文件
啟動(dòng)方式:keepalived -f 配置文件(絕對(duì)路徑) -p PID文件(絕對(duì)路徑)
關(guān)閉方式:kill $( cat PID文件(絕對(duì)路徑) )
1.3 腳本內(nèi)容
注意:該腳本只能Linux的超級(jí)用戶root才能啟動(dòng),因?yàn)槟_本中有進(jìn)行限制
#!/bin/bash
## Define variables
RETVAL=0
Conf="/data/apps/keepalived/etc/keepalived/keepalived.conf"
Exce="/data/apps/keepalived/sbin/keepalived"
Pid="/data/apps/keepalived/run/keepalived.pid"
# Determine the user to execute
if [ "$UID" -ne "$RETVAL" ];then
echo "Must be root to run scripts"
exit 1
fi
# Load local functions library
[ -f /etc/init.d/functions ] source /etc/init.d/functions
# Define functions
start(){
if [ ! -f "$Pid" ];then
$Exce -f $Conf -p $Pid >/dev/null 2>1
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "Start keepalived service" /bin/true
else
action "Start keepalived service" /bin/false
fi
else
echo "keepalived service is running"
fi
return $RETVAL
}
stop(){
if [ -f "$Pid" ];then
kill $(cat $Pid) >/dev/null 2>1
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "Stop keepalived service" /bin/true
else
action "Stop keepalived service" /bin/false
fi
else
echo "keepalived service is not running"
fi
return $RETVAL
}
status(){
if [ -f "$Pid" ];then
echo "keepalived service is running"
else
echo "keepalived service is not running"
fi
return $RETVAL
}
# case local functions
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
status)
status
RETVAL=$?
;;
restart)
stop
sleep 2
start
RETVAL=$?
;;
*)
echo "USAGE:$0{status|start|stop|restart}"
exit 1
esac
# Scripts return values
exit $RETVAL
總結(jié)
到此這篇關(guān)于使用shell開發(fā)keepalived啟動(dòng)腳本的文章就介紹到這了,更多相關(guān)shell keepalived啟動(dòng)腳本內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- linux環(huán)境下編寫shell腳本實(shí)現(xiàn)啟動(dòng)停止tomcat服務(wù)的方法
- Linux啟動(dòng)jar包的shell腳本
- 用shell腳本監(jiān)控進(jìn)程是否存在 不存在則啟動(dòng)的實(shí)例
- Shell實(shí)現(xiàn)的Oracle啟動(dòng)腳本分享
- Shell實(shí)現(xiàn)判斷進(jìn)程是否存在并重新啟動(dòng)腳本分享
- CentOS下redis自啟動(dòng)shell腳本