博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用zabbix监控nginx
阅读量:2156 次
发布时间:2019-05-01

本文共 3743 字,大约阅读时间需要 12 分钟。

用zabbix监控nginx

实验环境

服务端 客户端
主机名 C1 C2
ip 192.168.10.11 192.168.10.15

部署zabbix

在客户端部署nginx

创建nginx系统用户

[root@C2 ~]# useradd -r -M -s /sbin/nologin nginx

安装依赖环境

[root@C2 ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ wget make[root@C2 ~]# yum -y groups mark install 'Development Tools'

创建日志存放目录

[root@C2 ~]# mkdir -p /var/log/nginx[root@C2 ~]# chown -R nginx.nginx /var/log/nginx

下载nginx

[root@C2 ~]# wget https://nginx.org/download/nginx-1.20.1.tar.gz

编译安装

[root@C2 ~]# tar xf nginx-1.20.1.tar.gz[root@C2 ~]# cd nginx-1.20.1/[root@C2 nginx-1.20.1]# ./configure \--prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-debug \--with-http_ssl_module \--with-http_realip_module \--with-http_image_filter_module \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_stub_status_module \--http-log-path=/var/log/nginx/access.log \--error-log-path=/var/log/nginx/error.log[root@C2 nginx-1.20.1]# make && make install

配置环境变量

[root@C2 nginx-1.20.1]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh[root@C2 nginx-1.20.1]# . /etc/profile.d/nginx.sh

启动

[root@C2 ~]# nginx[root@C2 ~]# ss -antlState         Recv-Q        Send-Q               Local Address:Port                Peer Address:Port       Process       LISTEN        0             128                        0.0.0.0:10050                    0.0.0.0:*                        LISTEN        0             128                        0.0.0.0:80                       0.0.0.0:*                        LISTEN        0             128                        0.0.0.0:22                       0.0.0.0:*                        LISTEN        0             80                               *:3306                           *:*                        LISTEN        0             128                           [::]:22                          [::]:*    [root@C2 ~]# systemctl restart firewalld.service [root@C2 ~]# setenforce 0

配置nginx

[root@C2 ~]# vim /usr/local/nginx/conf/nginx.conf        location /nginx_status {            stub_status on;            access_log off;            allow 127.0.0.1;            allow 192.168.10.1;            deny all;        }[root@C2 ~]# nginx -s reload

image-20210626155101981

编写脚本

[root@C2 ~]# mkdir /scripts[root@C2 ~]# vim /scripts/check_nginx.sh#!/bin/bash#Script to fetch nginx statuses for monitoring systems HOST="127.0.0.1"PORT="80" function ping {    /sbin/pidof nginx | wc -l} function active {    /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'}function reading {    /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'}function writing {    /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'}function waiting {    /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'}function accepts {    /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}'}function handled {    /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}'}function requests {    /usr/bin/curl "http://$HOST:$PORT/nginx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}'}$1[root@C2 ~]# chmod +x /scripts/check_nginx.sh

zabbix-agent配置文件开启自定义功能

[root@C2 ~]# vim /usr/local/etc/zabbix_agentd.confUnsafeUserParameters=1   #取消注释并改为1在最后的空白处添加UserParameter=check_nginx[*],/bin/bash /scripts/check_nginx.sh $1[root@C2 ~]# pkill zabbix[root@C2 ~]# zabbix_agentd

测试server端是否可以收到数据

[root@C1 etc]# zabbix_get -s 192.168.10.15 -p 10050 -k check_nginx[accepts]9[root@C1 etc]# zabbix_get -s 192.168.10.15 -k check_nginx[active]1

在web上配置

image-20210626162625498

image-20210626162650668

image-20210626162701157

image-20210626162720240

image-20210626162939308

image-20210626163030270

剩下的就不演示了,就是改个 参数

image-20210626163303219

image-20210626163323155

image-20210626163458895

image-20210626163556357

image-20210626163733973

image-20210626163821941

可以看到状态,把剩下的都分别加进去

image-20210626164436270

image-20210626164502318

image-20210626164715314

这样就可以实时监控数据

或者直接把7个数据画到一张图里,用不同颜色的线来显示

转载地址:http://fplwb.baihongyu.com/

你可能感兴趣的文章
Java Guava中的函数式编程讲解
查看>>
Eclipse Memory Analyzer 使用技巧
查看>>
tomcat连接超时
查看>>
谈谈编程思想
查看>>
iOS MapKit导航及地理转码辅助类
查看>>
检测iOS的网络可用性并打开网络设置
查看>>
简单封装FMDB操作sqlite的模板
查看>>
iOS开发中Instruments的用法
查看>>
iOS常用宏定义
查看>>
什么是ActiveRecord
查看>>
有道词典for mac在Mac OS X 10.9不能取词
查看>>
关于“团队建设”的反思
查看>>
利用jekyll在github中搭建博客
查看>>
Windows7中IIS简单安装与配置(详细图解)
查看>>
linux基本命令
查看>>
BlockQueue 生产消费 不需要判断阻塞唤醒条件
查看>>
强引用 软引用 弱引用 虚引用
查看>>
数据类型 java转换
查看>>
"NetworkError: 400 Bad Request - http://172.16.47.117:8088/rhip/**/####t/approval?date=976
查看>>
mybatis 根据 数据库表 自动生成 实体
查看>>