Nginx信号控制和平滑升级(二)

Nginx的信号控制

上面我们实现的Nginx服务器的启动、停止以及重启是用信号来控制的。这是一些简单的信号控制。在Nginx服务器中,通常情况都是通过对其发送控制信号进行控制的,除了以上所说的简单的信号控制之外,还有很多的信号控制。在此,我们需要知道要想操作Nginx服务器,一般来说是对其发送信号来对其进行控制。


HUP:重启
QUIT:从容关闭
TERM:快速关闭
INT:从容关闭
USRI:切换日志文件
USR2:平滑升级可执行进程

WINCH:从容关闭工作进程

测试

[root@localhost alen]# ps -ef|grep nginx
root       3475      1  0 11:46 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody     3477   3475  0 11:46 ?        00:00:00 nginx: worker process
root       3725   3431  0 11:50 pts/0    00:00:00 grep --color=auto nginx

[root@localhost alen]# kill -QUIT 3475



Nginx的平滑升级 

有时,我们需要对我们的服务器进行升级更高版本。此时,如果我们强行将服务器停止然后直接升级,这样原来在服务器上运行着的进程就会被影响。如何解决这个问题呢?可以通过平滑升级的方式来解决。平滑升级时,不会停掉在运行着的进程,这些进程会继续处理请求,但不会再接受新请求,在这些老进程在处理完还在处理的请求后,停止。此平滑升级的过程中,新开的进程会处理新请求。这就是平滑升级的简要说明。 

具体步骤

1.查看现在nginx版本,进入nginx可执行文件目录,
[alen@localhost ~]$ cd /usr/local/nginx/sbin
[alen@localhost sbin]$ ls
nginx
输入
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.13.8

2.下载nginx1.13.9版本http://nginx.org/en/download.html
复制到目录soft
解压
[root@localhost soft]# tar -zxvf nginx-1.13.9.tar.gz 

3.进入nginx-1.13.9解压的文件夹
[root@localhost soft]# ls
nginx-1.13.8  nginx-1.13.8.tar.gz  nginx-1.13.9  nginx-1.13.9.tar.gz
[root@localhost soft]# cd nginx-1.13.9
[root@localhost nginx-1.13.9]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README

4.执行
[root@localhost nginx-1.13.9]# ./configure

5.执行make
[root@localhost nginx-1.13.9]# make
不需要执行make install

6.进入nginx可执行文件目录,备份旧的nginx文件
[alen@localhost ~]$ cd /usr/local/nginx/sbin
[alen@localhost sbin]$ ls
nginx
[alen@localhost sbin]$ cp nginx nginx.old
cp: 无法创建普通文件"nginx.old": 权限不够
[alen@localhost sbin]$ su
密码:
[root@localhost sbin]# cp nginx nginx.old
[root@localhost sbin]# ls
nginx  nginx.old


7.将新的nginx文件覆盖旧的nginx文件
[root@localhost nginx-1.13.9]#  cp -rfp objs/nginx /usr/local/nginx/sbin
cp:是否覆盖"/usr/local/nginx/sbin/nginx"? y
平滑升级成功

8.删除压缩包和解压后的文件
[root@localhost soft]# ls
nginx-1.13.8  nginx-1.13.8.tar.gz  nginx-1.13.9  nginx-1.13.9.tar.gz

[root@localhost soft]# rm -rf nginx-1.13.9/
[root@localhost soft]# rm -r nginx-1.13.9.tar.gz 
rm:是否删除普通文件 "nginx-1.13.9.tar.gz"?y
[root@localhost soft]# 


猜你喜欢

转载自blog.csdn.net/u014401141/article/details/79360904