您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)怎么利用shell開發(fā)keepalived啟動腳本的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
keepalived是什么?
Keepalived軟件起初是專為LVS負(fù)載均衡軟件設(shè)計(jì)的,用來管理并監(jiān)控LVS集群系統(tǒng)中各個服務(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)個別節(jié)點(diǎn)宕機(jī)時,整個網(wǎng)絡(luò)可以不間斷地運(yùn)行。
所以,Keepalived 一方面具有配置管理LVS的功能,同時還具有對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文件
啟動方式:keepalived -f 配置文件(絕對路徑) -p PID文件(絕對路徑)
關(guān)閉方式:kill $( cat PID文件(絕對路徑) )
1.3 腳本內(nèi)容
注意:該腳本只能Linux的超級用戶root才能啟動,因?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
感謝各位的閱讀!關(guān)于“怎么利用shell開發(fā)keepalived啟動腳本”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。