NGINX热部署

备份二进制文件:

cp /usr/bin/nginx nginx.old

把编译好的新版Nginx的二进制文件覆盖旧版本。objs目录为编译过程中的中间文件目录。

cp -r /new_nginx/objs/nginx /usr/bin/ -f 

向正在运行Nginx的master进程发送热部署信号:

ps -ef | grep nginx
root       6668      1  0 19:50 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www        6674   6668  0 19:50 ?        00:00:00 nginx: worker process
www        6677   6668  0 19:50 ?        00:00:00 nginx: worker process
root       9256   7671  0 20:49 pts/0    00:00:00 grep --color=auto nginx
kill -USR2 6668

Nginx将会建立一个新的master和多个worker进程,新的请求新的连接将会发送到新的nginx进程中。旧的nginx进程已不再使用。

root       6668      1  0 19:50 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www        6674   6668  0 19:50 ?        00:00:00 nginx: worker process
www        6677   6668  0 19:50 ?        00:00:00 nginx: worker process
root       9285   6668  0 21:00 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www        9286   9285  7 21:00 ?        00:00:00 nginx: worker process
www        9287   9285  7 21:00 ?        00:00:00 nginx: worker process
root       9289   7671  0 21:00 pts/0    00:00:00 grep --color=auto nginx

关闭旧Nginx进程,注意进程状态。

kill -WINCH 6668
root       6668      1  0 19:50 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
root       9285   6668  0 21:00 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www        9286   9285  0 21:00 ?        00:00:00 nginx: worker process
www        9287   9285  0 21:00 ?        00:00:00 nginx: worker process
root       9305   7671  0 21:06 pts/0    00:00:00 grep --color=auto nginx

旧的Nginx中worker进程已被销毁,而master进程还在。用于在新版本的Nginx中若遇到问题,可以重新reload旧版本的nginx进程拉起worker进程,用于保留版本回退,顾旧版本的Nginx主进程不会自动关闭。


Nginx安装包解压后的根目录中有contrib目录,把contrib/vim下的所有文件复制到~/.vim目录下以使Nginx的配置文件代码高亮。

cp -r contrib/vim/* ~/.vim/
原文地址:https://www.cnblogs.com/qiutianjia/p/11574063.html