Nginx compilation and installation + monitoring module Nginx-module-vts

Table of contents

1. Prepare the installation package and decompress it

2. Install dependent compilation software

3. Compile and install nginx and modules

4. Optimizing management

Five, modify the configuration file

6. Verification

7. Information in each field of the monitoring module


 

The vts module in nginx is a very useful monitoring module, which allows us to clearly observe the current status of the server

1. Prepare the installation package and decompress it

First, we prepare the installation packages of nginx and vts

41525d782d9d499489bb75f650f9f5f3.png

 and then unzip it

tar -zxvf nginx-1.22.0.tar.gz

unzip nginx-module-vts-master.zip

mv nginx-module-vts-master /usr/local

f0b188ebb2e54a159ec305fe231ded6e.png 2. Install dependent compilation software

yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel make

89e67e0919474efbb637228a50b5c74e.png

Here I have installed all

3. Compile and install nginx and modules

useradd -M -s /sbin/nologin nginx

#Creating users is to make nginx more flexible and give more permissions

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --add-module=/opt/nginx-module-vts-master/   

5eafed276fd04a918a39b8a38de7d74a.png

 make && make install

44db5b543a544a1e9b30fcd55df64108.png

5e807ae6fb61458483ba9bfce2b87e41.png

 This completes the installation

4. Optimizing management

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

625fd1b903d5418aae03bd672ce9c2b3.png

 nginx -V #View nginx installation information

02f9bda3451c45258b6175975a4727ee.png

The vts module is also loaded here

nginx -t #Test it

dd38ed204acc49dd8ffe2c55cb78fcf4.png

Five, modify the configuration file

vim /usr/local/nginx/conf/nginx.conf #The configuration file is as follows

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    vhost_traffic_status_zone;                  #流量状态监控
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
log_format main '{ "@timestamp": "$time_local", '
'"@fields": { '
'"uri":"$request_uri",'
'"url":"$uri",'
'"upstream_addr":"$upstream_addr",'
'"remote_addr": "$remote_addr", '
'"remote_user": "$remote_user", '
'"body_bytes_sent": "$body_bytes_sent", '
'"host":"$host",'
'"server_addr":"$server_addr",'
'"request_time": "$request_time", '
'"request_time":"$request_time",'
'"status":"$status",'
'"request": "$request", '
'"request_method": "$request_method", '
'"size":$body_bytes_sent,'
'"upstream_time":"$upstream_response_time"'
'"http_referrer": "$http_referer", '
'"body_bytes_sent":"$body_bytes_sent", '
'"http_x_forwarded_for": "$http_x_forwarded_for", '
'"http_user_agent": "$http_user_agent" } }';
    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
        }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

nginx #start service

nginx reload #Reload the configuration file

6. Verification

0a30effb49c94d758de87729f106260f.png

 a34d4884dc24441e8e27876cb7dd37bf.png

This module is successfully added

7. Information in each field of the monitoring module

监控列表各项信息
Server main 主服务器
**Host:**主机名
**Version:**版本号
**Uptime:**服务器运行时间
Connections active:当前客户端的连接数 reading:读取客户端连接的总数 writing:写入客户端连接的总数
Requsts accepted:接收客户端的连接总数 handled:已处理客户端的连接总数 Total:请求总数 Req/s:每秒请求的数量
Shared memory:共享内存 name:配置中指定的共享内存名称 maxSize:配置中指定的共享内存的最大限制 usedSize:共享内存的当前大小 usedNode:共享内存中当前使用的节点数
Server zones 服务器区域
zone:当前区域
Requests Total:请求总数 Req/s:每秒请求数 time:时间
Responses:状态码数量 1xx、2xx、3xx、4xx、5xx:表示响应不同状态码数量 Total:响应状态码的总数
Traffic表示流量 Sent:发送的流量 Rcvd:接收的流量 Sent/s:每秒发送的流量 Rcvd/s:每秒接收的流量
Cache表示缓存 Miss:未命中的缓存数 Bypass:避开的缓存数 Expirde:过期的缓存数 Stale:生效的缓存数 Updating:缓存更新的次数 Revalidated:重新验证的缓存书 Hit:缓存命中数 Scarce:未达缓存要求的请求次数Total:总数

 

 

Guess you like

Origin blog.csdn.net/qq_57377057/article/details/126552836#comments_26028363