Linux 服务升级:Nginx 热升级 与 平滑回退,2024年最新字节大牛教你手撕Linux运维学习

本文详细介绍了如何在Linux上进行Nginx服务的热升级和平滑回退,包括备份、解压、编译、验证、发送不同信号等关键步骤。通过发送USR2、WINCH和QUIT信号来确保服务的稳定切换和旧版本的恢复。作者分享了个人在大厂的运维经验,并提供了一套全面的2024年Linux运维学习资料,涵盖从零基础到高级进阶的全方面内容,旨在帮助运维工程师系统提升技能。
摘要由CSDN通过智能技术生成

(3)备份

[root@www nginx-1.25.4]# cd ~
[root@www ~]# cd /usr/local/nginx
[root@www nginx]# ls
client_body_temp  conf  fastcgi_temp  html  logs  passwd.db  proxy_temp  sbin  scgi_temp  uwsgi_temp
[root@www nginx]# cd ..
[root@www local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  nginx  php  sbin  share  src  stress
[root@www local]# cp -pr ./nginx ./nginx_20240319_1.22.0
[root@www local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  nginx  nginx_20240319_1.22.0  php  sbin  share  src  stress

(4)解压

[root@www opt]# tar xf nginx-1.25.4.tar.gz

(5)编译

[root@www local]# cd /opt/nginx-1.25.4/
[root@www nginx-1.25.4]# ls

#这里指定的安装路径前缀和老的nginx保持一致
[root@www nginx-1.25.4]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module

[root@www nginx-1.25.4]# make

(6)验证

[root@www nginx-1.25.4]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@www nginx-1.25.4]# cd objs
[root@www objs]# ls
autoconf.err  Makefile  nginx  nginx.8  ngx_auto_config.h  ngx_auto_headers.h  ngx_modules.c  ngx_modules.o  src

(7)备份旧的Nginx二进制

[root@www objs]# cd /usr/local/sbin
[root@www sbin]# ls
nginx  php-fpm
[root@www sbin]# mv ./nginx ./nginx_1.22.0
[root@www sbin]# ls
nginx_1.22.0  php-fpm

(8)拷贝新的Nginx二进制

[root@www sbin]# cd ..
[root@www local]# ls
bin  etc  games  include  lib  lib64  libexec  mysql  nginx  nginx_20240319_1.22.0  php  sbin  share  src  stress
[root@www local]# cp -pr /opt/nginx-1.25.4/objs/nginx ./sbin

查看

[root@www local]# cd sbin
[root@www sbin]# ls
nginx  nginx_1.22.0  php-fpm

(9)向旧的master发送USR2信号

查看旧的master进程PID为3142

[root@www sbin]# ps -ef | grep  -E "CMD|nginx"
UID         PID   PPID  C STIME TTY          TIME CMD
root       3142      1  0 12:34 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx      3143   3142  0 12:34 ?        00:00:00 nginx: worker process
nginx      3144   3142  0 12:34 ?        00:00:00 nginx: worker process
nginx      3145   3142  0 12:34 ?        00:00:00 nginx: worker process
nginx      3146   3142  0 12:34 ?        00:00:00 nginx: worker process
nginx      3147   3142  0 12:34 ?        00:00:00 nginx: worker process
nginx      3148   3142  0 12:34 ?        00:00:00 nginx: worker process
nginx      3149   3142  0 12:34 ?        00:00:00 nginx: worker process
nginx      3150   3142  0 12:34 ?        00:00:01 nginx: worker process
root      10884   3006  0 14:09 pts/1    00:00:00 grep --color=auto -E CMD|nginx
[root@www sbin]# ps axuw | head -1;ps axuw | grep nginx
USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root       3142  0.0  0.0  20532   688 ?        Ss   12:34   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx      3143  0.0  0.1  24292  2964 ?        S    12:34   0:00 nginx: worker process
nginx      3144  0.0  0.1  24292  2972 ?        S    12:34   0:00 nginx: worker process
nginx      3145  0.0  0.1  24292  2968 ?        S    12:34   0:00 nginx: worker process
nginx      3146  0.0  0.1  24292  2972 ?        S    12:34   0:00 nginx: worker process
nginx      3147  0.0  0.1  24292  2968 ?        S    12:34   0:00 nginx: worker process
nginx      3148  0.0  0.1  24292  2968 ?        S    12:34   0:00 nginx: worker process
nginx      3149  0.0  0.1  24292  2972 ?        S    12:34   0:00 nginx: worker process
nginx      3150  0.0  0.1  24292  2972 ?        S    12:34   0:01 nginx: worker process
root      10922  0.0  0.0 112676   984 pts/1    S+   14:10   0:00 grep --color=auto nginx

(10)确认nginx.pid位置

[root@www run]# cd /usr/local/nginx

[root@www nginx]# find ./ -name nginx.pid
./logs/nginx.pid
[root@www nginx]# cat ./logs/nginx.pid
3142

(11) 热升级

<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值