如何在不影响业务的情况下升级nginx版本

王林
Lepaskan: 2020-11-03 16:54:13
ke hadapan
2797 orang telah melayarinya

如何在不影响业务的情况下升级nginx版本

本文介绍了对yum安装的nginx的平滑升级的方法,如果原先的nginx是编译安装的,那么在升级时要注意自己的实际配置情况。

(推荐教程:nginx教程

1、查看yum安装的nginx版本及现有配置

先记录下以前的配置,后面会用到

nginx -V
Salin selepas log masuk
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
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-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --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_geoip_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_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic’ --with-ld-opt=’-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E’ --add-module=/root/nginx-rtmp-module
Salin selepas log masuk

configure arguments:后面,即为nginx现有的配置

2、下载需要的新版本的nginx的源码包

wget http://nginx.org/download/nginx-1.14.2.tar.gz
Salin selepas log masuk

3、将原来的nginx重要文件备份(为了安全)

mv /usr/sbin/nginx /usr/sbin/nginx.back 
cp -rf /etc/nginx /etc/nginx.back
Salin selepas log masuk

4、进行编译

采用前面查到的配置,如有新模块要添加也可加入

tar xf  nginx-1.14.2.tar.gz
cd nginx-1.14.2
Salin selepas log masuk
./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-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-ipv6 --with-http_auth_request_module --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_geoip_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_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic’ --with-ld-opt=’-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E’ --add-module=/root/nginx-rtmp-module
Salin selepas log masuk

5、make

由于原先已有nginx,所以不能执行make install,否则会覆盖掉以前的配置文件及内容

make
cp objs/nginx /usr/sbin/nginx
Salin selepas log masuk

6、检查是否成功

/usr/sbin/nginx -t
Salin selepas log masuk

7、平滑切换

注意:要根据自己实际的编译的配置内容,查找自己的pid文件的位置。文中原来的nginx为yum安装,所以在 /var/run下。

实际上也可在nginx-1.14.2目录下,使用make update 升级,为了避免问题,建议全手动处理

kill -USR2 `cat /var/run/nginx.pid`              将旧版本Nginx的主进程将重命名为nginx.pid.oldbin,并执行新版本的Nginx可执行程序,启动新的主进程和新的工作进程,再次生成新的nginx.pid文件
kill -WINCH `cat /var/run/nginx.pid.oldbin`      平缓停止worker process(此步骤可省略)
kill -QUIT `cat /var/run/nginx.pid.oldbin`       平缓停止旧的Nginx服务进程
Salin selepas log masuk

8、查看

f7a72f8226865d78c487ff3959a2aa9.png

文章补充:

Nginx支持的信号

可以用来控制Nginx的活动

TERM,INT——快速关闭

QUIT          平滑关闭

HUP           平滑重启,重新加载配置文件

USR1          重新打开日志文件

USR2          平滑升级可执行程序

WINCH         平滑关闭工作进程

Atas ialah kandungan terperinci 如何在不影响业务的情况下升级nginx版本. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Label berkaitan:
sumber:csdn.net
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!