侧边栏壁纸
博主头像
zyixin

当你觉得为时已晚的时候,恰恰是最早的时候

  • 累计撰写 64 篇文章
  • 累计创建 0 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

监控案例

zyixin
2022-04-01 / 0 评论 / 0 点赞 / 1,771 阅读 / 2,720 字
温馨提示:
本文最后更新于 2022-04-01,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

5 监控案例

—在客户端编写监控脚本,给监控服务器调用

** 环境准备 **
· 一台Nginx服务器(192.168.139.200),部署Nginx时要加载status模块,因为192.168.139.200服务器是自动发现的,没有zabbix_agent的包,所以需要安装一下
-安装zabbix_agent

[root@agent-2 ~]# yum -y install gc pcre-devel
[root@agent-2 ~]# cd /home/setup
[root@agent-2 setup]# tar -zxvf zabbix-3.4.15.tar.gz
[root@agent-2 setup]# cd zabbix-3.4.15
[root@agent-2 zabbix-3.4.15]# configure --enable-agent
[root@agent-2 zabbix-3.4.15]# make install

[root@agent-2 ~]# vim /usr/local/etc/zabbix_agentd.conf
Server=127.0.0.1,192.168.139.15
ServerActive=192.168.139.15:10051
Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1

[root@agent-2 ~]# useradd zabbix
[root@agent-2 ~]# zabbix_agentd
[root@agent-2 ~]# netstat -utnlp |grep :10050
tcp        0      0 0.0.0.0:10050           0.0.0.0:*               LISTEN      43022/zabbix_agentd

-安装nginx

[root@agent-2 ~]# cd /home/setup
[root@agent-2 ~]# yum -y install zlib-devel
[root@agent-2 setup]# scp root@192.168.139.15:/home/setup/nginx-1.19.1.tar.gz ./
[root@agent-2 setup]# tar -zxvf nginx-1.19.1.tar.gz
[root@agent-2 setup]# cd nginx-1.19.1
[root@agent-2 nginx-1.19.1]# ./configure --with-http_stub_status_module
[root@agent-2 nginx-1.19.1]# make && make install
[root@agent-2 nginx-1.19.1]# ls /usr/local/nginx/
conf  html  logs  sbin

-配置nginx

[root@agent-2 ~]# vim /usr/local/nginx/conf/nginx.conf
··· ···
server {
        location /status {
                stub_status on;
        }
		
··· ···

[root@agent-2 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@agent-2 ~]# /usr/local/nginx/sbin/nginx
[root@agent-2 ~]# netstat -utnlp | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      46031/nginx: master


[root@agent-2 ~]# curl http://localhost/status
Active connections: 1 
server accepts handled requests
 7 7 1 
Reading: 0 Writing: 1 Waiting: 0 

5.1 监控nginx服务状态

** 编写监控脚本 **

[root@agent-2 ~]# vim /usr/local/bin/nginx_status.sh
#!/bin/bash

case $1 in
"Active")
curl -s http://localhost/status | awk 'NR==1{print $3}';;
"accepts")
curl -s http://localhost/status | awk 'NR==3{print $1}';;
"Waiting")
curl -s http://localhost/status | awk 'NR==4{print $6}'
esac

[root@agent-2 ~]# chmod +x /usr/local/bin/nginx_status.sh
[root@agent-2 ~]# /usr/local/bin/nginx_status.sh Waiting
[root@agent-2 ~]# /usr/local/bin/nginx_status.sh Active
[root@agent-2 ~]# /usr/local/bin/nginx_status.sh accepts

** 把脚本定义成监控命令 **

[root@agent-2 ~]# vim /usr/local/etc/zabbix_agentd.conf.d/x.conf
UserParameter=nginx_statu[*],/usr/local/bin/nginx_status.sh $1

[root@agent-2 ~]# killall -9 zabbix_agentd
[root@agent-2 ~]# killall -9 zabbix_agentd
zabbix_agentd: no process found
[root@agent-2 ~]# zabbix_agentd

** 测试定义的监控命令 **

[root@agent-2 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k nginx_statu[Waiting]
[root@agent-2 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k nginx_statu[Active]
[root@agent-2 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k nginx_statu[accepts]

5.2 监控网络连接状态

5.3 扩展

0

评论区