nginx 平滑升级

nginx平滑升级

wget http://nginx.org/download/nginx-1.20.2.tar.gz 这是nginx1.20.2的包可以改成别的版本

nginx下载地址: nginx: download​​​​​​

我声明一下我的nginx-..新 是新版的nginx,版本有点长不想打

# nginx -v #查看当前版本(没有隐藏版本号前提下)#或者/usr/local/nginx/sbin/nginx -v也可以强制查
# cd /usr/local/src/ #存放压缩包路径(我习惯了) 
# tar -xzvf nginx-..新

要把debug日志关掉

# cd nginx-..新      
# vim auto/cc/gcc   #在配置文件把下面两行注释掉

#debug                                  #171行 大概 
#CFLAGS="$CFLAGS -g" ##注释掉(关闭debug日至) #172行

到新nginx-..本下面,编译一下 (升级就不用 make install 了,会把原先的主线程整失控)

# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module 
# make 
# echo $?            #以防出错 (0是对的其他数字都错) 
0

把原来的nginx二进制文件系统程序备份一份,防止升级后nginx出现问题可以方便恢复

# cd /usr/local/nginx/sbin/ # ls nginx # cp nginx nginx_20220413_bak

把二级制文件替换一下

# cd nginx-1.15.8 # cd objs/

# cp -f nginx /usr/local/nginx/sbin/nginx 
cp: overwrite ‘/usr/local/nginx/sbin/nginx’? y #y 确定

# -f 强制,如果不加-f,原来的nginx仍在运行,就不会覆盖

然后开始平滑升级

  • -HUP 平滑启动(相当于reload)
  • -USR2 平滑升级可执行程序,主要用在版本升级
  • -WINCH 从容关闭工作进程
  • -USR1 重新打开日志文件,主要用在日志切割(相当于reopen)

kill -USR2 旧版本主进程号

执行新的主进程(新版本)和新的工作进程,依次启动新的主进程和新的工作进程,现在新,旧版本的nginx实例会同时运行,共同处理请求

kill -WINCH 旧版本主进程号

发送WINCH信号给旧版主进程,旧版主进程就开始从容关闭

# ps -ef | grep nginx
 root 21227 1 0 2021 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx 
root 26723 21227 0 2021 ? 00:00:27 nginx: worker process 
root 26724 21227 0 2021 ? 00:00:23 nginx: worker process 
root 26725 21227 0 2021 ? 00:00:35 nginx: worker process 
root 26726 21227 0 2021 ? 00:00:24 nginx: worker process 
root 26727 21227 0 2021 ? 00:00:22 nginx: worker process 
root 26728 21227 0 2021 ? 00:00:25 nginx: worker process 
root 26729 21227 0 2021 ? 00:00:35 nginx: worker process 
root 26730 21227 0 2021 ? 00:00:22 nginx: worker process 
root 26942 20085 0 18:26 pts/1 00:00:00 grep --color=auto nginx

# kill -USR2 21227
# kill -WINCH 21227

出来问题还没整理

可以在评论去讨论,我每天都会来CSDN上找资料

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

菜鸡运维.

感谢大佬的奖励

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值