Zabbix_Agentd自动化安装脚本

2021-07-06 10:52:29 浏览数 (1)

此脚本是Zabbix_Agentd安装脚本,有需要朋友可以参考,脚本内容如下:

系统环境:CentOS 7.4

软件版本:4.4.3

[root@localhost ~]# vim auto_install_zabbix_agentd.sh

代码语言:javascript复制
#!/bin/bash
#Date:2018-5-20 14:08:55
#Author Blog:
#	https://www.yangxingzhen.com
#Author WeChat:
#	微信公众号:小柒博客
#Author mirrors site:
#	https://mirrors.yangxingzhen.com
#About the Author
#	BY:YangXingZhen
#	Mail:xingzhen.yang@yangxingzhen.com
#Auto Install Zabbix_Agent
#Define Zabbix path variables
ZABBIX_URL=http://mirrors.yangxingzhen.com/zabbix
ZABBIX_FILES=zabbix-4.4.3.tar.gz
ZABBIX_FILES_DIR=zabbix-4.4.3
ZABBIX_PREFIX=/usr/local/zabbix
function Install_Zabbix_Agent (){
#Install Zabbix_Agent
if [ ! -d ${ZABBIX_PREFIX} ];then
	#Install Package
	yum -y install pcre pcre-devel libevent libevent-devel wget gcc gcc-c  
	wget -c ${ZABBIX_URL}/${ZABBIX_FILES}
	tar xf ${ZABBIX_FILES}
	cd ${ZABBIX_FILES_DIR}
	./configure --prefix=${ZABBIX_PREFIX} --enable-agent
	if [ $? -eq 0 ];then
		make && make install
		echo -e "33[32mThe Zabbix_Agent Install sussess...33[0m"
	else
		echo -e "33[31mThe Zabbix_Agent Install fail,Please check...33[0m"
		exit 1
	fi
else
	echo -e "33[31mThe Zabbix_Agent already Install...33[0m"
	exit 1
fi
#Backup Configuration File
cp ${ZABBIX_PREFIX}/etc/zabbix_agentd.conf ${ZABBIX_PREFIX}/etc/zabbix_agentd.conf.bak
ln -sf ${ZABBIX_PREFIX}/sbin/zabbix_* /usr/local/sbin/
#Config Zabbix_Agent File
cat >${ZABBIX_PREFIX}/etc/zabbix_agentd.conf <<EOF
LogFile=/tmp/zabbix_agentd.log
Server=${SERVER_IP}
ServerActive=${SERVER_IP}
Hostname=$(hostname -I)
EnableRemoteCommands=1
UnsafeUserParameters=1
LogFileSize=10
Timeout=30
EOF
#Configuring system services
cp misc/init.d/tru64/zabbix_agentd /etc/init.d/zabbix_agentd
chmod o x /etc/init.d/zabbix_agentd
#Create zabbix user
useradd -s /sbin/nologin zabbix >/dev/null 2>&1
#Start Zabbix_agentd
/etc/init.d/zabbix_agentd start
#Configure power on self start
grep -qw "/etc/init.d/zabbix_agentd" /etc/rc.d/rc.local
if [ $? -ne 0 ];then
	echo "/etc/init.d/zabbix_agentd start" >>/etc/rc.d/rc.local
	chmod  x /etc/rc.d/rc.local
fi
}
function Menu_Zabbix_Agent (){
stty erase '^H'
Code=""
while true
do
	read -p "$(echo -e "33[32m请输入Zabbix_Server的服务器IP:33[0m")" SERVER_IP
	ping "${SERVER_IP}" 2>&1 -c 2|grep -q "ttl" >/dev/null
	if [ $? -eq 0 ];then
		Install_Zabbix_Agent
		Code=break
	elif [ -z "${SERVER_IP}" ];then
		echo -e "33[31m输入错误,服务器IP地址不能为空...33[0m"
	elif [ "${SERVER_IP}" = "q" -o "${SERVER_IP}" = "Q" ];then
		Code="break"
	else
		echo -e "33[31m你输入服务器IP:${SERVER_IP} 错误,请输入正确的服务器IP地址...33[0m"
	fi
${Code}
done
}
Menu_Zabbix_Agent

0 人点赞