Alexsandro Felix

como inicializar automaticamente o Zabbix no CentOS

Esta dica é pra você, que configurou o Zabbix no CentOS 7 e está quebrando a cabeça para fazer com que o Zabbix inicie automaticamente através do ntsysv.


# vim /etc/init.d/zabbix_server


#!/bin/bash
#
# chkconfig: - 85 15
# description: zabbix server daemon
#

### BEGIN INIT INFO
# Provides: zabbix
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: start and stop zabbix server
# Description: Zabbix Server
### END INIT INFO

# zabbix details
ZABBIX=/usr/sbin/zabbix_server
CONF=/etc/zabbix/zabbix_server.conf
PIDFILE=/var/run/zabbix/zabbix_server.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x $ZABBIX ] || exit 5
[ -e $CONF ] || exit 6
RETVAL=0
case "$1" in
start)
echo -n "Starting zabbix server: "
daemon $ZABBIX -c $CONF
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix
;;
stop)
echo -n "Shutting down zabbix server: "
killproc zabbix_server
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix
;;
restart|reload)
$0 stop
$0 start
RETVAL=$?
;;
status)
status zabbix_server
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
;;
esac
exit $RETVAL

# vim /etc/init.d/zabbix_agentd

# !/bin/bash
#
# chkconfig: - 85 15
# description: zabbix agent daemon
#

### BEGIN INIT INFO
# Provides: zabbix-agent
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: start and stop zabbix agent
# Description: Zabbix Agent
### END INIT INFO

# zabbix details
ZABBIX_AGENTD=/usr/sbin/zabbix_agentd
CONF=/etc/zabbix/zabbix_agentd.conf
PIDFILE=/var/run/zabbix/zabbix_agentd.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network                                                                       
                                                                                                 
# Check that networking is up.                                                                     
[ ${NETWORKING} = "no" ] && exit 0                                                                   
                                                                                                       
[ -x $ZABBIX_AGENTD ] || exit 5                                                                           
[ -e $CONF ] || exit 6                                                                                      
RETVAL=0                                                                                                       
case "$1" in                                                                                                     
start)                                                                                                              
echo -n "Starting zabbix agent: "                                                                                    
daemon $ZABBIX_AGENTD -c $CONF                                                                                         
RETVAL=$?                                                                                                                
echo                                                                                                                        
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix-agent                                                                                       
;;                                                                                                                                             
stop)                                                                                                                                          
echo -n "Shutting down zabbix agent: "
killproc zabbix_agentd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix-agent
;;
restart|reload)
$0 stop
$0 start
RETVAL=$?
;;
status)
status zabbix_agentd
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status}"
exit 1
;;
esac
exit $RETVAL

[root@localhost ~]

# reset

[root@localhost ~]

# cat /etc/init.d/zabbix_agentd # !/bin/bash # # chkconfig: – 85 15 # description: zabbix agent daemon # ### BEGIN INIT INFO # Provides: zabbix-agent # Required-Start: $local_fs $network # Required-Stop: $local_fs $network # Default-Start: # Default-Stop: 0 1 2 3 4 5 6 # Short-Description: start and stop zabbix agent # Description: Zabbix Agent ### END INIT INFO # zabbix details ZABBIX_AGENTD=/usr/sbin/zabbix_agentd CONF=/etc/zabbix/zabbix_agentd.conf PIDFILE=/var/run/zabbix/zabbix_agentd.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = “no” ] && exit 0 [ -x $ZABBIX_AGENTD ] || exit 5 [ -e $CONF ] || exit 6 RETVAL=0 case “$1” in start) echo -n “Starting zabbix agent: ” daemon $ZABBIX_AGENTD -c $CONF RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/zabbix-agent ;; stop) echo -n “Shutting down zabbix agent: ” killproc zabbix_agentd RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zabbix-agent ;; restart|reload) $0 stop $0 start RETVAL=$? ;; status) status zabbix_agentd RETVAL=$? ;; *) echo “Usage: $0 {start|stop|restart|reload|status}” exit 1 ;; esac exit $RETVAL

Tornar os arquivos executáveis:


# chmod +x /etc/init.d/zabbix_server
# chmod +x /etc/init.d/zabbix_agentd

Adicionar o serviço ao sistema:


# chkconfig --add /etc/init.d/zabbix_server
# chkconfig --add /etc/init.d/zabbix_agentd

Ativar inicialização automática:

# ntsysv

Referência: zabbixbrasil.org

Sair da versão mobile