zabbix-agent 一键部署自动上线

2020-12-08 11:06:38 浏览数 (1)

背景

业务环境需要频繁新增Centos7/8 虚拟机,新增主机需要手动安装zabbix-agent,重复的劳动力等于无用功,通过shell脚本实现zabbix-agent 一键安装并在zabbix 平台上线。。。

搭建 Nginx 服务器发布文件目录

zabbix-agent 一键安装脚本

代码语言:javascript复制
#/bin/bash
echo "关闭selinux"
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config
setenforce 0
#yum clean all

checkwget=`rpm -qa wget`
if [ -z $checkwget ];then
  yum  install wget -y  
fi

echo "下载zabbix-agent"
OSVERSION=`cat /etc/redhat-release |awk -F "release " '{print $2}'|awk -F "." '{print $1}'`
#wget -P /opt http://repo.zabbix.com/zabbix/4.0/rhel/$OSVERSION/x86_64/zabbix-agent-4.0.12-1.el$OSVERSION.x86_64.rpm
wget -P /opt http://192.168.99.107/software/zabbix-agent-4.0.12-1.el$OSVERSION.x86_64.rpm
rpm -ivh /opt/zabbix-agent-4.0.12-1.el$OSVERSION.x86_64.rpm
rm -rf /opt/zabbix-agent-4.0.12-1.el$OSVERSION.x86_64.rpm

echo "修改zabbix-agent配置文件"
ipaddr=$(ip a show |grep ens|grep inet |awk '{print $2}'|awk -F '/' '{print $1}')
zabbix_server='192.168.250.252'
hostname=$(hostname)

sed -i "s/^Server=127.0.0.1/Server=${zabbix_server}/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/^ServerActive=127.0.0.1/ServerActive=${zabbix_server}/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/Hostname=Zabbix server/Hostname=${hostname}/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/# HostMetadata=/HostMetadata=Linux/g" /etc/zabbix/zabbix_agentd.conf

echo "防火墙放行zabbix-agent端口"
firewall-cmd --permanent --add-port=10050-10051/tcp
firewall-cmd --reload
echo "启动zabbix-agent服务"
systemctl start zabbix-agent && systemctl  enable zabbix-agent

zabbixagentpid=`ps -ef |grep zabbix_agentd|grep -w 'zabbix_agentd'|grep -v 'grep'|awk '{print $2}'`
if [ "$zabbixagentpid" ];then
      echo "zabbix agent is running "
   else
    echo "zabbix agent 安装失败!!!"
 fi

zabbix-server 配置

动作---自动注册---创建动作

客户端执行Nginx 目录发布的centos.sh 脚本

代码语言:javascript复制
curl http://192.168.99.107/software/centos.sh |bash

钉钉消息

脚本只适用于Centos7/8 ,其他系统需要自定义修改脚本,实现思路一样。

0 人点赞