Nginx平滑升级(make upgrade)

对于我们在生产中的nginx服务器端,如需升级咱们的nginx系统版本,前题就是需要在升级过程中不能影响到nginx的运行,今天我们就介绍一下nginx的平滑升级,讲述一下据体的升级操作过程。

还有一个就是,最近遇到项目上线需要进行安全测试,按圈扫描之后报告当中提示nginx存在安全漏洞,需要进行修复,一种解决办法是去打补丁,一种就是直接升级到该漏洞影响的版本之外,我们这里说的就是第二种方式。

首先我们查看下服务器上面原nginx的版本

[root@localhost ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.15.9
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_addition_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-http_v2_module --add-module=/root/ngx_http_substitutions_filter_module
[root@localhost ~]# 

在这里我们可以看到这台nginx服务器端的版本是1.15.9,下面是配置选项,这个一会我们下载最新的版本后,需要用到这个配置项来对新版本进行配置。

下载最新的nginx,(官方下载地址:http://nginx.org/en/download.html) 

[root@localhost ~]# wget -c http://nginx.org/download/nginx-1.17.0.tar.gz
--2019-06-19 12:37:46--  http://nginx.org/download/nginx-1.17.0.tar.gz
Resolving nginx.org (nginx.org)... 95.211.80.227, 62.210.92.35, 2001:1af8:4060:a004:21::e3
Connecting to nginx.org (nginx.org)|95.211.80.227|:80... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 1032978 (1009K), 1016293 (992K) remaining [application/octet-stream]
Saving to: ‘nginx-1.17.0.tar.gz’

100%[++=======================================================================================================================================>] 1,032,978   33.9KB/s   in 33s    

2019-06-19 12:38:19 (30.3 KB/s) - ‘nginx-1.17.0.tar.gz’ saved [1032978/1032978]

[root@localhost ~]# 

解压nginx-1.17.0.tar.gz,并cd到解压目录

[root@localhost ~]# tar -zxvf nginx-1.17.0.tar.gz
………………………………………………………………
nginx-1.17.0/auto/cc/name
nginx-1.17.0/auto/cc/owc
nginx-1.17.0/auto/cc/sunc
[root@localhost ~]# cd nginx-1.17.0
[root@localhost nginx-1.17.0]# 

 配置安装选项,要和我们上面查询版本时所查看到的配置保持一致,要不你可就少安装功能了,导致一些功能不可用了。

[root@localhost nginx-1.17.0]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_addition_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-http_v2_module --add-module=/root/ngx_http_substitutions_filter_module
checking for OS
 + Linux 3.10.0-957.1.3.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
………………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………………

编译

[root@localhost nginx-1.17.0]# make
……………………………………………………………………………………
……………………………………………………………………………………
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
	-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
	-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
	-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
	< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/root/nginx-1.17.0'

运行平滑升级命令

[root@localhost nginx-1.17.0]# make upgrade
/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
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
[root@localhost nginx-1.17.0]# 

 注:到这里运行平滑级后,升级并没有完成,需要再次编译安装才可以,原本第一次认为到这里升级就结束了,但查询版本号还是原来的版本。

编译安装(其实make 和make install 可以一步运行写成。make && make install)

扫描二维码关注公众号,回复: 8835888 查看本文章
[root@localhost nginx-1.17.0]# make install
make -f objs/Makefile install
make[1]: Entering directory `/root/nginx-1.17.0'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
test -d '/usr/local/nginx/sbin' \
	|| mkdir -p '/usr/local/nginx/sbin'
test ! -f '/usr/local/nginx/sbin/nginx' \
	|| mv '/usr/local/nginx/sbin/nginx' \
		'/usr/local/nginx/sbin/nginx.old'

至此我们的平滑升级结束,我们可以再次查询nginx的版本号。

[root@localhost nginx-1.17.0]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.17.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_addition_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-http_v2_module --add-module=/root/ngx_http_substitutions_filter_module
[root@localhost nginx-1.17.0]#

查询得到我们已把nginx升级到最新的1.17.0版本了,经测试,你也可以把平滑升级命令make upgrade这一步省略掉,直接编译安装,但安装后需要重启nginx才可以,是重启,不是重新加载。

发布了143 篇原创文章 · 获赞 31 · 访问量 14万+

猜你喜欢

转载自blog.csdn.net/qq_42112846/article/details/102905984