How to recompile nginx and replace current binary, with no down-time:
Recompile/upgrade nginx binary with no down-time
精选 转载xiaoyuwang 博主文章分类:运维
Follow the same generic steps as a regular install initially.
1. Download and untar the nginx source if you don't have it on your machine already.
2. Make a copy of your current nginx binary and conf. The installation usually does this automatically, but just to be safe.
"cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx_old"
"cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.old"
3. Run the "./configure" command. For example if you wanted to add SSL support to nginx, you would have a configure statement such as:
./configure --with-http_ssl_module --with-openssl=/path/to/openssl_src
If you have other options you need you can add those as well. To see what your current nginx has configured, run the binary with -V flag ie.
"/usr/local/nginx/sbin/nginx -V"
4. run: "make install clean" This will install the new binary in place of the old one and makes a backup of the old one.
These steps are more specific to replacing a current install without down-time:
5. Send a USR2 signal to the current pid file, something like:
"kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`".
This causes nginx master process that was running to rename its pid and start the new binary. Both will run simultaneously.
6. To disable the old workers, send the old master process a WINCH signal. If your pid is '123' that would be something like:
"kill -WINCH 123"
7. Now you can test the new nginx process to see if it's working. If it is, you can kill the old master process to allow the new one to take over. If the old master process had a PID of '123' you would do this:
"kill -QUIT 123"
If you find your new binary isn't working correctly, maybe due to a mistake during configuration, you can revert back to the old master process by doing the following. Assume your old master process has a PID of '123' and the new master process has a PID of '321':
"kill -HUP 123" - this will restart the workers under the old master process
"kill -QUIT 321" - shuts down the new master process workers
"kill -TERM 321" - shuts down the new master process
You can find some additional information about nginx upgrades and signals here:
http://wiki.codemongers.com/NginxCommandLine#utnbotf
下一篇:通过awk求文件的后缀名
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Leetcode: Binary Tree Upside Down
这题第一眼看上去觉得没头绪,不知道怎么上下翻转和左右翻转。但在纸上画几个例子就清楚了。所有的右子树要么为空、要么就是叶子节点且有左子树存在。 那么原来的数一直沿左子树走下去最左的那个节点就是新树的根节点。 这道题最关键在于想到要用递归去做!这种树的结构、父子两层节点关系的问题多半都要用递归去做。这是
Leetcode Tree/Graph Recursion java函数参数问题 Construct Tree