Zabbix Agent的安装
一、 添加Zabbix用户和组
1. groupadd zabbix;
2. useradd zabbix -g zabbix -s /sbin/nologin;
二、获取Zabbix软件,并解压缩
获取软件包,建议登录zabbix官网获得具体地址如下:
http://www.zabbix.com/download.php
三、解压缩Zabbix软件包后,编译并安装
1. mkdir /usr/local/zabbix;
2. cd /usr/local/zabbix 解压软件包到当前目录下;
tar -vxf /zabbix-2.4.5.tar;
cd zabbix-2.4.5;
3、./configure –prefix=/usr/local/zabbix --enable-agent;
make install ;
四、创建Zabbix Agent配置文件
1. vi /usr/local/zabbix/etc/zabbix_agentd.conf 将原有备份,并将以下配置信息覆盖该配置文件。
文件内容如下(请修改Server参数后的“Zabbix Server的IP地址”hostname 为agent-server的主机名):
[root@MP1 ~]#vi /usr/local/zabbix/etc/zabbix_agentd.conf
Server=
Hostname=MP1
BufferSize=1024
Timeout=5
StartAgents=3
DebugLevel=2
PidFile=/tmp/zabbix_agentd.pid
LogFile=/tmp/zabbix_agentd.log
LogFileSize=10
EnableRemoteCommands=1
#UnsafeUserParameters=1
2. 重要一步 防火墙
iptables -A INPUT -m state --state NEW -m udp -p udp --dport 10050:10051 -j ACCEPT
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 10050:10051 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
service iptables save;
五、编辑/etc/services
增加如下内容:
zabbix-agent 10050/tcp #Zabbix Agent
zabbix-agent 10050/udp #Zabbix Agent
七、Zabbix自启动配置
1.将自启动脚本拷贝到/etc/init.d/中:
cp zabbix_agent.sh /etc/init.d/
并增加可执行权限。
zabbix_agent.sh脚本的具体内容如下:
vi /etc/init.d/zabbix_agent.sh
#!/bin/bash
#
#zabbix_agent.sh startup for zabbix_agentd
#
# chkconfig: 2345 99 01
# description: Apache is a World Wide Web server.
#
umask 022
CAT=/bin/cat
KILL=/bin/kill
SU_USER=zabbix
ZABBIX_AGENT=/usr/local/zabbix/sbin/zabbix_agentd
PIDFILE=/tmp/zabbix_agentd.pid
status_service() {
if [ -r $PIDFILE -a ! -z ${PIDFILE} ]; then
PID=`${CAT} ${PIDFILE}`
fi
if [ ${PID:=0} -gt 1 -a ! "X$PID" = "X " ]; then
echo "Zabbix_agent is running !"
else
echo "Zabix_agent is stoped!"
fi
}
stop_service() {
if [ -r $PIDFILE -a ! -z ${PIDFILE} ]; then
PID=`${CAT} ${PIDFILE}`
fi
if [ ${PID:=0} -gt 1 -a ! "X$PID" = "X " ]; then
${KILL} ${PID}
zabbix_rc=$?
if [ $zabbix_rc -ne 0 ]; then
echo "$0: Error ${zabbix_rc} stoping ${ZABBIX_AGENT}... bailing."
exit $zabbix_rc
else
echo "Zabbix_agent has been stoped!"
fi
else
echo "Unable to read PID file $PIDFILE"
fi
}
start_service() {
# XXX We really should check if the service is already going, but
# XXX we will opt out at this time.
# Start zabbix_server
echo "starting $ZABBIX_AGENT... " ;
${ZABBIX_AGENT}
zabbix_rc=$?
if [ $zabbix_rc -ne 0 ]; then
echo "$0: Error ${zabbix_rc} starting ${ZABBIX_AGENT}... bailing."
exit $zabbix_rc
fi
echo done.
}
case $1 in
'start')
start_service
;;
'stop')
stop_service
;;
'status')
status_service
;;
'restart')
stop_service
/bin/sleep 5 && \
start_service
;;
*)
echo "$0: usage: $0 {start|stop|restart}"
;;
esac
如果该文件中的内容(安装目录和可执行文件目录)与实际状况不同,那么则需要修改。
3、自启动配置:
chkconfig --add zabbix-agent;
chkconfig --level 35 zabbix-agent on;
chkconfig --list zabbix-agent;
zabbix_agent.sh 0:off 1:off 2:off 3:on 4:off 5:on 6:off
表示系统启动级别为3和5时该服务会自动启动。
八、启停Zabbix Agent
1、zabbix_agentd的启动、停止、状态查看和重启都可以通过以下命令完成:
service zabbix-agent start|stop|status|restart
2、使用netstat命令查看Zabbix Agent是否已被正常启动:
netstat -utlnp | grep zabbix