平滑升级nginx到新版本

这里测试一下nginx的平滑升级,以备不时之需

查看nginx版本号:

[root@zklf-server01 ~]# /application/nginx/sbin/nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

查看nginx的编译时用到了哪些参数

(好吧,我承认这里我偷懒了,只给了一个默认路径)

[root@zklf-server01 nginx]# /application/nginx/sbin/nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
configure arguments: --prefix=/application/nginx

下载新版本,编译,make。这里的编译参数要和原来的参数相同。所有参数都要相同

[root@zklf-server01 application]# wget http://nginx.org/download/nginx-1.15.10.tar.gz
tar zxf nginx-1.15.10.tar.gz

./configure --prefix=/application/nginx

make

mv/application/nginx/sbin/nginx /application/nginx/sbin/nginx.old

cp objs/nginx /application/nginx/sbin/      # 这里的objs是新版make过的目录下面的

 

测试新版本的nginx

[root@zklf-server01 nginx-1.15.10]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx/conf/nginx.conf test is successful

让nginx把nginx.pid文件修改成nginx.pid.oldbin,随即启动nginx,实现不间断

这里的pid文件可以在nginx.conf配置文件中查看位置

kill -USR2 `cat /application/nginx/logs/nginx.pid`  平滑的重启新的部署的进程
kill -WINCH `cat /application/nginx/logs/nginx.pid` 关闭老的进程。所有请求切换到新版本

查看版本号

[root@zklf-server01 ~]# /application/nginx/sbin/nginx -V
nginx version: nginx/1.15.10
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

差不多就这样了,我的所有nginx安装路径是在/application/nginx  下面。环境变量单独设置在/etc/profile.d/nginx.sh

 

posted @ 2019-04-08 11:00  恶灵酒  阅读(251)  评论(0编辑  收藏  举报