Zabbix_Agentd自动化安装脚本

小柒博客
小柒博客
小柒博客
313
文章
93
评论
2020-04-0814:37:57 评论 3.6K 2164字阅读7分12秒

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

系统环境:CentOS 7.4

软件版本:4.4.3

[root@localhost ~]# vim auto_install_zabbix_agentd.sh

#!/bin/bash
#2020-3-13 10:17:32
#By Author YangXingZhen
#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 "\033[32mThe Zabbix_Agent Install sussess...\033[0m"
	else
		echo -e "\033[31mThe Zabbix_Agent Install fail,Please check...\033[0m"
		exit 1
	fi
else
	echo -e "\033[31mThe Zabbix_Agent already Install...\033[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 "\033[32m请输入Zabbix_Server的服务器IP:\033[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 "\033[31m输入错误,服务器IP地址不能为空...\033[0m"
	elif [ "${SERVER_IP}" = "q" -o "${SERVER_IP}" = "Q" ];then
		Code="break"
	else
		echo -e "\033[31m你输入服务器IP:${SERVER_IP} 错误,请输入正确的服务器IP地址...\033[0m"
	fi
${Code}
done
}

Menu_Zabbix_Agent

脚本执行方式:

[root@localhost ~]# sh auto_install_zabbix_agentd.sh

继续阅读
  • 微信号
  • 微信扫一扫加我!
  • weinxin
  • 微信公众号
  • 微信扫一扫关注我!
  • weinxin
小柒博客
  • 本文由 发表于 2020-04-0814:37:57
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: