1. 查看现有nginx 版本及参数
查看版本和原编译参数
#旧版本的nginx安装目录/usr/local/nginx
$cd /usr/local/nginx
$./sbin/nginx -V
nginx version: nginx/1.22.1
built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4)
built with OpenSSL 3.0.7 1 Nov 2022 (running with OpenSSL 3.0.8 7 Feb 2023)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-Os -fomit-frame-pointer -g' --with-ld-opt=-Wl,--as-needed,-O1,--sort-common
2. 备份现有的nginx
$cp -a ./nginx ./nginx.bak
3. 参考之前旧版本的编译参数,编译安装新的nginx
#如果新版本的nginx源代码文件位置/opt/nginx-1.24.0.tar.gz
$cd /opt
$tar -zxvf nginx-1.24.0.tar.gz
$cd nginx-1.24.0
$./configure --prefix=/usr/local/nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-Os -fomit-frame-pointer -g' --with-ld-opt=-Wl,--as-needed,-O1,--sort-common
$make && make install
4. 生成新的master进程
给正在运行nginx的master进程发送一个信号,告诉master要热部署,做一次版本升级,这个信号是USER2,USER2信号用来传递热部署的信号
$kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
5. 优雅退出老worker进程
向老的master进程发信号,4076是老nginx的master进程的进程号,告诉它关闭其worker进程
kill -WINCH 4076
6. 升级完成,退出老的worker进程
经过一段时间测试,服务器没问题,退出老的master进程
kill -QUIT 4076