nginx的用户认证、https和zabbix监控

nginx的安装
zabbix的安装
ssl证书生成
环境说明

系统信息IP服务名称
rhel7.4192.168.20.99lnmp
zabbix_server
zabbix_agentd
rhel7.4192.168.20.135zabbix_agentd
nginx

1.用户认证

//创建可以访问的用户和密码
[root@localhost nginx]# htpasswd -c -m /usr/local/nginx/conf/.password admin
New password: 
Re-type new password: 
Adding password for user admin


        location /abc {
            root html;
            index  index.html;
            auth_basic "123";
            auth_basic_user_file /usr/local/nginx/conf/.password
        }

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

2.https配置

[root@localhost ssl]# pwd
/usr/local/nginx/ssl
[root@localhost ssl]# ll
总用量 8
-rw-r--r-- 1 root root 1103 8月  11 02:33 www.a.com.crt
-rw-r--r-- 1 root root 1675 8月  11 02:32 www.a.com.key

[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
106     server {
107         listen       443 ssl;
108         server_name  www.a.com;
109 
110         ssl_certificate     /usr/local/nginx/ssl/www.a.com.crt;       //证书存放路径
111         ssl_certificate_key  ../ssl/www.a.com.key;       //证书存放路径
112 
113         ssl_session_cache    shared:SSL:1m;
114         ssl_session_timeout  5m;
115 
116         ssl_ciphers  HIGH:!aNULL:!MD5;
117         ssl_prefer_server_ciphers  on;
118 
119         location / {
120             root   html;
121             index  index.html index.htm;
122         }
123     }
124 

:106,123s/#//g                        //替换106行到123的#

在这里插入图片描述
在这里插入图片描述

3.zabbix监控

3.1开启状态界面

        location /status {
            stub_status on;                       //开启
            allow 192.168.20.0/24;           //允许这个网段的可以访问
            deny all;                             //拒绝所有
        }

在这里插入图片描述
状态页面信息详解:

状态码表示的意义
Active connections 2当前所有处于打开状态的连接数
accepts总共处理了多少个连接
handled成功创建多少握手
requests总共处理了多少个请求
Readingnginx读取到客户端的Header信息数,表示正处于接收请求状态的连接数
Writingnginx返回给客户端的Header信息数,表示请求已经接收完成,且正处于处理请求或发送响应的过程中的连接数
Waiting开启keep-alive的情况下,这个值等于active - (reading + writing),意思就是Nginx已处理完正在等候下一次请求指令的驻留连接

3.2安装zabbix_agent服务

[root@localhost zabbix-5.0.2]# yum -y install gcc pcre*
[root@localhost zabbix-5.0.2]# ./configure --enable-agent
[root@localhost zabbix-5.0.2]# make install
[root@localhost zabbix-5.0.2]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost zabbix-5.0.2]# vim /usr/local/etc/zabbix_agentd.conf
Server=192.168.20.99     
ServerActive=192.168.20.99
Hostname=001

3.3添加监控脚本

//监控总共连接各数
[root@localhost ~]# mkdir /scritps
[root@localhost ~]# cd /scritps/
[root@localhost scritps]# vim requests.sh
#!/bin/bash
requests=$(curl -s http://192.168.20.135/status | awk 'NR==3{print $3}')


if [ $requests -gt 200 ];then
    echo  $requests 
else 
    echo 0
fi

[root@localhost scritps]# chmod +x requests.sh

//修改配置文件启动功能,启动功能
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf

UnsafeUserParameters=1

UserParameter=requests,/bin/bash  /scripts/requests.sh
UserParameter=Reading,/bin/bash  /scripts/Reading.sh
UserParameter=Writing,/bin/bash  /scripts/Writing.sh

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

监控正处于接收请求状态的连接数

[root@localhost scritps]# vim Reading.sh
#!/bin/bash
Reading=$(curl -s http://192.168.20.135/status | awk 'NR==4{print $2}')

if [ $Reading -gt 0 ];then
    echo $Reading 
else
    echo 0
fi

[root@localhost scritps]# chmod +x Reading.sh

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

监控已经接受请求且正在处理的或发生响应过程中的连接数

[root@localhost scritps]# vim Writing.sh
#!/bin/bash
Writing=$(curl -s http://192.168.20.135/status | awk 'NR==4{print $4}')

if [ $Writing -gt 0 ];then
    echo $Writing 
else 
    echo 0
fi

[root@localhost scritps]# chmod +x Writing.sh

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Zabbix是一个开源的网络监控工具,可以用来监控各种网络设备和服务的状态。在监控nginx运行状态方面,可以通过自定义key或使用监控模板来实现。 方法一:自定义key实现监控nginx运行状态 1. 在zabbix-agent端操作,可以使用命令"zabbix_get -s <zabbix-agent IP> -k 'nginx.status'"来获取nginx的运行状态。当nginx运行时,会显示"running",不运行时,会显示"dead"。\[1\] 2. 在zabbix-agent端操作,将监控脚本与zabbix-agent关联起来,确保监控脚本能够正确获取nginx的运行状态。\[2\] 3. 在web端创建监控项和触发器,监控项使用自定义key来获取nginx的运行状态,触发器根据需要设置相应的条件和动作。 方法二:使用监控模板监控nginx运行状态 1. 创建监控项,使用预定义的监控模板中的项来监控nginx的运行状态。 2. 创建触发器,根据监控项的数值设置相应的条件和动作。 3. 验证监控是否生效,可以使用命令"zabbix_get -s <zabbix-server IP> -k 'nginx.status\[accepts\]'"来测试监控是否正常工作。\[2\] 通过以上两种方法,可以实现对nginx运行状态的监控,并根据需要设置相应的触发器来进行告警或其他操作。 #### 引用[.reference_title] - *1* *3* [zabbix监控系统——zabbix实现对nginx运行状态的监控](https://blog.csdn.net/weixin_44178770/article/details/124706744)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [zabbix监控nginx](https://blog.csdn.net/qq_37369726/article/details/103383468)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值