一、上传解压新版本的源码包
root@localhost ~]# rz
z waiting to receive.**B0100000023be50
[root@localhost ~]# ls
anaconda-ks.cfg nginx-1.14.0.tar.gz nginx-1.16.1.tar.gz
[root@localhost ~]# tar xf nginx-1.16.1.tar.gz -C /usr/src/
二、获取旧版本的编译安装信息
[root@localhost ~]# nginx -V
nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx
三、编译新版本的源码包,不执行安装(make install)
#安装路径与旧版本必须相同
[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx && make
四、备份二进制文件,用新版替换旧的
[root@localhost ~]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/old.nginx
[root@localhost ~]# ls /usr/local/nginx/sbin/
old.nginx
[root@localhost ~]# cp /usr/src/nginx-1.16.1/objs/nginx /usr/local/nginx/sbin/
[root@localhost ~]# ls /usr/local/nginx/sbin/
nginx old.nginx
五、确保配置文件不报错
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
六、发送USR2信号
向主进程(master)发送USR2信号,Nginx会启动一个新版本的master进程和对应工作进程,和旧版一起处理请求
[root@localhost ~]# ps aux | grep nginx | grep -v grep
root 4108 0.0 0.2 45028 1152 ? Ss 16:58 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 4109 0.0 0.4 45456 2012 ? S 16:58 0:00 nginx: worker process
[root@localhost ~]# kill -USR2 4108
[root@localhost ~]# ps aux | grep nginx | grep -v grep
root 4108 0.0 0.2 45028 1316 ? Ss 16:58 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 4109 0.0 0.4 45456 2012 ? S 16:58 0:00 nginx: worker process
root 6605 0.5 0.6 45196 3364 ? S 17:02 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 6607 0.0 0.3 45624 1756 ? S 17:02 0:00 nginx: worker process
七、发送WINCH信号
向旧的Nginx主进程(master)发送WINCH信号,它会逐步关闭自己的工作进程(主进程不退出),这时所有请求都会由新版Nginx处理
[root@localhost ~]# kill -WINCH 4108
[root@localhost ~]# ps aux | grep nginx | grep -v grep
root 4108 0.0 0.2 45028 1320 ? Ss 16:58 0:00 nginx: master process /usr/local/nginx/sbin/nginx
root 6605 0.0 0.6 45196 3364 ? S 17:02 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 6607 0.0 0.3 45624 1756 ? S 17:02 0:00 nginx: worker process
八、发送QUIT信号
升级完毕,可向旧的Nginx主进程(master)发送(QUIT、TERM、或者KILL)信号,使旧的主进程退出
[root@localhost ~]# kill -QUIT 4108
[root@localhost ~]# ps aux | grep nginx | grep -v grep
root 6605 0.0 0.6 45196 3364 ? S 17:02 0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 6607 0.0 0.4 45624 2056 ? S 17:02 0:00 nginx: worker process
九、验证nginx版本号,并访问测试
[root@localhost ~]# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx/1.16.0
Date: Sun, 18 Aug 2019 13:34:07 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 18 Aug 2019 13:26:08 GMT
Connection: keep-alive
ETag: "5d5951f0-264"
Accept-Ranges: bytes