#!/usr/bin/env bash
#================================================================
#
# systemos=centos7.2
# #this is zabbix_agent install script
# Author:xw thank you!!!
# Date:2018.5.23
# Description:install zabbix-agent
# wang.cong@aliyun.com
#================================================================
systemctl stop firewalld.service && systemctl disable firewalld.service
setenforce 0 && sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
echo "Now this shell will install zabbix_agentd autoly:please wait"
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all && yum makecache
HOSTNAME=cat /etc/hostname |awk NR==1
yum install net-snmp-devel libxml2-devel libcurl-devel gcc gcc+ make -y
echo "add zabbix group and user"
groupadd zabbix
useradd -r zabbix -g zabbix -s /sbin/nologin
echo "download package -make and make install "
cd /usr/local/src
wget -c https://sourceforge.mirrorservice.org/z/za/zabbix/ZABBIX%20Latest%20Stable/3.2.11/zabbix-3.2.11.tar.gz
tar xzvf zabbix-3.2.11.tar.gz
cd zabbix-3.2.11
./configure --prefix=/usr/local/zabbix-3.2.11/ --enable-agent
make && make install
if [ $? -eq 0 ]
then
read -p "please input zabbix_serverIP:" zabbix_serverIP
sed -i 's/Server=127.0.0.1/Server='$zabbix_serverIP'/' /usr/local/zabbix-3.2.11/etc/zabbix_agentd.conf
sed -i 's/ServerActive=127.0.0.1/ServerActive='$zabbix_serverIP'/' /usr/local/zabbix-3.2.11/etc/zabbix_agentd.conf
sed -i 's/Hostname=Zabbix server/Hostname='$HOSTNAME'/' /usr/local/zabbix-3.2.11/etc/zabbix_agentd.conf
else
echo "error please talk your administrator"
fi
/usr/local/zabbix-3.2.11/sbin/zabbix_agentd
if [ $? -eq 0 ]
then
echo "set zabbix_agentd start with system"
echo "/usr/local/zabbix-3.2.11/sbin/zabbix_agentd start" >> /etc/rc.d/rc.local
else
echo "start error,please talk administrator"
fi