天天看点

Zabbix 监控获取apache_status

以下操作均在zabbix-agent端操作:

  • 初始化(执行脚本)
sh init.sh           
  • httpd的安装与启动(二进制)
yum install -y httpd*  #安装httpd           
systemctl  start httpd.service;systemctl  enable httpd.service #服务的启动与开机自启            
ss -ant |grep :80 #查看httpd的80是否起来
LISTEN     0      128          *:10050                    *:*                   users:(("zabbix_agentd",pid=16735,fd=4),("zabbix_agentd",pid=16734,fd=4),("zabbix_agentd",pid=16733,fd=4),("zabbix_agentd",pid=16732,fd=4),("zabbix_agentd",pid=16731,fd=4),("zabbix_agentd",pid=16730,fd=4))
LISTEN     0      128         :::10050                   :::*                   users:(("zabbix_agentd",pid=16735,fd=5),("zabbix_agentd",pid=16734,fd=5),("zabbix_agentd",pid=16733,fd=5),("zabbix_agentd",pid=16732,fd=5),("zabbix_agentd",pid=16731,fd=5),("zabbix_agentd",pid=16730,fd=5))           
在/etc/httpd/conf/httpd.conf的末尾加上如下代码
ExtendedStatus On
<location /server-status>
   SetHandler server-status
   Order Allow,Deny
   Allow from all
</location>           
systemctl restart httpd.service #修改配置文件之后重启服务           
#执行下方命令看是否status是否配置成功
/usr/bin/curl --insecure --silent --location http://localhost/server-status?auto 
Total Accesses: 146
Total kBytes: 97
Uptime: 226
ReqPerSec: .646018
BytesPerSec: 439.504
BytesPerReq: 680.329
BusyWorkers: 1
IdleWorkers: 5
Scoreboard: _W____..........................................................................................................................................................................................................................................................           
  • 部署zabbix-agent端
    1. 一键部署
    2. 分步部署:

      -配置zabbix-repo

rpm -Uvh https://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm           

-安装agent端软件

yum install zabbix-agent           

-修改配置启动agent端服务

vim /etc/zabbix/zabbix_agentd.conf
Server=192.168.122.105           //被动模式 zabbix-server-ip
ServerActive=192.168.122.105    //主动模式  zabbix-server-ip
Hostname=Zabbix server         //Agent端主机名,最终显示在监控页面上的名字
UnsafeUserParameters=1        //是否限制用户自定义keys使用特殊字符           

-服务的启动与开机自启动

systemctl start zabbix-agent           
netstat -antp | grep agent
LISTEN     0      128          *:10050                    *:*                   users:(("zabbix_agentd",pid=16735,fd=4),("zabbix_agentd",pid=16734,fd=4),("zabbix_agentd",pid=16733,fd=4),("zabbix_agentd",pid=16732,fd=4),("zabbix_agentd",pid=16731,fd=4),("zabbix_agentd",pid=16730,fd=4))
LISTEN     0      128         :::10050                   :::*                   users:(("zabbix_agentd",pid=16735,fd=5),("zabbix_agentd",pid=16734,fd=5),("zabbix_agentd",pid=16733,fd=5),("zabbix_agentd",pid=16732,fd=5),("zabbix_agentd",pid=16731,fd=5),("zabbix_agentd",pid=16730,fd=5))           

-配置snmp

yum -y install net-snmp net-snmp-utils           
vim /etc/snmp/snmpd.conf 
com2sec notConfigUser  192.168.122.105    public  
access  notConfigGroup ""  any  noauth  exact  all none none
view all    included  .1    80           
systemctl  start snmpd;systemctl  enable snmpd           
ss -anup |grep snmp
UNCONN     0      0            *:161                      *:*                   users:(("snmpd",pid=4315,fd=6))           
  • 准备获取status的脚本(脚本内容:
cd /etc/zabbix
mkdir scripts
touch apache_status.sh
chomd +x apache_status.sh           

把脚本执行一边,检查脚本看是否能够正常获取到数值。

sh apache_status.sh TotalAccesses
37552           
  • 自定义key
cd /etc/zabbix/zabbix_agentd.d
touch apache_status.conf
cat apache_status.conf
UserParameter=apache.status[*],/etc/zabbix/scripts/apache_status.sh $1           
  • 在zabbix上添加监控项
    Zabbix 监控获取apache_status
Zabbix 监控获取apache_status
Zabbix 监控获取apache_status
Zabbix 监控获取apache_status

创建完主机之后先查看一下主机的状态,为绿色就正常,为红色或者灰色则需要排查问题。

Zabbix 监控获取apache_status
Zabbix 监控获取apache_status
Zabbix 监控获取apache_status
Zabbix 监控获取apache_status
Zabbix 监控获取apache_status
Zabbix 监控获取apache_status

根据上图添加脚本里获取的所有的值为监控项

Zabbix 监控获取apache_status

查看状态是否为已启用的状态,不是则需要排查。

Zabbix 监控获取apache_status
Zabbix 监控获取apache_status

如果有最新数据,监控项则配置成功。

Zabbix 监控获取apache_status

根据业务情况配置触发器等。