最近使用过的Zabbix agent自动安装脚本,做个备份。所用服务器环境为Ubuntu 10.04 64位,Ubuntu官方源中的Zabbix agent有点陈旧,都是老版本了,这里用的是目前最新版本2.0.5.需要更具需求来装了!
将以下内容保存为Zabbixinstall.sh,放置合适目录,并通过chmod获取相应权限后运行(./zabbixinstall.sh):
groupadd zabbix;/usr/sbin/useradd -g zabbix -s /sbin/nologin zabbixwget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/2.0.5/zabbix-2.0.5.tar.gz tar xvfz zabbix-2.0.5.tar.gzcd zabbix-2.0.5 ./configure --enable-agentmake install #mkdir /etc/zabbix ;cp misc/conf/zabbix_agentd.conf /etc/zabbix cd /usr/local/etcsed -i 's/^Server=127.0.0.1/Server=192.168.1.106/g' zabbix_agentd.conf /usr/local/sbin/zabbix_agentd
以下为网上网络到的CentOS及Debian的自动安装脚本:Centos_zabbix.sh
#!/bin/bash zabbix_server_ip="192.168.x.xx" inner_ip=`sudo /sbin/ifconfig eth1 |awk '/inet/ {split($2,x,":");print x[2]}'` tar xvzf zabbix-1.8.2.tar.gz cd zabbix-1.8.2 sudo /usr/sbin/useradd zabbix sudo mkdir -p /var/log/zabbix /opt/app/zabbix /etc/zabbix sudo chown -R zabbix /var/log/zabbix/ ./configure --prefix=/opt/app/zabbix --enable-agent make sudo make install sudo cp misc/conf/zabbix_agentd.conf /etc/zabbix/ sudo cp misc/init.d/Fedora/core5/zabbix_agentd /etc/init.d/ sudo /sbin/chkconfig zabbix_agentd on sudo sed -i -e '/^LogFile/s/^.*$/LogFile=\/var\/log\/zabbix\/zabbix_agentd.log/' /etc/zabbix/zabbix_agentd.conf sudo sed -i -e "/Server=127/s/127.0.0.1/${zabbix_server_ip}/" /etc/zabbix/zabbix_agentd.conf sudo sed -i -e "/^hostname/s/^.*$/Hostname=`hostname`/" /etc/zabbix/zabbix_agentd.conf sudo sed -i -e "/ListenIP=127/s/^.*$/ListenIP=${inner_ip}/" /etc/zabbix/zabbix_agentd.conf #sudo sed -i -e '/^PID=/s/\/var//' /etc/init.d/zabbix_agentd sudo sed -i -e '/^ZABBIX_BIN=/s/usr\/bin/opt\/app\/zabbix\/sbin/' /etc/init.d/zabbix_agentd #sudo sed -i -e '/\$0 stop/asleep 2' /etc/init.d/zabbix_agentd sudo /etc/init.d/zabbix_agentd start ps aux | grep zabbix tail /var/log/zabbix/zabbix_agentd.log
下面是debian的。debian_zabbix.sh
#!/bin/bash zabbix_server_ip="192.168.x.x" inner_ip=`sudo /sbin/ifconfig eth1 |awk '/inet/ {split($2,x,":");print x[2]}'` tar xvzf zabbix-1.8.2.tar.gz cd zabbix-1.8.2 sudo /usr/sbin/useradd zabbix sudo mkdir -p /var/log/zabbix /opt/app/zabbix /etc/zabbix sudo chown -R zabbix /var/log/zabbix/ ./configure --prefix=/opt/app/zabbix --enable-agent make sudo make install sudo cp misc/conf/zabbix_agentd.conf /etc/zabbix/ sudo cp misc/init.d/debian/zabbix-agent /etc/init.d/ sudo /usr/sbin/update-rc.d zabbix-agent defaults sudo sed -i -e '/^LogFile/s/^.*$/LogFile=\/var\/log\/zabbix\/zabbix_agentd.log/' /etc/zabbix/zabbix_agentd.conf sudo sed -i -e "/Server=127/s/127.0.0.1/${zabbix_server_ip}/" /etc/zabbix/zabbix_agentd.conf sudo sed -i -e "/^Hostname/s/^.*$/Hostname=`hostname`/" /etc/zabbix/zabbix_agentd.conf sudo sed -i -e "/ListenIP=127/s/^.*$/ListenIP=${inner_ip}/" /etc/zabbix/zabbix_agentd.conf sudo sed -i -e '/^PID=/s/\/var//' /etc/init.d/zabbix-agent sudo sed -i -e '/^DAEMON=/s/home\/zabbix\/bin/opt\/app\/zabbix\/sbin/' /etc/init.d/zabbix-agent sudo sed -i -e '/\$0 stop/asleep 2' /etc/init.d/zabbix-agent sudo /etc/init.d/zabbix-agent start ps aux | grep zabbix tail /var/log/zabbix/zabbix_agentd.log
脚本都是死的,使用的时候得根据个人需求改相应的配置了。
本文转自 蔡小赵 51CTO博客,原文链接:http://blog.51cto.com/zhaopeiyan/1732943