此脚本是Zabbix_Agentd安装脚本,有需要朋友可以参考,脚本内容如下:
系统环境:CentOS 7.4
软件版本:4.4.3
[root@localhost ~]# vim auto_install_zabbix_agentd.sh
#!/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 "\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
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。