Nginx 监控模块
Nginx 监控模块
1. 编译环境
yum -y install gcc gcc-c++ pcre pcre-devel zlib-devel expat-devel
#缺少C++环境提示在安装这个
openssl openssl-devel
2. 软件包
wget http://nginx.org/download/nginx-1.22.0.tar.gz
3. 解压
tar xf nginx-1.22.0.tar.gz -C /usr/local/src
4. 创建用户
useradd -M -s /sbin/nologin nginx
5. 编译安装
cd /usr/local/src/nginx-1.22.0
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make && make install
6. 启动
cd /usr/local/nginx/sbin/
./nginx
7. 是否运行
netstat -lntup | grep nginx
增加监控配置模块模拟
- 先检查是否有http_stub_status_module模块
- 需要安装的模块是ngx_req_status-master模块、nginx-module-vts模块
先停掉服务
1. 上传包
#Xftp
nginx-module-vts-0.1.18.tar.gz
ngx_req_status-master.zip
2. 放到同级目录
mv /root/* /usr/local/src/
3. 解压
tar xf nginx-module-vts-0.1.18.tar.gz
unzip ngx_req_status-master.zip
4. 备份
cp -rf /usr/local/src/nginx/objs /root/
cp -rf /usr/local/nginx/sbin/nginx /root/
cp -rf /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx/nginx.bak
5.添加补丁
cd /usr/local/src/nginx/
ls
patch -p1 < ../ngx_req_status-master/write_filter-1.7.11.patch
6. 执行编译
还需要把原来的编译环境参数也需要添加过来
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module \
--add-module=/usr/local/src/nginx-module-vts-0.1.18 \
--add-module=/usr/local/src/ngx_req_status-master
7. 编译
make
8. 查看objs目录
- 会新生成一个nginx命令
#执行,查看有没有新的监控模块
./nginx -V
9. 替换命令
#上面步骤都备份好了,先把源目录/usr/local/nginx/sbin/nginx,移走,安全点,
cd /usr/local/src/nginx/objs/
mv nginx /usr/local/nginx/sbin/
10. 配置文件添加内容
req_status_zone server_name $server_name 256k;
req_status_zone server_addr $server_addr 256k;
req_status_zone server_url $server_name$uri 256k;
req_status server_name server_addr server_url;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /req-status{
req_status_show on;
}
location /nginx-status{
stub_status on;
access_log on;
}
location /vts_status {
access_log off;
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
11. 测试
curl localhost/req-status