nginx平滑升级(添加echo功能)配置和状态监控

2023-05-16

(添加echo模块)配置

1.先去github或者gitee中找到nginx_module_echo-master.zip包
2.将原来的ngin-1.20.1删除,重新编译安装

[root@host src]# ls
debug  kernels  nginx-1.20.1.tar.gz  wujunze-nginx_module_echo-master.zip
[root@host src]# yum -y install unzip
[root@host src]# unzip wujunze-nginx_module_echo-master.zip 
Archive:  wujunze-nginx_module_echo-master.zip
cc5135fd7a7c87ccac48fd05509396443c71c065
   creating: nginx_module_echo/
 extracting: nginx_module_echo/.gitignore  
  inflating: nginx_module_echo/LICENSE  
  inflating: nginx_module_echo/README.md  
  inflating: nginx_module_echo/README_zh.md  
  inflating: nginx_module_echo/config  
   creating: nginx_module_echo/src/
  inflating: nginx_module_echo/src/ngx_http_echo_module.c  
[root@host src]# tar xf nginx-1.20.1.tar.gz   
[root@host src]# ls
debug  kernels  nginx-1.20.1  nginx-1.20.1.tar.gz  nginx_module_echo  wujunze-nginx_module_echo-master.zip
  • 查看之前的安装配置
[root@host ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-2) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
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
  • 开始编译安装
[root@host 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 --add-module=../nginx_module_echo

可以发现现在多了一个objs目录
[root@host nginx-1.20.1]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@host nginx-1.20.1]# make

[root@host nginx-1.20.1]# ls objs/
addon  autoconf.err  Makefile  ngx_auto_config.h  ngx_auto_headers.h  ngx_modules.c  src
[root@host nginx-1.20.1]# ls objs/
addon         Makefile  nginx.8            ngx_auto_headers.h  ngx_modules.o
autoconf.err  nginx     ngx_auto_config.h  ngx_modules.c       src

替换nginx文件
[root@host nginx-1.20.1]# pkill nginx;\cp objs/nginx /usr/local/nginx/sbin/;nginx 
[root@host nginx-1.20.1]# nginx -V
nginx version: nginx/1.20.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-2) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
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=../nginx_module_echo

location应用

修饰符功能
=精确匹配
~正则表达式模式匹配,区分大小写
~*正则表达式模式匹配,不区分大小写
^~前缀匹配,类似于无修饰符的行为,也是以指定模块开始,不同的是,如果模式匹配,那么就停止搜索其他模式了,不支持正则表达式
@定义命名location区段,这些区段客户端不能访问,只可以由内部产生的请求来访问,如try_files或error_page等
  • ( location = 路径 ) --> ( location ^~ 路径 ) --> ( location ~ 正则 ) --> ( location ~* 正则 ) --> ( location 路径 )
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location /abc {
            echo "hehe";
        }
        #error_page  404              /404.html;
......
用windows的cmd查看

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

精确查找
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location = /abc {
            echo "hehe";
        }
......

在这里插入图片描述

正则表达式模式匹配,区分大小写
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location ~ /abc {
            echo "hehe";
        }
......

在这里插入图片描述

正则表达式模式匹配,不区分大小写
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location ~* /abc {
            echo "xx";
        }
......        

在这里插入图片描述

前缀匹配 (+上$表示匹配的项以$前面的为结尾)
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location ~ ^/abc$ {
            echo "bb";
        }
......

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

访问控制

禁用一定要在运行前面,否则无效
这里只是禁用这个ip不能去访问主页但是其它的还是可以访问的
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location / {
            deny   192.168.149.143;
            allow  192.168.149.0/24;
            root   html;
            index  index.html index.htm;
        }
......   
[root@host ~]# nginx -s reload
[root@host ~]# curl http://192.168.149.143
<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.20.1</center>
</body>
</html>

[root@host ~]# curl http://192.168.149.143/abc
bb     

用户认证

安装apache的工具包
[root@host ~]# yum -y install httpd-tools
[root@host ~]# which htpasswd
/usr/bin/htpasswd
[root@host ~]# htpasswd -c -m /usr/local/nginx/conf/.auth_pass xx   (这里的xx用户是不存在的虚拟的)
New password: 
Re-type new password: 
Adding password for user xx

