1. 升级
1.1. 下载、编译新版本的 Nginx
1 2 3 4 5
| ➜ ~ wget https://nginx.org/download/nginx-1.15.6.tar.gz ➜ ~ tar zxvf nginx-1.15.6.tar.gz ➜ ~ cd nginx-1.15.6 ➜ ~ ./configure --prefix=/usr/local/nginx ➜ ~ make
|
备份原 Nginx 二进制文件,并用新版本替换
1 2
| ➜ ~ cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old ➜ ~ \cp -rf objs/nginx /usr/local/nginx/sbin/nginx
|
1.2. 切换 Nginx 的新老进程
1 2 3 4 5
| ➜ ~ cd /usr/local/nginx/sbin/ ➜ ~ ps -ef | grep nginx root 6680 1 0 12:17 ? 00:00:00 nginx: master process ./nginx nobody 6681 6680 0 12:17 ? 00:00:00 nginx: worker process root 31579 3601 0 12:28 pts/0 00:00:00 grep --color=auto nginx
|
向正在运行的老版本的 master
进程发送热部署信号
1 2 3 4 5 6 7 8 9 10
| ➜ ~ kill -USR2 6680
➜ ~ ps -ef | grep nginx root 6680 1 0 12:17 ? 00:00:00 nginx: master process ./nginx nobody 6681 6680 0 12:17 ? 00:00:00 nginx: worker process root 31581 6680 0 12:29 ? 00:00:00 nginx: master process ./nginx nobody 31582 31581 0 12:29 ? 00:00:00 nginx: worker process root 31584 3601 0 12:29 pts/0 00:00:00 grep --color=auto nginx
|
向老版本的 master
进程发送信号,让其优雅关闭所有 worker
进程
1 2 3 4 5 6
| ➜ ~ kill -WINCH 6680 ➜ ~ ps -ef | grep nginx root 6680 1 0 12:17 ? 00:00:00 nginx: master process ./nginx root 31581 6680 0 12:29 ? 00:00:00 nginx: master process ./nginx nobody 31582 31581 0 12:29 ? 00:00:00 nginx: worker process root 31587 3601 0 12:31 pts/0 00:00:00 grep --color=auto nginx
|
⚠️ 注意:老版本的 master
进程不会自动退出,以方便执行版本回退操作。当新版本稳定运行后,再发送信号退出老版本的 master
进程。