linux 下nginx 平滑升级

1.下载nginx 源码包,下载地址:http://nginx.org

2.使用远程工具上传至相应的服务器(putty、xshell)

3.解压

示例:[root@shuaishuai ~]# tar -xf nginx-1.19.5.tar.gz 

4.切换目录

示例:[root@shuaishuai ~]# cd nginx-1.19.5

 5.查看之前nginx所安装的模块

示例:[root@shuaishuai nginx-1.19.5]# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.15.10built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.1.1  11 Sep 2018
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=../openssl-1.1.1 --with-openssl-opt='enable-tls1_3 enable-ec_nistp_64_gcc_128' --with-pcre --without-http_gzip_module

6.预配置新版本nginx,且进行编译

示例: [root@shuaishuai nginx-1.19.5]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=../openssl-1.1.1 --with-openssl-opt='enable-tls1_3 enable-ec_nistp_64_gcc_128' --with-pcre --without-http_gzip_module && make

注:安装路径需与旧版一致,模块也需要与旧版的一致;此处千万不能执行make install

7.备份旧二进制文件nginx

示例:[root@shuaishuai nginx-1.19.5]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old 

8.用新的二进制文件nginx替换旧的

示例:[root@shuaishuai nginx-1.19.5]# cp -p objs/nginx /usr/local/nginx/sbin/nginx 

9. 确保配置文件无误

示例:[root@shuaishuai nginx-1.19.5]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

10. 向主进程(master)发送USR2信号,Nginx会启动一个新版本的master进程和对应工作进程,和旧版一起处理请求

[root@shuaishuai nginx-1.19.5]# ps aux | grep nginx

root 19658 0.0 0.5 47136 2684 ? Ss 14:49 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 16404 0.0 0.7 47532 3548 ? S 14:54 0:00 nginx: worker process
root 21993 0.0 0.2 112724 996 pts/1 S+ 20:42 0:00 grep --color=auto nginx 

[root@shuaishuai nginx-1.19.5]# kill -USR2 19658

 [root@shuaishuai nginx-1.19.5]# ps aux | grep nginx

root 19658 0.0 0.5 47136 2684 ? Ss 14:49 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 16404 0.0 0.7 47532 3548 ? S 14:54 0:00 nginx: worker process
root 21994 0.0 0.6 45968 3288 ? S 20:44 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 21995 0.0 0.3 46428 1892 ? S 20:44 0:00 nginx: worker process
root 21997 0.0 0.2 112724 996 pts/1 R+ 20:44 0:00 grep --color=auto nginx 

11. 向旧的Nginx主进程(master)发送WINCH信号,它会逐步关闭自己的工作进程(主进程不退出),这时所有请求都会由新版Nginx处理

[root@shuaishuai nginx-1.19.5]# kill -WINCH 19658

[root@shuaishuai nginx-1.19.5]# ps aux | grep nginx

root 19658 0.0 0.5 47136 2684 ? Ss 14:49 0:00 nginx: master process /usr/local/nginx/sbin/nginx
root 21994 0.0 0.6 45968 3288 ? S 20:44 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 21995 0.0 0.3 46428 1892 ? S 20:44 0:00 nginx: worker process

注:

如果这时需要回退继续使用旧版本,可向旧的Nginx主进程发送HUP信号,它会重新启动工作进程, 仍使用旧版配置文件。然后可以将新版Nginx进程杀死(使用QUIT、TERM、或者KILL)

[root@shuaishuai nginx-1.19.5]# kill -HUP 19658

 12.升级完毕,可向旧的Nginx主进程(master)发送(QUIT、TERM、或者KILL)信号,使旧的主进程退出

[root@shuaishuai nginx-1.19.5]# kill -QUIT 19658

[root@shuaishuai nginx-1.19.5]# ps aux | grep nginx

root 21994 0.0 0.6 45968 3288 ? S 20:44 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 21995 0.0 0.3 46428 1892 ? S 20:44 0:00 nginx: worker process 

13.验证nginx版本号

[root@shuaishuai nginx-1.19.5]# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.19.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.1.1  11 Sep 2018
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=../openssl-1.1.1 --with-openssl-opt='enable-tls1_3 enable-ec_nistp_64_gcc_128' --with-pcre --without-http_gzip_module

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值