环境: centos7
[root@localhost zabbix]# hostnamectl
Static hostname: localhost.localdomain
Icon name: computer-vm
Chassis: vm
Machine ID: cd1fb65f4b0e4d1283b15080b07aef92
Boot ID: 770adca33f1d45099d7f967c7e054ba2
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-693.el7.x86_64
Architecture: x86-64
安装包以及依赖
rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-agent-3.4.7-1.el7.x86_64.rpm
yum install -y sysstat
编辑zabbix_agentd配置文件
[root@localhost zabbix]# cat /etc/zabbix/zabbix_agentd.conf |grep -v '^#' |grep -v "^$"
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
EnableRemoteCommands=1
Server=192.168.1.142
ServerActive=192.168.1.142
Hostname=jfgitlab
AllowRoot=1
Include=/etc/zabbix/zabbix_agentd.d/*.conf
注:如果是zabbix_agentd与docker zabbix_server 部署在同一台服务器上,需要配置的Server
以及ServerActive
IP地址为docker容器内部IP,通过下面命令获取。
# docker exec -it zabbix_server ip addr
导入脚本
# mkdir /etc/zabbix/scripts
# mv disk_discovery.py disk_status.sh sysinfo.py /etc/zabbix/scripts/
# chmod +x /etc/zabbix/scripts/*
# echo 'UserParameter=sysinfo,/etc/zabbix/scripts/sysinfo.py' > /etc/zabbix/zabbix_agentd.d/userparameter_system.conf
# echo 'UserParameter=disk.discovery,/etc/zabbix/scripts/disk_discovery.py
UserParameter=disk.status[*],/etc/zabbix/scripts/disk_status.sh $1 $2' > /etc/zabbix/zabbix_agentd.d/userparameter_disk.conf
后台启动iostat
# nohup /usr/bin/iostat -dxkt 10 > /tmp/iostat_output 2>/dev/null &
# echo "nohup /usr/bin/iostat -dxkt 10 > /tmp/iostat_output 2>/dev/null &" >> /etc/rc.local
# chmod +x /etc/rc.d/rc.local
服务化
#!/bin/sh
#
# chkconfig: 2345 10 90
# description: Starts and stops Zabbix Agent using chkconfig
SERVICE="Zabbix agent"
DAEMON=/usr/sbin/zabbix_agentd
PIDFILE=/var/run/zabbix/zabbix_agentd.pid
case $1 in
'start')
if [ -x ${DAEMON} ]
then
$DAEMON
# Error checking here would be good...
echo "${SERVICE} started."
else
echo "Can't find file ${DAEMON}."
echo "${SERVICE} NOT started."
fi
;;
'stop')
if [ -s ${PIDFILE} ]
then
if kill `cat ${PIDFILE}` >/dev/null 2>&1
then
echo "${SERVICE} terminated."
rm -f ${PIDFILE}
fi
fi
;;
'restart')
$0 stop
sleep 10
$0 start
;;
*)
echo "Usage: $0 start|stop|restart"
;;
esac
启动服务
# chmod +x /etc/init.d/zabbix_agentd
# chkconfig --add zabbix_agentd
# /etc/init.d/zabbix_agentd start