#!/bin/sh
###Zabbix客户端部署脚本###
#下载zabbix
#cd /tmp
#wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.2.3/zabbix-2.2.3.tar.gz
#用户组和用户建立
/usr/sbin/groupadd zabbix
/usr/sbin/useradd -g zabbix -M zabbix
#解压文件
tar -zxvf zabbix-2.2.3.tar.gz
#编译安装
cd zabbix-2.2.3
./configure --prefix=/usr/local/zabbix --enable-agent
make && make install
#修改启动脚本
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
sed -i ‘s/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g‘ /etc/init.d/zabbix_agentd
#添加服务
/sbin/chkconfig --add zabbix_agentd
/sbin/chkconfig zabbix_agentd on
#修改zabbix_agent配置文件
echo "" > /usr/local/zabbix/etc/zabbix_agentd.conf
cat >> /usr/local/zabbix/etc/zabbix_agentd.conf << EOF
LogFile=/var/log/zabbix_agentd.log
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFileSize=4
StartAgents=1
DebugLevel=3
Timeout=30
EnableRemoteCommands=0
LogRemoteCommands=0
RefreshActiveChecks=60
BufferSend=60
BufferSize=500
MaxLinesPerSecond=100
Server=serverip,127.0.0.1
ListenIP=0.0.0.0
ListenPort=10050
ServerActive=serverip:10051
Hostname=`/sbin/ifconfig | grep "inet addr:"|grep -v 127.0.0.1|awk -F : ‘{print $2}‘|awk ‘{print $1}‘|head -1`
UnsafeUserParameters=1
EOF
#创建日志并授权
touch /var/log/zabbix_agentd.log
chown -R zabbix:zabbix /var/log/zabbix_agentd.log
#创建PID目录并授权
mkdir -p /var/run/zabbix
chown -R zabbix:zabbix /var/run/zabbix
#改变zabbix家目录的属主
chown -R zabbix:zabbix /usr/local/zabbix/
#启动
/etc/init.d/zabbix_agentd start
/etc/init.d/zabbix_agentd restart
#查看端口
netstat -tunlp|grep 10050