栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Nginx配置文件详解(2)

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Nginx配置文件详解(2)

Nginx配置文件详解(2) 开启状态界面
[root@localhost ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --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 --add-module=../echo-nginx-module-0.61
在编译nginx的时候安装相应的软件包--with-http_gzip_static_module,然后去配置文件中添加内容,最后去浏览器中去访问即可
[root@localhost conf]# pwd
/usr/local/nginx/conf
[root@localhost conf]# vim nginx.conf
//添加一下三行内容
        location /status {   
                stub_status;
}
 ......
[root@localhost conf]# nginx -s reload

去网页查看

状态页面信息详解:

状态码表示的意义
Active connections 2当前所有处于打开状态的连接数
accepts总共处理了多少个连接
handled成功创建多少握手
requests总共处理了多少个请求
Readingnginx读取到客户端的Header信息数,表示正处于接收请求状态的连接数
Writingnginx返回给客户端的Header信息数,表示请求已经接收完成, 且正处于处理请求或发送响应的过程中的连接数
Waiting开启keep-alive的情况下,这个值等于active - (reading + writing), 意思就是Nginx已处理完正在等候下一次请求指令的驻留连接
使用zabbix监控nginx页面状态信息 在nginx服务器安装zabbix_agent客户端
下载依赖包,解压zabbix到/usr/src, 创建用户 编译安装zabbix-agent 修改配置文件
[root@localhost ]# yum -y install gcc gcc-c++ make pcre-devel openssl openssl-devel
[root@localhost src]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost src]# tar xf zabbix-5.4.4.tar.gz 
[root@localhost src]# cd zabbix-5.4.4/
[root@localhost zabbix-5.4.4]# ./configure --enable-agent
[root@localhost zabbix-5.4.4]# make install
#安装完过后在/usr/local/etc/下会有agent配置文件
[root@localhost zabbix-5.4.4]# ls /usr/local/etc/
zabbix_agentd.conf  zabbix_agentd.conf.d

[root@localhost zabbix-5.4.4]# vim /usr/local/etc/zabbix_agentd.conf
......
Server=192.168.136.131   //被动模式
ServerActive=192.168.136.131  //主动模式
Hostname=Nginx
......
关闭防火墙和selinx
[root@localhost zabbix-5.4.4]# systemctl disable firewalld
[root@localhost zabbix-5.4.4]# setenforce 0
setenforce: SELinux is disabled

[root@localhost zabbix-5.4.4]# zabbix_agentd 
[root@localhost zabbix-5.4.4]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:10050               *:*                  
LISTEN      0      128     *:80                  *:*                  
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128     *:443                 *:*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  

zabbix服务端添加主机


编写监控脚本 让zabbix监控nginx状态

reading大 很多请求在等待接受 处理能力不够
waiting 越小越好 工作饱和 只有几个人在等待,如果没有人等待表示工作不饱和很闲,实际中不会这么浪费 会近可能的给机器安排工作。

[root@localhost ~]# mkdir /scripts
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# ls
[root@localhost scripts]# curl http://192.168.136.250/status
Active connections: 1 
server accepts handled requests
 3 3 3 
Reading: 0 Writing: 1 Waiting: 0 

[root@localhost scripts]# vim writing.sh
[root@localhost scripts]# vim waiting.sh 
[root@localhost scripts]# vim reading.sh 
[root@localhost scripts]# cat reading.sh 
#/bin/bash

Reading=$(curl  -s http://192.168.136.250/status | awk 'NR==4{print $2}')
if [ $Reading -gt 80 ];then
        echo "1"
else
        echo "0"
fi
[root@localhost scripts]# cat writing.sh 
#/bin/bash
writing=$(curl  -s http://192.168.136.250/status | awk 'NR==4{print $4}')
if [ $writing -gt 50 ];then
        echo "1"
else
        echo "0"
fi
[root@localhost scripts]# cat waiting.sh 
#/bin/bash
waiting=$(curl  -s http://192.168.136.250/status | awk 'NR==4{print $6}')
if [ $waiting -gt 30 ];then
        echo "1"
else
        echo "0"
fi
[root@localhost scripts]# 

修改zabbix_agentd.conf文件

[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
......
UnsafeUserParameters=1
......
# 配置文件最后面添加一下内容
UserParameter=check_reading,/scripts/reading.sh   
UserParameter=check_waiting,/scripts/waiting.sh
UserParameter=check_writing,/scripts/writing.sh

重启zabbix-agentd 验证

[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd 
[root@localhost ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128     *:10050               *:*                  
LISTEN      0      128     *:80                  *:*                  
LISTEN      0      128     *:22                  *:*                  
LISTEN      0      100    127.0.0.1:25                  *:*                  
LISTEN      0      128     *:443                 *:*                  
LISTEN      0      128    :::22                 :::*                  
LISTEN      0      100       ::1:25                 :::*                  
[root@localhost ~]# chmod 755 /scripts/
[root@localhost scripts]# chmod +x reading.sh waiting.sh writing.sh 

[root@localhost ~]# zabbix_get -s 192.168.136.250 -k check_reading
0

本文只演示一个监控,其他两个配置与这个配置相同

添加监控项

添加触发器


验证

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/361606.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号