随笔 - 911  文章 - 5  评论 - 94  阅读 - 243万

CentOS安装并配置Zabbix Agent

 

复制代码
#/bin/bash
#Setup zabbix agent.
#configure zabbix_agent.conf.

#Check zabbix agent process,and install zabbix agent.
zabbix_num=`ps -ef |grep 'zabbix_agentd: listener' |grep -v grep |wc -l`
if [ $zabbix_num -gt 1 ];then
  echo 'zabbix agent setup successed'
  exit
else
  yum -y -q install zabbix-agent
fi


#Get host ip,used for zabbix agent hostname.
ip=`ip a |grep -E '255 scope global eth0|255 scope global noprefixroute eth0' |awk -F ' ' '{print $2}'|awk -F '/' '{print $1}' |awk 'NR==1{print}'`
zabbix_agent_name="DevTest_"$ip
#echo $zabbix_agent_name
zabbix_agent_name_g=`echo $zabbix_agent_name |grep '\.' |wc -l`
if [ $zabbix_agent_name_g -ne 1 ];then
  echo 'zabbix agent setup failed,cannot set zabbix agent host name.'
  exit
fi

#Configure zabbix_agent.conf.
sed -i '115{s/127.0.0.1/zabbixproxy.xx.com/}'  /etc/zabbix_agentd.conf
sed -i '169{s/127.0.0.1/zabbixproxyi.xx.com/}'  /etc/zabbix_agentd.conf
sed -i "180{s/Zabbix server/$zabbix_agent_name/}" /etc/zabbix_agentd.conf

#Check Zabbix_agent.conf.
zbx_server_g=`grep 'zabbixproxy' /etc/zabbix_agentd.conf |wc -l`
zbx_server_g2=`grep "$zabbix_agent_name" /etc/zabbix_agentd.conf |wc -l`
if [ $zbx_server_g -ne 2 -o $zbx_server_g2 -ne 1 ];then
  echo 'zabbix agent setup failed,configure zabbix_agent.conf failed.'
  exit
fi


sleep 1
systemctl restart zabbix-agent
sleep 1

#Check zabbix agent service status.
zabbix_status=`systemctl is-active zabbix-agent`
if [ $zabbix_status == "active" ];then
  echo "zabbix agent setup successed"
else
  echo "zabbix agent setup failed"
fi
复制代码

 

posted on   momingliu11  阅读(212)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2019-12-13 编辑修改json文件(PSCustomObject)
2013-12-13 Windows命令大全
2013-12-13 Klist
2013-12-13 Nltest
2013-12-13 HTML输出 二 控制行背景颜色
2013-12-13 创建虚拟交换机(New-VMSwitch)
2012-12-13 JavaScript消息框应用
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示