nginx平滑升级

先说明平滑的含义,就是服务不中断。。

http://wiki.nginx.org/CommandLine

nginx的几种信号

  

The master process can handle the following signals:

TERM, INT Quick shutdown
QUIT Graceful shutdown
KILL Halts a stubborn process
HUP Configuration reload
Start the new worker processes with a new configuration
Gracefully shutdown the old worker processes
USR1 Reopen the log files
USR2 Upgrade Executable on the fly
WINCH Gracefully shutdown the worker processes


There's no need to control the worker processes yourself. However, they support some signals, too:

TERM, INT Quick shutdown
QUIT Graceful shutdown
USR1

Reopen the log files  

需要用到USR2,平滑升级的根本点在于程序支持。

方法是这样的,先是下载新版的nginx ,然后make ,make install ,网上有些说法是不正确的,说会覆盖原来的文件,那是不对的。

install了以后会自动吧原来的nginx 重命名为nginx.old ,这里需要指出的是编译参数prefix要和原来的一样。

之后是kill -USR2 `cat logs/nginx.pid`

回吧nginx.pid 改成nginx.pid.oldbin

并启动新的nginx ,现在会有两个版本的nginx 在运行

现在你可以把老版本的nginx 工作线程给关了,发送WINCH 信号,此时你可以进一步发送QUIT给老版本的nginx master

At this point you can still revert to the old server because it hasn't closed its listen sockets yet, by following these steps:

  • Send HUP signal to the old master process - it will start the worker processes without reloading a configuration file
  • Send QUIT signal to the new master process to gracefully shut down its worker processes
  • Send TERM signal to the new master process to force it quit
  • If for some reason new worker processes do not quit, send KILL signal to them

After new master process quits, the old master process removes .oldbin suffix from its .pid file, and everything is exactly as before the upgrade attempt.

If an update is successful and you want to keep the new server, send QUIT signal to the old master process to leave only new server running:

可以控制的比较精细,中途可以退回到就版本,确定要升级的话,直接USR2了以后发送QUIT 就ok了,不需要WINCH,应该本身就是Graceful shutdown 了。

原文地址:https://www.cnblogs.com/gqdw/p/2707973.html