#!/bin/bash
# zabbix server 或 zabbix proxy IP,根据实际情况设置
SERVER_IP="172.20.50.21"
# get network ip addr function
function getIP()
{
NET=$1
if [ "$NET" = "" ]; then
NET="eth0"
fi
IP=""
if [ $(ifconfig | grep "$NET" | wc -l) -gt 0 ]; then
IP=$(ifconfig $NET | grep 'inet addr:' | awk -F: '{print $2}' | awk '{print $1}')
fi
echo $IP
}
# get IP segment function
function getSegment()
{
IP_ADD=$1
N=$2
echo $(echo $IP_ADD | cut -d. -f$N)
}
ETH0_IP=$(getIP eth0)
IP_ADDR=$ETH0_IP
LOCAL_IP=$IP_ADDR
yum -y install gcc
groupadd zabbix
useradd -g zabbix -s /sbin/nologin -M zabbix
cd /usr/local/src
tar zxvf zabbix_agents_2.2.19.linux2_6.amd64.tar.gz
cd zabbix_agents_2.2.19.linux2_6.amd64
./configure --prefix=/usr/local/zabbix --enable-agent
make
make install
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d
sed -i 's/BASEDIR=\/usr\/local/BASEDIR=\/usr\/local\/zabbix/g' /etc/init.d/zabbix_agentd
chkconfig --add zabbix_agentd
chkconfig zabbix_agentd on
sed -i "s/^Server=127.0.0.1/Server=$SERVER_IP/g" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i "s/^ServerActive=127.0.0.1/#ServerActive=127.0.0.1/" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i "s/^# ListenIP=0.0.0.0/ListenIP=$LOCAL_IP/" /usr/local/zabbix/etc/zabbix_agentd.conf
sed -i 's/^# UnsafeUserParameters=0/UnsafeUserParameters=1/' /usr/local/zabbix/etc/zabbix_agentd.conf
/etc/init.d/zabbix_agentd start