NAME=`hostname`
sed -i '/'$NAME'/d' /etc/hosts
NEWNAME=$1
if [ $# -eq 1 -a ! -z "$NEWNAME" ];then
echo "Setting HOSTNAME"
sed -i "s/$NAME/$NEWNAME/" /etc/sysconfig/network
hostname $NEWNAME
else
echo "The hostname of this server must not be empty"
exit 1
fi
if [ ! -f "zabbix-3.0.4.tar.gz" ];then
echo "zabbix-3.0.4.tar.gz is not exist"
exit 1
fi
tar zxvf zabbix-3.0.4.tar.gz
cd zabbix-3.0.4
sleep 1
/bin/bash configure --prefix=/usr --sysconfdir=/etc/zabbix --enable-agent
sleep 3
if [ $? != 0 ]; then
echo "configure was wrong!!"
exit 1
else
echo "The zabbix is aready installed!!"
fi
make && make install
if [ $? != 0 ]; then
echo "There were something wrong in make!!!"
exit 1
fi
#创建zabbix日志目录
if [ ! -d "$log_d" ];then
mkdir $log_d
fi
chown zabbix.zabbix $log_d
#修改配置文件
/bin/cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
chmod 755 /etc/init.d/zabbix_agentd
sed -i "s#BASEDIR=/usr/local#BASEDIR=/usr/#g" /etc/init.d/zabbix_agentd
sed -i "s/Server\=127.0.0.1/Server\=127.0.0.1,$MASTER/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/ServerActive\=127.0.0.1/ServerActive\=$MASTER:10051/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/Hostname=Zabbix server/Hostname=$hname/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s#tmp/zabbix_agentd.log#var/log/zabbix/zabbix_agentd.log#g" /etc/zabbix/zabbix_agentd.conf
sed -i "#UnsafeUserParameters=0#aUnsafeUserParameters=1\n" /etc/zabbix/zabbix_agentd.conf
#启动服务
chkconfig zabbix_agentd on
service zabbix_agentd start
return 1
}
pid=`pgrep zabbix_agentd`
if [ -n "$pid" ];then
echo "the zabbix_agentd is aready installed!"
echo "Do want to reload the zabbix_agentd? Y/N"
read choice
case $choice in
Y) service zabbix_agentd stop;zabbix_agentd_install ;;
N) echo "You choose N,the script will be break";exit 2;;
*) echo "UNknow anwser!";exit 3;;
esac
else
add_user_zabbix
zabbix_agentd_install
exit 4
fi