#!/bin/bash
ZABBIX_AGENT=/tmp/zabbix*.tar.gz
id zabbix > /dev/null 2>&1
if [ $? -eq 1 ];then
useradd zabbix -u 201 -s /sbin/nologin
fi
tar xvf $ZABBIX_AGENT -C /tmp
cd /tmp/zabbix*
/tmp/zabbix*/configure --prefix=/usr/local/zabbix --enable-agent && make install
#log file
mkdir /var/log/zabbix
chown zabbix.zabbix /var/log/zabbix
#copy zabbix start script
cp /tmp/zabbix*/misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
chmod 755 /etc/init.d/zabbix_agentd
#config zabbix start script,change BASEDIR
sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/local/zabbix#g" /etc/init.d/zabbix_agentd
ln -s /usr/local/zabbix/etc/* /etc/zabbix/
ln -s /usr/local/zabbix/bin/* /usr/bin/
ln -s /usr/local/zabbix/sbin/* /usr/sbin/
#configure zabbix_agentd.conf
sed -i "s/Server\=127.0.0.1/Server\=127.0.0.1,192.168.1.110/g" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i "s/ServerActive\=127.0.0.1/ServerActive\=127.0.0.1,192.168.1.110/g" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i "s#/tmp/zabbix_agentd.log#/var/log/zabbix/zabbix_agentd.log#g" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i "#UnsafeUserParameters=0#UnsafeUserParamters=1#g" /usr/local/zabbix/etc/zabbix_agentd.conf
#add service to /etc/services
echo "zabbix-agent 10050/tcp #zabbix agent" >> /etc/services
echo "zabbix-agent 10050/udp #zabbix agent" >> /etc/services
echo "zabbix-trapper 10051/tcp #zabbix trapper" >> /etc/services
echo "zabbix-trapper 10051/udp #zabbix trapper" >> /etc/services
#start service
chkconfig zabbix_agentd on
service zabbix_agentd start
echo "zabbix_agentd installed!"
以上脚本亲测可行。运行平台 centos6.5,有一些不足就是不能自动获取zabbix安装包,不过可以通过搭建ftp ,然后通过wget下载。