本文共 3743 字,大约阅读时间需要 12 分钟。
服务端 | 客户端 | |
---|---|---|
主机名 | C1 | C2 |
ip | 192.168.10.11 | 192.168.10.15 |
[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
[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
[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
[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
[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
[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
剩下的就不演示了,就是改个 参数
可以看到状态,把剩下的都分别加进去
这样就可以实时监控数据
或者直接把7个数据画到一张图里,用不同颜色的线来显示
转载地址:http://fplwb.baihongyu.com/