51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Linux环境安装Zabbix_Agentd自动化脚本

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

系统环境:CentOS 7.9文章源自小柒网-https://www.yangxingzhen.cn/6697.html

软件版本:4.4.3文章源自小柒网-https://www.yangxingzhen.cn/6697.html

[root@localhost ~]# vim auto_install_zabbix_agentd.sh文章源自小柒网-https://www.yangxingzhen.cn/6697.html

#!/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 https://51tbox.com/
/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

脚本执行方式:文章源自小柒网-https://www.yangxingzhen.cn/6697.html

[root@localhost ~]# sh auto_install_zabbix_agentd.sh文章源自小柒网-https://www.yangxingzhen.cn/6697.html 文章源自小柒网-https://www.yangxingzhen.cn/6697.html
继续阅读 Shell最后更新:2022-12-6

赞(0)
未经允许不得转载:工具盒子 » Linux环境安装Zabbix_Agentd自动化脚本