Linux   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linux centos7 实现yum安装的nginx平滑升级 从1.12.2版本到1.61.1版本大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

yum安装nginx-1.12.2 升级到nginx-1.16.1 一、查看现有的 nginx 编译参数 [[email protected] ~]# 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
yum安装Nginx-1.12.2 升级Nginx-1.16.1

一、查看现有的 Nginx 编译参数
[[email protected] ~]# 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/clientbody --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-httpauthrequestmodule --with-httpsslmodule --with-httpv2module --with-httprealipmodule --with-httpadditionmodule --with-httpxsltmodule=dynamic --with-httpimagefiltermodule=dynamic --with-httpgeoipmodule=dynamic --with-httpsubmodule --with-httpdavmodule --with-httpflvmodule --with-httpR_681_11845@p4module --with-httpgunzipmodule --with-httpgzipstaticmodule --with-httprandomindexmodule --with-httpsecurelinkmodule --with-httpdegradationmodule --with-httpslicemodule --with-httpstubstatusmodule --with-httpperlmodule=dynamic --with-mail=dynamic --with-mailsslmodule --with-pcre --with-pcre-jit --with-stream=dynamic --with-streamsslmodule --with-googleperftoolsmodule --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‘

二、将上面加粗字体部分进行配置,加粗字体后面为系统的配置文件不需要配置,只需要到 make,千万不要 make install 。如果make install 会将原来的配置文件覆盖

事先可以先把这些依赖包下好,配置之后就不会出现下面这些错误
yum -y install GeoIP GeoIP-devel GeoIP-data perl-devel perl-ExtUtils-Embed gd-devel libxml2 libxslt-devel gperftools pcre-devel openssl openssl-devel
准备新版本的Nginx放在/usrr/local/ 下

[[email protected]]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
[[email protected]]# tar -xf Nginx-1.16.1.tar.gz
[[email protected]]# cd Nginx-1.16.1
[[email protected] 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-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-google_perftools_module --with-debug

有可能的报错
报错1:
./configure: error: the http XSLT module requires the libxml2/libxslt
libraries. You can either do not enable the module or install the libraries.
原因:缺少依赖
解决
[[email protected] Nginx-1.16.1]# yum -y install libxml2 libxslt-devel

再次配置
报错2:
./configure: error: the http image filter module requires the GD library.
You can either do not enable the module or install the libraries.
解决:安装依赖
yum -y install gd-devel

再次配置
报错3:
./configure: error: perl module ExtUtils::Embed is required
解决
yum -y install perl-devel perl-ExtUtils-Embed
再次配置
报错4:
./configure: error: the GeoIP module requires the GeoIP library. You can either do not enable the module or install the library.
解决
yum -y install GeoIP GeoIP-devel GeoIP-data
再次配置
报错5:
./configure: error: the Google perftools module requires the Google perftools
library. You can either do not enable the module or install the library.
解决
yum install gperftools**
再次配置成功

三、make千万不要make install

四、备份原 Nginx 二进制文件
备份二进制文件Nginx配置文件(期间Nginx不会停止服务)
[[email protected] Nginx-1.16.1]# mv /usr/sbin/Nginx /usr/sbin/Nginx_$(date +%F)

五、复制新的Nginx二进制文件,进入新的Nginx源码包
[[email protected] Nginx-1.16.1]# cp /root/Nginx-1.16.1/objs/Nginx /usr/sbin/

六、测试新版本的Nginx是否正常
[[email protected] Nginx-1.16.1]# Nginx -t
报错:
Nginx: [emerg] module "/usr/lib64/Nginx/modules/ngx_http_geoip_module.so" version 1012002 instead of 1016001 in /usr/share/Nginx/modules/mod-http-geoip.conf:1
Nginx: configuration file /etc/Nginx/Nginx.conf test Failed
解决
vim /etc/Nginx/Nginx.conf //进入配置文件
注释 #include /usr/share/Nginx/modules/*.conf;
再次检测成功

七、给Nginx发送平滑迁移信号(若不清楚pid路径,请查看Nginx配置文件或find / -name ‘Nginx.pid‘ 查找)
[@L_301_10@ Nginx-1.16.1]# kill -USR2 cat /run/Nginx.pid

八、查看Nginx pid,会出现一个Nginx.pid.oldbin
[[email protected] Nginx-1.16.1]# ll /run/Nginx*
-rw-r--r-- 1 root root 5 Sep 6 00:36 /run/Nginx.pid
-rw-r--r-- 1 root root 6 Sep 6 00:00 /run/Nginx.pid.oldbin

九、从容关闭旧的Nginx进程
[[email protected] Nginx-1.16.1]# kill -WINCH cat /run/Nginx.pid.oldbin

十、此时不重载配置启动旧的工作进程
[[email protected] Nginx-1.16.1]# kill -HUP cat /run/Nginx.pid.oldbin

十一、结束工作进程,完成此次升级
[[email protected] Nginx-1.16.1]# kill -QUIT cat /run/Nginx.pid.oldbin

十二、验证Nginx是否升级成功
[[email protected] Nginx-1.16.1]# Nginx -vNginx version: Nginx/1.16.1升级成功

大佬总结

以上是大佬教程为你收集整理的linux centos7 实现yum安装的nginx平滑升级 从1.12.2版本到1.61.1版本全部内容,希望文章能够帮你解决linux centos7 实现yum安装的nginx平滑升级 从1.12.2版本到1.61.1版本所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。