• 技术文章 >运维 >Nginx

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

    VV2020-11-03 16:54:13转载663

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

    (推荐教程:nginx教程

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

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

    nginx -V
    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

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

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

    wget http://nginx.org/download/nginx-1.14.2.tar.gz

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

    mv /usr/sbin/nginx /usr/sbin/nginx.back 
    cp -rf /etc/nginx /etc/nginx.back

    4、进行编译

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

    tar xf  nginx-1.14.2.tar.gz
    cd nginx-1.14.2
    ./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

    5、make

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

    make
    cp objs/nginx /usr/sbin/nginx

    6、检查是否成功

    /usr/sbin/nginx -t

    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服务进程

    8、查看

    f7a72f8226865d78c487ff3959a2aa9.png

    文章补充:

    Nginx支持的信号

    可以用来控制Nginx的活动

    TERM,INT——快速关闭

    QUIT 平滑关闭

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

    USR1 重新打开日志文件

    USR2 平滑升级可执行程序

    WINCH 平滑关闭工作进程

    以上就是如何在不影响业务的情况下升级nginx版本的详细内容,更多请关注php中文网其它相关文章!

    声明:本文转载于:csdn,如有侵犯,请联系admin@php.cn删除
    专题推荐:业务 nginx
    上一篇:nginx怎么输出php错误日志 下一篇:nginx可以启动成功却无法访问
    大前端线上培训班

    相关文章推荐

    • 数据收集-升级Nginx服务器,添加HTTPS过程中遇到的问题• CentOS无缝升级nginx[完整命令及自动升级脚本]• 升级nginx,查看已经安装的模块,并隐藏或者修改版本号• 重启nginx有哪几种方法

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网