计算机网络/计算机科学与应用/系统/运维/开发

Nginx 服务器升级

1、先将nginx/sbin 下的进程备份

[root@localhost sbin]# cp nginx nginx.old
[root@localhost sbin]# ll
total 7472
-rwxr-xr-x. 1 root root 3825560 Jul  2 00:08 nginx
-rwxr-xr-x  1 root root 3825560 Sep 13 22:56 nginx.old



2、查看原先nginx 版本

[root@localhost sbin]# ./nginx -v
nginx version: nginx/1.16.1



3、查看原先nginx进程

[root@localhost sbin]# ps -ef|grep nginx

root       3647      1  0 19:30 ?        00:00:00 nginx: master process ./nginx

www        3648   3647  0 19:30 ?        00:00:00 nginx: worker process

www        3649   3647  0 19:30 ?        00:00:00 nginx: worker process

www        3650   3647  0 19:30 ?        00:00:00 nginx: worker process

root       8782   5680  0 23:37 pts/1    00:00:00 grep --color=auto nginx


4、重新下载一个新的版本nginx

# wget https://nginx.org/download/nginx-1.22.1.tar.gz


解压nginx

tar zxvf nginx-1.22.1.tar.gz


cd nginx-1.22.1


编译

./configure  --prefix=/usr/local/nginx


make


5、复制新版本的二进制文件到原先旧版本二进制文件目录下

[root@localhost nginx-1.22.1]# cp -r objs/nginx /usr/local/nginx/sbin/ -f

cp: overwrite ‘/usr/local/nginx/sbin/nginx’? y



6、发送升级信号给进程号

[root@localhost sbin]# kill -USR2 3647


查看进程:

[root@localhost sbin]# ps -ef|grep nginx

root       3647      1  0 19:30 ?        00:00:00 nginx: master process ./nginx

www        3648   3647  0 19:30 ?        00:00:00 nginx: worker process

www        3649   3647  0 19:30 ?        00:00:00 nginx: worker process

www        3650   3647  0 19:30 ?        00:00:00 nginx: worker process

root       8784   3647  0 23:37 ?        00:00:00 nginx: master process ./nginx

www        8785   8784  0 23:37 ?        00:00:00 nginx: worker process

www        8786   8784  0 23:37 ?        00:00:00 nginx: worker process

www        8787   8784  0 23:37 ?        00:00:00 nginx: worker process

root       8797   5680  0 23:38 pts/1    00:00:00 grep --color=auto nginx


7、优雅关闭老的nginx进程

[root@localhost sbin]# kill -WINCH 3647


查看进程信息

[root@localhost sbin]# ps -ef|grep nginx

root       3647      1  0 19:30 ?        00:00:00 nginx: master process ./nginx

root       8784   3647  0 23:37 ?        00:00:00 nginx: master process ./nginx

www        8785   8784  0 23:37 ?        00:00:00 nginx: worker process

www        8786   8784  0 23:37 ?        00:00:00 nginx: worker process

www        8787   8784  0 23:37 ?        00:00:00 nginx: worker process

root       8807   5680  0 23:39 pts/1    00:00:00 grep --color=auto nginx


注意:

保留旧master线程,可以用作回滚使用,如果确认不需要,可以kill掉


8、查看新版本的nginx

[root@localhost sbin]# ./nginx -v

nginx version: nginx/1.22.1



9、如果需要退回版本


将老的二进制文件覆盖新的配置文件

# cp -f /usr/local/nginx/sbin/nginx.old  /usr/local/nginx/sbin/nginx


执行平滑操作

ps -ef|grep nxinx 拿到进程号


kill -HUP 进程号

kill -QUIT 进程号


查看nginx版本

sbin# ./nginx -v


人生于世,就得有点兴致,闲暇之时,或乐游山水、或尽享食味、或寄情岁时,它让我们的生活变得充盈。

评论

^