zabbix agent自动安装脚本
#!/bin/bash
#desc: used for autoinstall zabbix client
#说明:本脚本旨在批量安装zabbix_agent,在一个服务器上放好软件和配置文件,执行本脚本后,将自动完成安装。后面会贴一个线上在线的配置文件。
modprobe ip_conntrack
src=/usr/local/src
IP=`ifconfig eth0 | grep inet | awk -F ":" '{print $2}' | awk '{print $1}' | cut -d "." -f 4`
IP1=`ifconfig eth0 | grep inet | awk -F ":" '{print $2}' | awk '{print $1}'`
HOSTNAME=`echo IP$IP`
OLDNAME=` grep "HOSTNAME" /etc/sysconfig/network | cut -d "=" -f 2`
hostname `echo IP$IP`
echo "$IP1 $HOSTNAME" >> /etc/hosts
sed -i "s/${OLDNAME}/${HOSTNAME}/g" /etc/sysconfig/network
useradd zabbix
test -e $src/zabbix-1.8.10.tar.gz && rm -rf $src/zabbix-1.8.10.tar.gz
wget http://192.168.1.1/zabbix_soft/zabbix-1.8.10.tar.gz -P $src
cd $src
tar -zxf zabbix-1.8.10.tar.gz
cd zabbix-1.8.10
./configure --prefix=/usr/local/zabbix --with-net-snmp --enable-agent && make install
sleep 1
test -e /etc/zabbix && mv /etc/zabbix /etc/zabbix_bak || mkdir /etc/zabbix
wget http://192.168.1.1/zabbix_soft/zabbix_agentd.conf -P /etc/zabbix/
mkdir /etc/zabbix/scripts/
wget http://192.168.1.1/zabbix_soft/scripts/net-tcp -P /etc/zabbix/scripts/
wget http://192.168.1.1/zabbix_soft/scripts/net-udp -P /etc/zabbix/scripts/
wget http://192.168.1.1/zabbix_soft/scripts/net-close -P /etc/zabbix/scripts/
wget http://192.168.1.1/zabbix_soft/scripts/net-established -P /etc/zabbix/scripts/
wget http://192.168.1.1/zabbix_soft/scripts/net-icmp -P /etc/zabbix/scripts/
wget http://192.168.1.1/zabbix_soft/scripts/net-syn -P /etc/zabbix/scripts/
wget http://192.168.1.1/zabbix_soft/scripts/net-time-wait -P /etc/zabbix/scripts/
chmod u+x /etc/zabbix/scripts/*
echo "zabbix ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
sed -i -e 's/^Defaults.*requiretty/# &/' /etc/sudoers
cp misc/init.d/redhat/zabbix_agentd_ctl /etc/init.d/
chmod u+x /etc/init.d/zabbix_agentd_ctl
sed -i 's/opt/usr\/local/g' /etc/init.d/zabbix_agentd_ctl
sed -i 's/var\/tmp/tmp/g' /etc/init.d/zabbix_agentd_ctl
sed -i "s/IP131/${HOSTNAME}/g" /etc/zabbix/zabbix_agentd.conf
/etc/init.d/zabbix_agentd_ctl start && netstat -tnlp
echo "/etc/init.d/zabbix_agentd_ctl start" >> /etc/rc.local