概述
Zabbix 监控nginx服务需要“http_stub_status_module”模块,但openEuler和麒麟V10系统 yum install nginx 缺失“--with-http_stub_status_module”模块,需要下载同版本nginx源码包编译后替换nginx执行文件。
Prometheus 监控nginx 支持使用“http_stub_status_module”模块和第三方VTS监控工具。Kylin 和 openEuler 如此相似;
Kylin http_stub_status_module 模块
查看 http_stub_status 模块的可用性
nginx -V 2>&1 | grep -o with-http_stub_status_module
1,查看Nginx版本
通过nginx -V 查看 yum install nginx 的版本为1.16.1
nginx -V
nginx version: nginx/1.16.1
built by gcc 7.3.0 (GCC)
built with OpenSSL 1.1.1f 31 Mar 2020
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/kylin/kylin-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/kylin/kylin-hardened-ld -Wl,-E'
2,下载nginx-1.16.1源码包
下载nginx-1.16.1.tar.gz
wget http://nginx.org/download/nginx-1.16.1.tar.gz
解压源码包
tar -xzvf nginx-1.16.1.tar.gz
3,备份现有的nginx文件
cp -r /etc/nginx /etc/nginx_bak
cp /usr/sbin/nginx /usr/sbin/nginx_bak
4,安装依赖并编译
4.1,安装依赖
yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel gd gd-devel libxslt-devel libunwind-devel gperftools gperftools-devel -y
4.2,编译
cd nginx-1.16.1 && ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_stub_status_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/kylin/kylin-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/kylin/kylin-hardened-ld -Wl,-E'
4.3,编译执行 “make -j8”命令
禁止执行“make install”命令,避免原有nginx文件被覆盖
执行完成在objs目录下生成一个nginx执行文件
./nginx -V
5,nginx执行文件替换,并重启服务
cp objs/nginx /usr/sbin/
systemctl restart nginx
6,配置nginx文件,开启状态监控
vim /etc/nginx/nginx.conf
location = /basic_status {
stub_status;
allow 127.0.0.1;
allow ::1;
deny all;
}
重载配置文件
nginx -s reload
7,curl访问测试
curl -L 127.0.0.1/basic_status
openEuler nginx-module-vts 模块
1,下载
wget https://github.com/vozlt/nginx-module-vts/archive/refs/tags/v0.2.1.tar.gz
2,解压
tar -zvxf nginx-module-vts-0.2.1.tar.gz
3,移动nginx-module-vts-0.2.1目录到nginx编译目录下
mv nginx-module-vts-0.2.1 nginx-1.21.5/
4,编译
cd nginx-1.20.1 && ./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_stub_status_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_perl_module=dynamic --with-http_auth_request_module --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-google_perftools_module --with-debug --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/generic-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fPIC -D_FORTIFY_SOURCE=2 -O2 -Wtrampolines -fsigned-char' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/generic-hardened-ld -Wl,-E -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack' --add-module=nginx-module-vts-0.2.1
5,编译执行 “make -j8”命令
禁止执行“make install”命令,避免原有nginx文件被覆盖 执行完成在objs目录下生成一个nginx执行文件
./nginx -V
6,nginx执行文件替换,并重启服务
cp objs/nginx /usr/sbin/
systemctl restart nginx
7,nginx 配置
vim /etc/nginx/nginx.conf
http {
vhost_traffic_status_zone; vhost_traffic_status_filter_by_host on;
location /status {
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
重载nginx配置
nginx -s reload
8,浏览器访问
http://192.168.43.165/status