欢迎光临
我们一直在努力

Nginx-利用make upgrade命令平滑升级

对于我们在生产中的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]# 

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

  • 编译安装
[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'
cp objs/nginx '/usr/local/nginx/sbin/nginx'
test -d '/usr/local/nginx/conf' \
	|| mkdir -p '/usr/local/nginx/conf'
cp conf/koi-win '/usr/local/nginx/conf'
cp conf/koi-utf '/usr/local/nginx/conf'
cp conf/win-utf '/usr/local/nginx/conf'
test -f '/usr/local/nginx/conf/mime.types' \
	|| cp conf/mime.types '/usr/local/nginx/conf'
cp conf/mime.types '/usr/local/nginx/conf/mime.types.default'
test -f '/usr/local/nginx/conf/fastcgi_params' \
	|| cp conf/fastcgi_params '/usr/local/nginx/conf'
cp conf/fastcgi_params \
	'/usr/local/nginx/conf/fastcgi_params.default'
test -f '/usr/local/nginx/conf/fastcgi.conf' \
	|| cp conf/fastcgi.conf '/usr/local/nginx/conf'
cp conf/fastcgi.conf '/usr/local/nginx/conf/fastcgi.conf.default'
test -f '/usr/local/nginx/conf/uwsgi_params' \
	|| cp conf/uwsgi_params '/usr/local/nginx/conf'
cp conf/uwsgi_params \
	'/usr/local/nginx/conf/uwsgi_params.default'
test -f '/usr/local/nginx/conf/scgi_params' \
	|| cp conf/scgi_params '/usr/local/nginx/conf'
cp conf/scgi_params \
	'/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
	|| cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/usr/local/nginx/logs' \
	|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/logs' \
	|| mkdir -p '/usr/local/nginx/logs'
test -d '/usr/local/nginx/html' \
	|| cp -R html '/usr/local/nginx'
test -d '/usr/local/nginx/logs' \
	|| mkdir -p '/usr/local/nginx/logs'
make[1]: Leaving directory `/root/nginx-1.17.0'

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

  • 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才可以,是重启,不是重新加载。

赞(3) 打赏
原创文章转载请注明出处:爱编程 » Nginx-利用make upgrade命令平滑升级
分享到: 更多

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

爱编程、一个运维兼程序员的博客!

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