shell安装zabbix 3.7客户端

#!/bin/bash
##############################################################
# File Name: install_zabbix_agentd.sh
# Version: V1.0
# Author: Tim
# Organization: opensource
# Created Time : 2017-09-11 22:38:36
# Description:
##############################################################
#sh scriptname 服务器IP地址(主机名)

sourceFile=/usr/local/src
agentFileName=zabbix-3.2.7
installDir=/usr/local/zabbix

##########指定服务器IP地址##########

zabbixServerIp=$1

##########获取本地客户端IP地址作为Hostname##########
##注意获取服务器的IP有可能是方法2:
#方法2:localIp=`ifconfig em2 | awk 'NR==2{print}' | awk '{print $2}' | awk -F ':' '{print $2}'`

localIp=`ifconfig | awk 'NR==2{print}' | awk '{print $2}'`

echo "本地客户端IP地址为:$localIp"


cd $sourceFile

[ -f ${agentFileName}.tar.gz ] && tar -xvf ${agentFileName}.tar.gz

useradd zabbix -g zabbix -s /sbin/nologin

cd $agentFileName


./configure --prefix=$installDir/zabbix-agent --sysconfdir=$installDir --enable-agent
make install

[ $? -eq 0 ] && echo  "zabbix make install sucessed"

sleep 1

echo "begind to modify config file......"

sleep 1

echo "复制启动文件设置启动项"
cp misc/init.d/tru64/zabbix_agentd /etc/init.d/

sed -i "/^# Zabbix/i# chkconfig: 2345 66 34\n#description:zabbix agent" /etc/init.d/zabbix_agentd

sed -i "/^DAEMON=/c DAEMON=$installDir/zabbix-agent/sbin/zabbix_agentd" /etc/init.d/zabbix_agentd

chmod +x /etc/init.d/zabbix_agentd

sleep 1

echo "开始修改配置文件zabbix_agentd.conf"
##########配置zabbix_agentd配置文件##########

sed -i "s/^Server=127.0.0.1/Server=$zabbixServerIp/" $installDir/zabbix_agentd.conf
sed -i "s/^Hostname=Zabbix server/Hostname=$localIp/" $installDir/zabbix_agentd.conf
sed -i "s/^# UnsafeUserParameters=0/UnsafeUserParameters=1/" $installDir/zabbix_agentd.conf
sed -i "/^# Include=$/c Include=$installDir/zabbix_agentd.conf.d/*.conf" $installDir/zabbix_agentd.conf


echo 'export PATH=$PATH:/usr/local/zabbix/zabbix-agent/bin:/usr/local/zabbix-agent/sbin' >> /etc/profile

source /etc/profile

service zabbix_agentd start

[ $? -eq 0 ] && echo "zabbix_agentd 启动完成"

chkconfig --add zabbix_agentd

你可能感兴趣的:(shell安装zabbix 3.7客户端)