1、下载新版本的nginx,编译但不安装
检查旧的nginx的配置信息
(1)# cd /opt/nginx-1.16.0/sbin
(2)#./nginx -V
nginx: nginx version: nginx/1.0.5
nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-50)
nginx: TLS SNI support disabled
nginx: configure arguments:--user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-cc-opt=-O3 --with-cpu-opt=opteron --with-http_gzip_static_module
注意红色区域,这是以前编译的参数。编辑新版本的nginx需要用到,根据实际的参数修改。
2、将安装包上传到/home/目录下
3、解压 > 编译
(1)tar -zxf nginx-1.22.0.tar.gz
(2)cd nginx-1.22.0
(3)
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-cc-opt=-O3 --with-cpu-opt=opteron --with-http_gzip_static_module
(4)make
执行完后,这里不用在 make install 了
4、备份旧的可执行文件,并替换旧的可执行文件。
1、cd /opt/nginx-1.16.0/sbin
2、mv nginx nginx_1.16.0.bak
3、cd /home/nginx_file/nginx-1.22.0/objs/
4、cp nginx /opt/nginx-1.16.0/sbin/
5、确保配置文件无报错
[root@localhost nginx-1.15.9]# /opt/nginx-1.16.0/sbin/nginx -t
5、kill -USR2 旧版本的nginx主进程号。
1、ps aux | grep nginx
2、kill -USR2 1290 (进程号根据实际情况修改)
6、旧版本nginx的主进程将重命名它的.pid文件为.oldbin
1、ps aux | grep nginx
2、cat /opt/nginx-1.16.0/logs/nginx.pid
3、cat /opt/nginx-1.16.0/logs/nginx.pid.oldbin
kill -QUIT 旧版本的nginx主进程号 ( kill -QUIT
cat /opt/nginx-1.16.0/logs/nginx.pid.oldbin
)
1、kill -QUIT 1290 (进程号根据实际情况修改)
此时旧的主进程会移除.oldbin后缀,恢复为.pid文件,并且可以查看到nginx已经升级成功。升级完成了,最后在看一下升级后的版本,测试可以访问就没问题了。
注:在以上第二步的时,一段时间后,旧的工作进程(worker process)处理了所有已连接的请求后退出。仅由新的工作进程来处理输入的请求了。
到此还可以决定是否使用新版本,还可以恢复到旧版本。
kill –HUP 旧的主进程号
kill –QUIT 新的主进程号
kill –TERM 新的主进程号
新的主进程退出后,旧的主进程会移除.oldbin后缀,恢复为它的.pid文件,这样就恢复到升级之前了。