zabbix的启动和关闭脚本

Posted 头痛不头痛

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zabbix的启动和关闭脚本相关的知识,希望对你有一定的参考价值。

1. zabbix客户端的系统服务脚本

   1.1 拷贝启动脚本

    zabbix的源码提供了系统服务脚本,在/usr/local/src/zabbix-3.2.6/misc/init.d目录下,我的系统是CentOS的,所以选择fedora下的脚本复制到/etc/init.d下

[[email protected] core5]# pwd
/usr/local/src/zabbix-3.2.6/misc/init.d/fedora/core5

[[email protected] core5]# cp -a zabbix_agentd /etc/init.d/

  这里需要添加一个软链接,否则会报错退出

ln -s /usr/local/zabbix-3.2.6/sbin/zabbix_agentd /usr/local/sbin/

 1.2 添加到开机自启动

[[email protected] init.d]# chkconfig --add zabbix_agentd 
[[email protected] init.d]# chkconfig zabbix_agentd on
[[email protected] init.d]# chkconfig --list|grep zabbix_agentd 
zabbix_agentd  	0:off	1:off	2:on	3:on	4:on	5:on	6:off

  脚本内容

#!/bin/bash
#
#       /etc/rc.d/init.d/zabbix_agentd
#
# Starts the zabbix_agentd daemon
#
# chkconfig: - 95 5
# description: Zabbix Monitoring Agent
# processname: zabbix_agentd
# pidfile: /tmp/zabbix_agentd.pid

# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA

# Source function library.

. /etc/init.d/functions

RETVAL=0
prog="Zabbix Agent"
ZABBIX_BIN="/usr/local/sbin/zabbix_agentd"

if [ ! -x ${ZABBIX_BIN} ] ; then
        echo -n "${ZABBIX_BIN} not installed! "
        # Tell the user this has skipped
        exit 5
fi

start() {
        echo -n $"Starting $prog: "
        daemon $ZABBIX_BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_agentd
        echo
}

stop() {
        echo -n $"Stopping $prog: "
        killproc $ZABBIX_BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_agentd
        echo
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload|restart)
        stop
        sleep 10
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f /var/lock/subsys/zabbix_agentd ]; then
            stop
            start
        fi
        ;;
  status)
        status $ZABBIX_BIN
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {condrestart|start|stop|restart|reload|status}"
        exit 1
esac

exit $RETVAL

  

2.2 服务端的系统服务脚本

 同样的方法,这里就不演示了

#!/bin/bash
#
#       /etc/rc.d/init.d/zabbix_server
#
# Starts the zabbix_server daemon
#
# chkconfig: - 95 5
# description: Zabbix Monitoring Server
# processname: zabbix_server
# pidfile: /tmp/zabbix_server.pid

# Modified for Zabbix 2.0.0
# May 2012, Zabbix SIA

# Source function library.

. /etc/init.d/functions

RETVAL=0
prog="Zabbix Server"
ZABBIX_BIN="/usr/local/sbin/zabbix_server"

if [ ! -x ${ZABBIX_BIN} ] ; then
        echo -n "${ZABBIX_BIN} not installed! "
        # Tell the user this has skipped
        exit 5
fi

start() {
        echo -n $"Starting $prog: "
        daemon $ZABBIX_BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix_server
        echo
}

stop() {
        echo -n $"Stopping $prog: "
        killproc $ZABBIX_BIN
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix_server
        echo
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload|restart)
        stop
        sleep 10
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f /var/lock/subsys/zabbix_server ]; then
            stop
            start
        fi
        ;;
  status)
        status $ZABBIX_BIN
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {condrestart|start|stop|restart|reload|status}"
        exit 1
esac

exit $RETVAL

  

以上是关于zabbix的启动和关闭脚本的主要内容,如果未能解决你的问题,请参考以下文章

如何在zabbix执行远程主机的脚本或指令

Zabbix的2个使用小案例

zabbix_proxy开机启动脚本

学习四个小案例,让 Zabbix 应用技能更上层楼 | 运维进阶

Zabbix中小型企业Zabbix监控实战之告警大全

Zabbix源码安装,使用service命令管理zabbix进程