您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關怎么利用shell開發keepalived啟動腳本的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
keepalived是什么?
Keepalived軟件起初是專為LVS負載均衡軟件設計的,用來管理并監控LVS集群系統中各個服務節點的狀態,后來又加入了可以實現高可用的VRRP功能。因此,Keepalived除了能夠管理LVS軟件外,還可以作為其他服務(例如:Nginx、Haproxy、MySQL等)的高可用解決方案軟件。
Keepalived軟件主要是通過VRRP協議實現高可用功能的。VRRP是Virtual Router RedundancyProtocol(虛擬路由器冗余協議)的縮寫,VRRP出現的目的就是為了解決靜態路由單點故障問題的,它能夠保證當個別節點宕機時,整個網絡可以不間斷地運行。
所以,Keepalived 一方面具有配置管理LVS的功能,同時還具有對LVS下面節點進行健康檢查的功能,另一方面也可實現系統網絡服務的高可用功能。
keepalived官網http://www.keepalived.org
1.1 keepalived的相關的文件
keepalived的執行命令:/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文件(絕對路徑)
關閉方式:kill $( cat PID文件(絕對路徑) )
1.3 腳本內容
注意:該腳本只能Linux的超級用戶root才能啟動,因為腳本中有進行限制
#!/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
感謝各位的閱讀!關于“怎么利用shell開發keepalived啟動腳本”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。