1、版本升级
1. 查看源程序的编译参数
configure arguments:后的参数就是编译参数
[root@k8s-node1 objs]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx/ --sbin-path=/opt/nginx/bin/nginx --conf-path=/opt/nginx/conf/nginx.conf --pid-path=/opt/nginx/nginx.pid --with-http_ssl_module --with-http_stub_status_module --with-stream
2. 备份和停止
cp -r /opt/nginx /opt/nginx-1.18.0
nginx -s stop
3. 解压并编译新版本
tar xf nginx-1.20.2.tar.gz
cd nginx-1.20.2
预编译
./configure --prefix=/opt/nginx/ \
--sbin-path=/opt/nginx/bin/nginx \
--conf-path=/opt/nginx/conf/nginx.conf \
--pid-path=/opt/nginx/nginx.pid \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-stream
编译(注意只make 不要make install)
make
复制编译make后的nginx可以执行文件覆盖nginx原文件
cp objc/nginx /opt/nginx/bin/nginx
chown -R nginx:nginx /opt/nginx
4. 验证并启动
[root@k8s-node1 nginx-1.20.2]# nginx -V
nginx version: nginx/1.20.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx/ --sbin-path=/opt/nginx/bin/nginx --conf-path=/opt/nginx/conf/nginx.conf --pid-path=/opt/nginx/nginx.pid --with-http_ssl_module --with-http_stub_status_module --with-stream
# 启动
nginx
2、配置监控
添加监控模块,需要编译http_stub_status_module
。请参照“安装”的步骤
备份nginx.conf配置文件,并添加监控server
server {
listen 127.0.0.1:8888;
server_name _;
location /nginx-status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
数据采集脚本:
#!/bin/bash
HOST="127.0.0.1" #具体配置可以查看nginx配置
PORT="8888"
function proc_num {
num=$(pgrep nginx |wc -l)
}
function active {
num=$(curl -s "http://$HOST:$PORT/nginx-status" |grep 'Active' |awk '{print $NF}')
}
function reading {
num=$(curl -s "http://$HOST:$PORT/nginx-status" |grep 'Reading' |awk '{print $2}')
}
function writing {
num=$(curl -s "http://$HOST:$PORT/nginx-status" |grep 'Writing' |awk '{print $4}')
}
function waiting {
num=$(curl -s "http://$HOST:$PORT/nginx-status" |grep 'Waiting' |awk '{print $6}')
}
function accepts {
num=$(curl -s "http://$HOST:$PORT/nginx-status" |awk NR==3 |awk '{print $1}')
}
function handled {
num=$(curl -s "http://$HOST:$PORT/nginx-status" |awk NR==3 |awk '{print $2}')
}
function requests {
num=$(curl -s "http://$HOST:$PORT/nginx-status" |awk NR==3 |awk '{print $3}')
}
$1
echo ${num:-0}
监控参数说明:
active connections -- 对后端发起的活动连接数
server accepts handled requests -- nginx 总共处理了 N个连接, 成功创建 N次握手 (证明中间没有失败的), 总共处理了 N个请求 (平均每次握手处理了 N个数据请求)
reading -- nginx 读取到客户端的Header信息数
writing -- nginx 返回给客户端的Header信息数
waiting -- 开启 keep-alive 的情况下,这个值等于 active - (reading + writing),意思就是Nginx说已经处理完正在等候下一次请求指令的驻留连接
添加可执行权限
chmod +x getNginxData.sh