怎么利用shell开发keepalived启动脚本-创新互联
这篇文章给大家分享的是有关怎么利用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启动脚本”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
文章标题:怎么利用shell开发keepalived启动脚本-创新互联
文章URL:http://azwzsj.com/article/dpppsg.html