坚持以客户需求至上原则
中国老牌优质服务商

Nginx添加nginx-module-vts监控

一、版本说明

(1)系统:CentOS 7.3
(2)Nginx:1.15.7 http://nginx.org/download/
(3)nginx-module-vts:v0.1.18 https://github.com/vozlt/nginx-module-vts

二、安装nginx-module-vts

(1)解压安装
unzip nginx-module-vts-master.zip
mv nginx-module-vts-master /usr/local/

三、编译安装Nginx

(1)安装依赖环境(本文所使用yum源为CentOS7.3镜像本地yum源)
yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
(2)编译安装nginx

编译时添加监控组件nginx-module-vts,其他默认即可

tar -xvf nginx-1.15.7.tar.gz
cd nginx-1.15.7
./configure --add-module=/usr/local/nginx-module-vts-master/
make && make install
(3)编辑配置文件
vim /usr/local/nginx/conf/nginx.conf

替换为如下配置,主要是修改默认日志文件格式,添加压缩配置,添加监控配置,具体可根据自己的需求修改

user nobody;
worker_processes 1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
vhost_traffic_status_zone;

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;

keepalive_timeout 65;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 3;
gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/json application/javascript;
gzip_vary on;
proxy_http_version 1.1;
proxy_set_header Connection “”;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
}

(4)启动测试

默认nginx安装目录为/usr/local/nginx/,相关目录都在这个目录下

  • 启动nginx
/usr/local/nginx/sbin/nginx

 

测试
浏览器输入IP+80端口,可打开nginx默认页面

浏览器输入“IP:80/status”可打开监控页面

四、开机自启

将“/usr/local/nginx/sbin/nginx”命令加入“/etc/rc.d/rc.local”文件并添加权限即可

chmod +x /etc/rc.d/rc.local

 

赞(43)

更专业 更快速 更方便

华夏名网VIP服务