[root@host ~]# cat  /usr/local/nginx/conf/.auth_pass 
xx:$apr1$qB8xdQeD$FEwzzuJXpT6vutlvaKmKs1
(忘记密码时可以用命令重新生成)

[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location / {
            auth_basic "yh";   这个只是注释
            auth_basic_user_file /usr/local/nginx/conf/.auth_pass;  写入存放文件路径
            root   html;
            index  index.html index.htm;
        }
......
[root@host ~]# nginx -s reload        

在这里插入图片描述
输入密码或用户名错误时
在这里插入图片描述

https配置

CA生成一对密钥
[root@host ~]# mkdir /etc/pki/CA
[root@host ~]# cd /etc/pki/CA/
[root@host CA]#  mkdir private
[root@host CA]# umask 077;openssl genrsa -out private/cakey.pem 2048
Generating RSA private key, 2048 bit long modulus (2 primes)
...........................................................................................................................................+++++
.........................+++++
e is 65537 (0x010001)

CA生成自签署证书
[root@host CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 365
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HB
Locality Name (eg, city) [Default City]:WU
Organization Name (eg, company) [Default Company Ltd]:xialuo
Organizational Unit Name (eg, section) []:xialuo
Common Name (eg, your name or your server's hostname) []:xialuo.example.com
Email Address []:1@1.com

生成密钥
[root@host CA]# mkdir certs newcerts crl
[root@host CA]# touch index.txt && echo 01 > serial
创一个存放密钥的目录
[root@host ~]# cd /usr/local/nginx/
[root@host nginx]# ls
client_body_temp  conf  fastcgi_temp  html  logs  proxy_temp  sbin  scgi_temp  uwsgi_temp
[root@host nginx]# mkdir ssl
[root@host ssl]# (umask 077;openssl genrsa -out nginx.key 2048)
Generating RSA private key, 2048 bit long modulus (2 primes)
.......+++++
...................................+++++
e is 65537 (0x010001)

客户端生成证书签署请求
[root@host ssl]# openssl req -new -key nginx.key -days 365 -out nginx.csr
Ignoring -days; not generating a certificate
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:HB
Locality Name (eg, city) [Default City]:WH
Organization Name (eg, company) [Default Company Ltd]:xialuo
Organizational Unit Name (eg, section) []:xialuo
Common Name (eg, your name or your server's hostname) []:xialuo.example.com
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

CA签署客户端提交上来的证书
[root@host ssl]# openssl ca -in nginx.csr -out nginx.crt -days 365
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches the signature
Signature ok
Certificate Details:
        Serial Number: 1 (0x1)
        Validity
            Not Before: Jun 26 09:42:34 2021 GMT
            Not After : Jun 26 09:42:34 2022 GMT
        Subject:
            countryName               = CN
            stateOrProvinceName       = HB
            organizationName          = xialuo
            organizationalUnitName    = xialuo
            commonName                = xialuo.example.com
        X509v3 extensions:
            X509v3 Basic Constraints: 
                CA:FALSE
            Netscape Comment: 
                OpenSSL Generated Certificate
            X509v3 Subject Key Identifier: 
                C7:A8:24:25:FE:BC:26:A8:8B:7A:DC:17:3A:74:26:EF:10:CC:1C:67
            X509v3 Authority Key Identifier: 
                keyid:B1:2C:84:A3:82:50:F6:87:F4:C7:1B:B1:60:2C:DF:3D:16:79:7D:6C

Certificate is to be certified until Jun 26 09:42:34 2022 GMT (365 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

[root@host ssl]# ls
nginx.crt  nginx.csr  nginx.key

[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
108     server {
109         listen       443 ssl;
110         server_name  xialuo.example.com;
111 
112         ssl_certificate      /usr/local/nginx/ssl/nginx.crt;
113         ssl_certificate_key  /usr/local/nginx/ssl/nginx.key;
114         
115         ssl_session_cache    shared:SSL:1m;
116         ssl_session_timeout  5m;
117         
118         ssl_ciphers  HIGH:!aNULL:!MD5;
119         ssl_prefer_server_ciphers  on;
120         
121         location / {
122             root   html;
123             index  index.html index.htm;
124         }   
125     }   
126     
127 }

[root@host ~]# nginx -s reload
[root@host ~]# ss -antl
State        Recv-Q       Send-Q             Local Address:Port              Peer Address:Port       Process       
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            128                      0.0.0.0:443                    0.0.0.0:*                        
LISTEN       0            128                         [::]:22                        [::]:*  

在这里插入图片描述

zabbix监控nginx状态页面

开启状态页面
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location /status {
            stub_status on;
        }
......
[root@host ~]# nginx -s reload 

在这里插入图片描述

状态设置
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location /status {
            stub_status on;
            allow 192.168.149.1/32;
            deny all;
        }
......
[root@host ~]# nginx -s reload        

在这里插入图片描述

  • 状态信息描述
状态码表示的意义
Active connections当前所有处于打开状态的连接数
accepts总共处理了多少个连接
handled成功创建多少握手
requests总共处理了多少个请求
Readingnginx读取到客户端的Header信息数,表示正处于接收请求状态的连接数
Writingnginx返回给客户端的Header信息数,表示请求已经接收完成,
且正处于处理请求或发送响应的过程中的连接数
Waiting开启keep-alive的情况下,这个值等于active - (reading + writing),
意思就是Nginx已处理完正在等候下一次请求指令的驻留连接
zabbix_server192.168.149.133
zabbix_agentd192.168.149.143
  • 编写脚本
[root@host ~]# mkdir /scripts
[root@host ~]# vim /scripts/check_status.sh
#!/bin/bash
  
HOST="192.168.149.143"
PORT="80"

function ping {
    /sbin/pidof nginx | wc -l
}
function active { 
    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
    /usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
$1

开启自定义
[root@host ~]#  vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=check_status[*],/bin/bash /scripts/check_status.sh $1

服务端测试:
[root@host ~]# zabbix_get -s 192.168.149.143 -p 10050 -k check_status[active]
1
  • 添加监控主机
    在这里插入图片描述

  • 创建监控项
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 添加监控图像
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    依次添加…

  • 屏幕
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 一次添加或者组合起来分别用不同的线表示
    在这里插入图片描述

  • 全选然后创建图像
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

nginx平滑升级(添加echo功能)配置和状态监控 的相关文章

随机推荐

  • MindSpore实现手写数字识别代码

    MindSpore是华为自研的一套AI框架 xff0c 最佳匹配昇腾处理器 xff0c 最大程度地发挥硬件能力 作为AI入门的LeNet手写字体识别网络 xff0c 网络大小和数据集都不大 xff0c 可以在CPU上面进行训练和推理 下面是
  • ATC模型转换

    xff08 1 xff09 在使用昇腾硬件 xff08 例如Atlas200 xff09 进行模型推理的时候 xff0c 首先需要使用ATC工具将原始模型转换为适合昇腾硬件的模型 xff08 om xff09 xff0c 支持原始框架类型为
  • TypeError: unsupported operand type(s) for *: ‘NoneType‘ and ‘float‘

    TypeError unsupported operand type s for 39 NoneType 39 and 39 float 39 xff0c 如果遇到这种情况说明NoneType和float不允许 的操作 xff0c 检查一下
  • 使用Image.open时,错误提示找不到文件

    Image open img path 这里的img path要是绝对路径 xff08 也就是图片在电脑上的路径 xff09 或者是执行的 py文件图片是在同一个目录下 xff0c 如果图片在另一个目录下 xff0c 编写代码的 py文件在
  • ToTensor() takes no arguments

    在写深度学习网络的时候如果出现如上错误 xff1a ToTensor takes no arguments 我当时的情况是transform 61 torchvision transforms ToTensor 这句代码 由于刚开始ToTe
  • 2022CANN训练营进阶班大作业1调试分享

    题目 xff1a 也就是输入一张JPEG图片 xff0c 经过DVPP解码 43 缩放 43 编码后将结果输出 xff0c 由于gitee代码仓中没有直接可以实现的代码 xff0c 不过提供了jpege xff0c resize xff0c
  • b660和b660m的区别 b660和b660m差多少

    1 xff1a B660M K D4 CPU供电部分有散热片 xff0c 有利于高负载供电的稳定性 2 xff1a B660M K D4具有2个M 2硬盘插槽 xff0c 而B660M P D4是1个M 2硬盘插槽 3 xff1a B660
  • OpenCV4遇到的报错及解决办法

    刚开始学习OpenCV4 xff0c 遇到一些错 xff0c 网上搜索错误原因和解决办法 xff0c 做个记录吧 报错 xff1a CV LOAD IMAGE COLOR 解决办法 xff1a 加入头文件 include opencv2 i
  • nginx的配置和详解

    nginx简介 nginx xff08 发音同engine x xff09 是一款轻量级的Web服务器 反向代理服务器及电子邮件 xff08 IMAP POP3 xff09 代理服务器 xff0c 并在一个BSD like协议下发行 ngi
  • The following packages have unmet dependencies问题解决

    当出现这些问题时一直追加安装即可
  • Python下载网易云音乐(云音乐飙升榜)

    最近突然想用python写一个自动下载的工具 xff0c 于是就先拿网易云来练练手 xff0c 并把过程中的心得写下来便于后面有想玩这个的童鞋们参考 首先我们分析网页源码 xff0c 找到我们想要的获取数据位置 xff1a 每一个标签对应着
  • ubuntu20.04 桌面图标显示异常及解决方法

    前言 更新至ubuntu20 04后 xff0c 出现了一些以前没有的问题 桌面上有些图标不显示 文章目录 前言一 具体表现二 原因三 解决方法总结 一 具体表现 例如有一次我在做备忘录时 我习惯地打开终端 span class token
  • Java类名的命名规则

    1 类名必须使用有意义的名字 xff1b 2 类名的每个单词的首字母必须大写 帕斯卡命名法 xff1b 3 类名不能使用数字 除了 和 之外的任何符号 xff0c 中间不能添加空格 xff0c 不能使用java关键字 xff1b 如 xff
  • firewalld高级配置

    1 IP地址伪装 masquerade xff1a 伪装 通过地址伪装 xff0c NAT设备将经过设备的包转发到指定接收方 xff0c 同时将通过的数据包的原地址更改为NAT的接口地址转发到不同步目的地 当是返回数据包是 xff0c 会将
  • Java中关于JSON格式数据的操作

    对于java格式数据的处理 xff1a 1 xff1a 先创建java实体类 xff0c 例如 xff1a public class Brand private String id private String brandName publ
  • 线程常用调度方法

    目录 一 线程等待 二 线程通知 三 线程休眠 四 请求让出CPU执行权 五 线程中断 一 线程等待 1 wait xff08 xff09 xff1a 当一个线程调用了wait xff08 xff09 方法后 xff0c 这个线程会被阻塞挂
  • centos7 安装jdk详细教程

    一 前言 本文主要介绍的是Centos7 Linux环境下安装jdk 8u333的详细图文教程 xff0c 用过linux服务器的开发人员都知道 xff0c JDK是作为日常开发常用的基础环境 xff0c 所以安装jdk是必要的 xff0c
  • KDE 美化(Manjaro)-记录

    KDE 美化 Manjaro 要想在不同的工具包之间获得相似的外观 xff0c 你很可能需要修改以下内容 xff1a 主题 包含一套风格 图标主题和颜色主题 风格 图形布置 xff0c 观感 图标主题 一套整体的图标 颜色主题 一套连接风格
  • spring容器对Bean组件的管理

    spring容器对Bean组件的管理 1 Bean对象创建时机 默认是随着容器创建 xff0c 可以使用lazy init 61 true xff08 在调用getBean创建 xff09 延迟创建 xff0c 也可以使用 lt beans
  • nginx平滑升级(添加echo功能)配置和状态监控

    添加echo模块 配置 1 先去github或者gitee中找到nginx module echo master zip包 2 将原来的ngin 1 20 1删除 重新编译安装 span class token punctuation sp