Linux环境安装Zabbix_Agentd自动化脚本

小柒博客 评论62,8622字数 440阅读1分28秒阅读模式

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

系统环境:CentOS 7.9

软件版本: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

若文章图片、下载链接等信息出错,请在评论区留言反馈,博主将第一时间更新!如本文“对您有用”,欢迎随意打赏,谢谢!

继续阅读
Wechat
微信扫一扫,加我!
weinxin
微信号已复制
微信公众号
微信扫一扫,关注我!
weinxin
公众号已复制
Shell最后更新:2024-1-24
小柒博客
  • 本文由 小柒博客 发表于 2020年4月8日 14:37:57
  • 声明:本站所有文章,如无特殊说明或标注,本站文章均为原创。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。转载请务必保留本文链接:https://www.yangxingzhen.com/6697.html
匿名

发表评论

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

拖动滑块以完成验证