批量安装zabbix-agent脚本,为了方便识别名称,自动根据IP最后一位对主机进行重命名操作,方便zabbix-server开启批量注册时,名称识别时用。也避免zabbix-server老是30分钟提示一次主机名被更改。
软件和配置文件都放在一台机器上。
- #!/bin/bash
- #desc: used for autoinstall zabbix client
- 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://172.16.10.165/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://172.16.10.165/zabbix_soft/zabbix_agentd.conf -P /etc/zabbix/
- 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
本文出自 “潜入技术的海洋” 博客,请务必保留此出处http://myhat.blog.51cto.com/391263/897020