linux centos7 实现yum安装的nginx平滑升级 从1.12.2版本到1.16.1版本
admin
2023-03-11 02:21:05
0

yum安装nginx-1.12.2 升级到nginx-1.16.1

一、查看现有的 nginx 编译参数
[root@vm-3 ~]# 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-httpmp4module --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 gcc make GeoIP GeoIP-devel GeoIP-data perl-devel perl-ExtUtils-Embed gd-devel libxml2 libxslt-devel gperftools pcre-devel openssl openssl-devel
准备新版本的nginx放在/usrr/local/ 下

[root@vm-3]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
[root@vm-3]# tar -xf nginx-1.16.1.tar.gz
[root@vm-3]# cd nginx-1.16.1
[root@vm-3 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.
原因:缺少依赖
解决:
[root@vm-3 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不会停止服务)
[root@vm-3 nginx-1.16.1]# mv /usr/sbin/nginx /usr/sbin/nginx_$(date +%F)

五、复制新的nginx二进制文件,进入新的nginx源码包
[root@vm-3 nginx-1.16.1]# cp /root/nginx-1.16.1/objs/nginx /usr/sbin/

六、测试新版本的nginx是否正常
[root@vm-3 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' 查找)
[root@vm-3 nginx-1.16.1]# kill -USR2 cat /run/nginx.pid

八、查看nginx pid,会出现一个nginx.pid.oldbin
[root@vm-3 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进程
[root@vm-3 nginx-1.16.1]# kill -WINCH cat /run/nginx.pid.oldbin

十、此时不重载配置启动旧的工作进程
[root@vm-3 nginx-1.16.1]# kill -HUP cat /run/nginx.pid.oldbin

十一、结束工作进程,完成此次升级
[root@vm-3 nginx-1.16.1]# kill -QUIT cat /run/nginx.pid.oldbin

十二、验证Nginx是否升级成功
[root@vm-3 nginx-1.16.1]# nginx -v
nginx version: nginx/1.16.1
升级成功

相关内容

热门资讯

台风“红霞”成为今年以来登陆我... 根据中央气象台、广东省气象台消息,今年第12号台风“红霞”的中心已于今天(26日)3时50分前后在广...
业界热议AI安全护栏升级路径 ● 本报记者 郑萃颖 近年来,人工智能(AI)技术快速发展,相关安全问题也引发各界关注。接受中国证券...
RISC-V:当开源架构遇见智... 2026年,RISC-V正站在新的历史节点。智能体的崛起、数据中心算力范式的重构,RVA23、RIS...
网络电视不小心按成蓝屏了 1、重新检查并连接好电视机的信号源输入即可。2、检测电视机的信号源输入,如线路、接口松动,则重新连接...
问问海尔的冰箱款式怎么样 最佳回答 海尔冰箱的款式还是很多的,你可以去专卖店看一看,也可以去京东上或者是天猫上看一看,京东和天...
美的中央空调面板按了没反应 美的中央空调面板按了没反应可能有多种原因,以下是一些常见的解决方法:1. 检查电源:确保空调面板已接...
爆料称一款小阔直板新机定档明年... 继华为陆续推出两款阔折叠手机产品之后,网间曾曝光过关于 @OPPO 将推出自家首款阔直板机的消息。不...
中央空调按了开关没有反应是怎么... 原因可能是因为中央空调在使用前忘记通电或者连接空调的电路老化,接触不良,可以尝试将电源通电或者更换新...
美的数控热水器开关按了没反应 先看看是否电源出现问题而导致美帝数控热水器没有通电,按了开关才会没反应。如果家里的电源有电,那么就可...
华为领衔“超节点”,这些跨界公... 文丨惠凯 编辑丨承承 算力竞争已进入“超节点”时代。在此背景下,液冷需求激增,芯片企业加速IPO,制...