线上不停机无感升级 Nginx 版本实战!

👉 这是一个或许对你有用的社群

🐱 一对一交流/面试小册/简历优化/求职解惑,欢迎加入「芋道快速开发平台」知识星球。下面是星球提供的部分资料: 

3bee6cf0f96ab35fd55aeb1324cfc80d.gif

👉这是一个或许对你有用的开源项目

国产 Star 破 10w+ 的开源项目,前端包括管理后台 + 微信小程序,后端支持单体和微服务架构。

功能涵盖 RBAC 权限、SaaS 多租户、数据权限、商城、支付、工作流、大屏报表、微信公众号等等功能:

  • Boot 地址:https://gitee.com/zhijiantianya/ruoyi-vue-pro

  • Cloud 地址:https://gitee.com/zhijiantianya/yudao-cloud

  • 视频教程:https://doc.iocoder.cn

来源:juejin.cn/post/
7277836494298447906


由于被第三方公司漏洞扫描、扫到大量Nginx漏洞、官网也有提供补丁、但是这种补丁一个一个打太麻烦了、直接升级到指定版本历史漏洞肯定也修复了。

第一想到的肯定是无感升级、为了不影响线上的环境正在跑的业务、百度去找了一下无感升级的流程后续总结一下。

查看当前Nginx一些信息

nginx -v     # 查看当前版本
nginx -V     # 查看当前版本、以及一些详细信息

基于 Spring Boot + MyBatis Plus + Vue & Element 实现的后台管理系统 + 用户小程序,支持 RBAC 动态权限、多租户、数据权限、工作流、三方登录、支付、短信、商城等功能

  • 项目地址:https://github.com/YunaiV/ruoyi-vue-pro

  • 视频教程:https://doc.iocoder.cn/video/

开始升级

下载安装包

https://nginx.org/en/download.html 前往官网下载稳定版、或者其他版本、都一样尽量下载官网的稳定版

fca25cf11f8c7f8df93a266270786c3c.jpeg

将下载好的安装包放入到服务器中

66616cda9db296210d1c8b9883e51b3c.jpeg

查看当前nginx版本

fb9745a81138d82f64d9d1d59806d64d.jpeg

将最新版本nginx解压

tar -zxvf nginx-1.24.0.tar.gz

进入到解压后的nginx文件夹内

cd nginx-1.24.0

查看nginx详细信息

nginx -V

第一张情况图

aa01d601c4afffb628267c787ca6dd37.jpeg

第二种情况图

13eaae82de8bb30831df15eb51db384e.jpeg

如:configure arguments:后无内容直接可以在当前目录下执行./configure 如:configure arguments:有内容就需要携带一起编译在当前目录下执行 ./configure --xxx

./configure --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads

执行这一步可能会出现编译失败的情况、就新版本可能会依赖一些其他包、所以执行会报错。

./configure: error: the HTTP rewrite module requires the PCRE library.
apt install libpcre3 libpcre3-dev


./configure: error: SSL modules require the OpenSSL library.
apt install libssl-dev


./configure: error: the HTTP XSLT module requires the libxml2/libxslt
apt install libxml2 libxml2-dev libxslt-dev


./configure: error: the HTTP image filter module requires the GD library.
apt install libgd-dev
 

./configure: error: the GeoIP module requires the GeoIP library.
apt install geoip-database libgeoip-dev


./configure: error: the HTTP gzip module requires the zlib library.
apt install zlib1g-dev

「注意apt命令可能一些服务上没有、你们可以选择使用yum安装的方式、百度找一下即可。」

这种情况是成功情况

13a0355e1e368f3dabf9269ab877bf4a.jpeg

重新执行make

还在新nginx文件命令下执行make命令。

f3a26fbcad6e7e962cc4214f3570e282.jpeg

等执行完成后在新nginx文件目录下一个./objs/nginx文件、将旧nginx的启动文件备份一下、在将新nginx文件目录下一个./objs/nginx文件复制到旧文件位置

mv /usr/sbin/nginx  /usr/sbin/nginx.bak

cp objs/nginx /usr/sbin/nginx

看一下当前新nginx目录中的Makefile文件

1aa89f77d3a60ff8c9faecb67a6a70c8.jpeg

如果upgrade对应的不是旧地址对应的nginx的需要进行手动修改一下。

修改好后、再新解压nginx.1.24.0文件目录下执行 make upgrade就升级好了

后续即可查看nginx版本、如果不放心有没有升级好、可以在执行make upgrade命令下先查看nginx进程ps -ef|grep nginx对比一下前后的进程是否变动了。


欢迎加入我的知识星球,全面提升技术能力。

👉 加入方式,长按”或“扫描”下方二维码噢

be690891784a0dcca73dbdfe374b3ec0.png

星球的内容包括:项目实战、面试招聘、源码解析、学习路线。

e4a186137ff8ce792027c34f5bb1db5a.png

c4b66a8baedb5294dce2cc376f0a083d.png5713088dd0cb6af529ff12ca7cf6c148.png4598d56cd0aedcb9307d033706daf133.pngb948b2a757b80c4cefd9a7ccf7b47a44.png

文章有帮助的话,在看,转发吧。
谢谢支持哟 (*^__^*)
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值