当前位置:   article > 正文

Centos8平滑升级nginx1.20.2和回滚方案_centos8更新nginx

centos8更新nginx
  1. #下载最新稳定版
  2. [root@centos8 ~]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
  3. [root@centos8 ~]# tar xf nginx-1.20.2.tar.gz
  4. [root@centos8 ~]# cd nginx-1.20.2
  5. #查看当前使用的版本及编译选项。
  6. [root@centos8 nginx-1.20.2]# nginx -V
  7. nginx version: nginx/1.18.0
  8. built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
  9. built with OpenSSL 1.1.1k FIPS 25 Mar 2021
  10. TLS SNI support enabled
  11. configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
  12. #configure arguments后面是以前编译时的参数。现在编译使用一样的参数
  13. [root@centos8 nginx-1.20.2]# ./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module
  14. #只要make无需要make install
  15. [root@centos8 nginx-1.20.2]# make
  16. [root@centos8 nginx-1.20.2]# objs/nginx -v
  17. nginx version: nginx/1.20.2
  18. #查看两个版本
  19. [root@centos8 nginx-1.20.2]# ll objs/nginx /apps/nginx/sbin/nginx
  20. -rwxr-xr-x 1 nginx nginx 7596448 Apr 10 21:17 /apps/nginx/sbin/nginx
  21. -rwxr-xr-x 1 root root 7731496 Apr 11 16:17 objs/nginx
  22. #把之前的旧版的nginx命令备份
  23. [root@centos8 nginx-1.20.2]# mv /apps/nginx/sbin/nginx{,.bak}
  24. #把新版本的nginx命令复制过去
  25. [root@centos8 nginx-1.20.2]# cp ./objs/nginx /apps/nginx/sbin/
  26. #检测一下有没有问题
  27. [root@centos8 nginx-1.20.2]# /apps/nginx/sbin/nginx -t
  28. nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
  29. nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
  30. #USR2 平滑升级可执行程序,将存储有旧版本主进程ID的文件重命名为nginx.pid.oldbin,跟着启动新nginx
  31. [root@centos8 nginx-1.20.2]# kill -USR2 `cat /apps/nginx/run/nginx.pid`
  32. [root@centos8 nginx-1.20.2]# ps aux|grep nginx
  33. root 16532 0.0 0.1 42588 3860 ? Ss 15:24 0:00 nginx: master process /apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
  34. nobody 16918 0.0 0.2 77120 5168 ? S 15:42 0:00 nginx: worker process
  35. nobody 16919 0.0 0.2 77120 5168 ? S 15:42 0:00 nginx: worker process
  36. root 20335 0.0 0.2 42484 5368 ? S 16:23 0:00 nginx: master process /apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
  37. nobody 20336 0.0 0.2 77240 4956 ? S 16:23 0:00 nginx: worker process
  38. nobody 20337 0.0 0.2 77240 4996 ? S 16:23 0:00 nginx: worker process
  39. #先关闭旧nginx的worker进程,而不关闭老nginx master方便回滚(这时候有问题,可以选择回滚)
  40. #向原Nginx主进程发送WINCH信号,它会逐步关闭旗下的worker(master不退出),这时所有请求都会由新版Nginx处理
  41. [root@centos8 nginx-1.20.2]# kill -WINCH `cat /apps/nginx/run/nginx.pid.oldbin`
  42. [root@centos8 nginx-1.20.2]# ps aux|grep nginx
  43. root 16532 0.0 0.1 42588 3860 ? Ss 15:24 0:00 nginx: master process /apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
  44. root 20335 0.0 0.2 42484 5368 ? S 16:23 0:00 nginx: master process /apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
  45. nobody 20336 0.0 0.2 77240 4956 ? S 16:23 0:00 nginx: worker process
  46. nobody 20337 0.0 0.2 77240 4996 ? S 16:23 0:00 nginx: worker process
  47. root 20645 0.0 0.0 12136 1144 pts/0 S+ 16:34 0:00 grep --color=auto nginx
  48. [root@centos8 nginx-1.20.2]# pstree -p|grep nginx
  49. |-nginx(16532)---nginx(20335)-+-nginx(20336)
  50. | `-nginx(20337)
  51. #经过一段时间测试,新版本服务没问题,最后退出老的master
  52. [root@centos8 nginx-1.20.2]# kill -QUIT `cat /apps/nginx/run/nginx.pid.oldbin`
  53. #查看版本是不是已经是新版了
  54. [root@centos8 nginx-1.20.2]# nginx -v
  55. nginx version: nginx/1.20.2
  56. [root@centos8 nginx-1.20.2]# curl -I 127.0.0.1
  57. HTTP/1.1 200 OK
  58. Server: nginx/1.20.2
  59. Date: Mon, 11 Apr 2022 08:42:57 GMT
  60. Content-Type: text/html
  61. Content-Length: 612
  62. Last-Modified: Sun, 10 Apr 2022 13:17:26 GMT
  63. Connection: keep-alive
  64. ETag: "6252d8e6-264"
  65. Accept-Ranges: bytes
  66. #回滚
  67. #如果升级的版本发现问题需要回滚,可以重新拉起旧版本的worker
  68. [root@centos8 nginx-1.20.2]# kill -HUP `cat /apps/nginx/run/nginx.pid.oldbin`
  69. #最后关闭新版的master
  70. [root@centos8 nginx-1.20.2]# kill -QUIT `cat /apps/nginx/run/nginx.pid`

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/151048
推荐阅读
相关标签
  

闽ICP备14008679号