自动安装Zabbix Agent的linux 脚本
安装Zabbix代理的脚本:
#!/bin/bash #the zabbix path you want to install PREFIX="/usr/local/zabbix" ConfigFile="/etc/zabbix/zabbix_agentd.conf" # List of comma delimited IP addresses (or hostnames) of Zabbix servers. Server="serverName" #Required for active checks and must match hostname as configured on the server. Hostname=`hostname` function checkReturn { if [ $1 -ne 0 ]; then echo "fail: $2" echo "$3" exit else echo "pass: $2" fi sleep 3 } [ -n "$(pidof -s zabbix_agentd)" ] && { echo "zabbix_agentd process is already running....." exit 1 } [ -n "$(which zabbix_agentd 2> /dev/null)" ] && { echo "zabbix_agentd program has been installed....." exit 1 } # check selinux if [ "`/usr/sbin/sestatus|awk ‘/status/{print $3}‘`" == "enabled" ]; then checkReturn 1 "Disable SELinux and then retry" fi rpm -q gcc make || { yum install gcc make RETVAL=$? checkReturn $RETVAL "Package install" } if [ -z "$(id -u zabbix 2> /dev/null)" ] then useradd zabbix -s /sbin/nologin fi wget http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/2.0.8/zabbix-2.0.8.tar.gz RETVAL=$? checkReturn $RETVAL "downloading source" "check mirror might be down" tar xvf zabbix-2.0.8.tar.gz cd zabbix-2.0.8 ./configure --prefix=${PREFIX} --enable-agent RETVAL=$? checkReturn $RETVAL "Configure" make RETVAL=$? checkReturn $RETVAL "Compile" make install RETVAL=$? checkReturn $RETVAL "make install" echo "zabbix agentd install ok....!" mkdir -p /var/log/zabbix chown zabbix.zabbix /var/log/zabbix echo "configure zabbix startup script.....!" cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/ chmod 755 /etc/init.d/zabbix_agentd sed -i ‘s#BASEDIR=/usr/local#&/zabbix#‘ /etc/init.d/zabbix_agentd chkconfig --level 345 zabbix_agentd on echo "copy the configuration file to zabbix installion directory.....!" if [ -d ${PREFIX}/etc ] then /bin/rm -rf ${PREFIX}/etc/* cp conf/zabbix_agentd.conf ${PREFIX}/etc fi echo "add link file.....!" ln -s /usr/local/zabbix/etc /etc/zabbix ln -s /usr/local/zabbix/bin/* /usr/bin/ ln -s /usr/local/zabbix/sbin/* /usr/sbin/ [ -f "$ConfigFile" ] && { sed -i "/^Server=/s#.*#Server=$Server#" $ConfigFile sed -i "/^ServerActive/s#.*#ServerActive=$Server:10051#" $ConfigFile sed -i ‘/^LogFile=/s#.*#LogFile=/var/log/zabbix/zabbix_agentd.log#‘ $ConfigFile sed -i ‘/UnsafeUserParameters=0/aUnsafeUserParameters=1‘ $ConfigFile if [ -n $Hostname ] then sed -i "/^Hostname=/c\Hostname=${Hostname}" $ConfigFile fi } echo ‘/etc/services add service port.....!‘ cat >> /etc/services << EOF #zabbix agentd zabbix-agent 10050/tcp #Zabbix Agent zabbix-agent 10050/udp #Zabbix Agent zabbix-trapper 10051/tcp #Zabbix Trapper zabbix-trapper 10051/udp #Zabbix Trapper EOF
*将下面的改为自己的zabbix的服务器
Server="serverName"
本文出自 “缘随心愿” 博客,请务必保留此出处http://281816327.blog.51cto.com/907015/1618036
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。