首页 > 其他分享 >脚本之一键安装zabbix-agent被监控端

脚本之一键安装zabbix-agent被监控端

时间:2022-10-08 23:31:11浏览次数:51  
标签:VER SETCOLOR color zabbix agent echo ZABBIX 监控

1、安装zabbix-agent2脚本
ZABBIX_SERVER=zabbix.wang.org
ZABBIX_VER=5.0
URL="https://mirror.tuna.tsinghua.edu.cn/zabbix"

. /etc/os-release


color () {
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \E[0m"
echo -n "$1" && $MOVE_TO_COL
echo -n "["
if [ $2 = "success" -o $2 = "0" ] ;then
${SETCOLOR_SUCCESS}
echo -n $" OK "
elif [ $2 = "failure" -o $2 = "1" ] ;then
${SETCOLOR_FAILURE}
echo -n $"FAILED"
else
${SETCOLOR_WARNING}
echo -n $"WARNING"
fi
${SETCOLOR_NORMAL}
echo -n "]"
echo
}

install_zabbix_agent2() {
if [ $ID = "centos" -o $ID = "rocky" ];then
VERSION_ID=`echo $VERSION_ID|awk -F. '{print $1}'`
rpm -Uvh $URL/zabbix/${ZABBIX_VER}/rhel/${VERSION_ID}/x86_64/zabbix-release-${ZABBIX_VER}-1.el${VERSION_ID}.noarch.rpm
if [ $? -eq 0 ];then
color "YUM仓库准备完成" 0
else
color "YUM仓库配置失败,退出" 1
exit
fi
sed -i "s#http://repo.zabbix.com#$URL#" /etc/yum.repos.d/zabbix.repo
yum -y install zabbix-agent2
else
wget $URL/zabbix/${ZABBIX_VER}/ubuntu/pool/main/z/zabbix-release/zabbix-release_${ZABBIX_VER}-1+${UBUNTU_CODENAME}_all.deb
if [ $? -eq 0 ];then
color "APT仓库准备完成" 0
else
color "APT仓库配置失败,退出" 1
exit
fi
dpkg -i zabbix-release_${ZABBIX_VER}-1+${UBUNTU_CODENAME}_all.deb
sed -i "s#http://repo.zabbix.com#$URL#" /etc/apt/sources.list.d/zabbix.list
apt update
apt -y install zabbix-agent2
fi
}

config_zabbix_agent2 (){
sed -i -e "/^Server=127.0.0.1/c Server=$ZABBIX_SERVER" -e "/^Hostname=Zabbix server/c Hostname=`hostname -I`" /etc/zabbix/zabbix_agent2.conf
}

start_zabbix_agent2 () {
systemctl enable zabbix-agent2.service
systemctl restart zabbix-agent2.service
systemctl is-active zabbix-agent2.service
if [ $? -eq 0 ];then
echo "-------------------------------------------------------------------"
color "Zabbix Agent 安装完成!" 0
else
color "Zabbix Agent 安装失败" 1
exit
fi
}

install_zabbix_agent2
config_zabbix_agent2
start_zabbix_agent2
2、安装zabbix-agent脚本
ZABBIX_SERVER=zabbix.wang.org
ZABBIX_VER=5.0
URL="https://mirror.tuna.tsinghua.edu.cn/zabbix"

. /etc/os-release


color () {
RES_COL=60
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \E[0m"
echo -n "$1" && $MOVE_TO_COL
echo -n "["
if [ $2 = "success" -o $2 = "0" ] ;then
${SETCOLOR_SUCCESS}
echo -n $" OK "
elif [ $2 = "failure" -o $2 = "1" ] ;then
${SETCOLOR_FAILURE}
echo -n $"FAILED"
else
${SETCOLOR_WARNING}
echo -n $"WARNING"
fi
${SETCOLOR_NORMAL}
echo -n "]"
echo
}

install_zabbix_agent() {
if [ $ID = "centos" -o $ID = "rocky" ];then
VERSION_ID=`echo $VERSION_ID|awk -F. '{print $1}'`
rpm -Uvh $URL/zabbix/${ZABBIX_VER}/rhel/${VERSION_ID}/x86_64/zabbix-release-${ZABBIX_VER}-1.el${VERSION_ID}.noarch.rpm
if [ $? -eq 0 ];then
color "YUM仓库准备完成" 0
else
color "YUM仓库配置失败,退出" 1
exit
fi
sed -i "s#http://repo.zabbix.com#$URL#" /etc/yum.repos.d/zabbix.repo
yum -y install zabbix-agent
else
wget $URL/zabbix/${ZABBIX_VER}/ubuntu/pool/main/z/zabbix-release/zabbix-release_${ZABBIX_VER}-1+${UBUNTU_CODENAME}_all.deb
if [ $? -eq 0 ];then
color "APT仓库准备完成" 0
else
color "APT仓库配置失败,退出" 1
exit
fi
dpkg -i zabbix-release_${ZABBIX_VER}-1+bionic_all.deb
sed -i "s#http://repo.zabbix.com#$URL#" /etc/apt/sources.list.d/zabbix.list
apt update
apt -y install zabbix-agent
fi
}

config_zabbix_agent (){
sed -i -e "/^Server=127.0.0.1/c Server=$ZABBIX_SERVER" -e "/^Hostname=Zabbix server/c Hostname=`hostname -I`" /etc/zabbix/zabbix_agentd.conf
}

start_zabbix_agent () {
systemctl enable zabbix-agent.service
systemctl restart zabbix-agent.service
systemctl is-active zabbix-agent.service
if [ $? -eq 0 ];then
echo "-------------------------------------------------------------------"
color "Zabbix Agent 安装完成!" 0
else
color "Zabbix Agent 安装失败" 1
exit
fi
}

install_zabbix_agent
config_zabbix_agent
start_zabbix_agent

标签:VER,SETCOLOR,color,zabbix,agent,echo,ZABBIX,监控
From: https://blog.51cto.com/dayu/5738789

相关文章

  • RabbitMQ 集群迁移与监控
    一、集群迁移RabbitMQ中的集群迁移更多的是用来解决集群故障不可短时间内修复而将所有的数据、客户端连接等迁移到新的集群中,以确保服务的可用性。迁移过程包括元数......
  • 泛在电力物联网下的远程抄表和设备监控维护
    随着工业化自动化的发展,物联网技术取得了蓬勃的发展。在电力能源领域,受到广泛的应用与关注,资料显示,国家电网系统接入的终端设备超过5亿只(其中4.5亿只电表,各类保护、采集、......
  • ZABBIX警告常见问题集锦
    一、磁盘1、告警:Diskread/writerequestresponsesaretoohigh表达式解释为:最近15分钟的对应磁盘的Diskreadrequestavgwaitingtime(r_await)大于20m......
  • Grafana监控java应用以及vCenter的方法
    Grafana监控java应用以及vCenter的方法背景最开始弄过vCenter的监控.但是发现很多地方已经不合适了.今天看了下jmx监控java的应用.顺便监控了下vCenter.这里简单记录一下,......
  • vCenter 6.7 使用Grafana监控失败的处理
    背景国庆处理的vCenter监控.老的vCenter6.0的平台很正常.但是新的vCenter6.7就经常出现断连的情况.花费了快一个多小时才搞定,这里记录一下.问题现象vCenter......
  • zabbix 自定义监控项
    1.zabbix_agent端配置[root@k8s1~]#egrep-v"^$|^#"/usr/local/zabbix/etc/zabbix_agentd.confLogFile=/tmp/zabbix_agentd.logServer=x.x.x.x #zabbixserver端i......
  • WGCLOUD监控平台可以实现哪些指标的可视化管理
    WGCLOUD是一个优秀的开源项目,主要用于自动化运维管理工作,减轻我们的工作复杂度,更具备灵活的告警机制WGCLOUD可以监测实体机、虚拟机、云主机等等,也可以PING监测各种网络设......
  • Java Agent到内存马(一)
    目录关于JavaAgent介绍使用方式premainagentmain方式参考关于JavaAgent介绍在jdk1.5之后引入了java.lang.instrument包,该包提供了检测java程序的Api,比如用于......
  • 如何引入阿里云ARMS前端监控?
    老大对我目前手上的项目引入了阿里云ARMS前端监控,但是我自己对ARMSSDK的API以及如何注入到Vue中不是很懂,因此这篇博客诞生了。/***阿里前端监控*配置文档https://www.......
  • Skywalking光会用可不行,必须的源码分析分析 - Skywalking Agent &插件解析
    3Skywalking源码导入接上文,已经学习了Skywalking的应用,接下来我们将剖析Skywalking源码,深度学习SkywalkingAgent。3.1源码环境搭建当前最新版本是8.3.0,我们首先找到8.3.......