ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

nginx通过shell脚本平滑升级版本

2019-03-08 14:56:07  阅读:246  来源: 互联网

标签:sbin shell http 平滑 module nginx usr local


1、简介
  有时候nginx发布了新BUG或者添加了新的功能时,想要更新的时候服务又不能中断,这时候就要用到nginx的平滑升级了。

  该脚本同样适用于添加新扩展,添加新扩展的时候只需要把更新的版本修改为当前版本,更新的时候把需要添加的扩展加上去即可。
我这里nginx安装目录为/usr/local/nginx
当前系统,阿里云ECS CentOS 7 64位

2、查看nginx版本与编译信息
/usr/local/nginx/sbin/nginx -V
nginx通过shell脚本平滑升级版本

注:这里的扩展要记录下来(重要),等下升级的时候用到,如果有需要添加新信息可以一起编译。
nginx通过shell脚本平滑升级版本

3、使用shell脚本平滑升级nginx版本
shell 脚本:------------------------------------------------------------------------------------------------------------------------------

#!/bin/bash
source ./cnl_function.sh
source ./cnl_install_lnmp_init.sh
#function of install nginx
updatenginx(){
cd /usr/local/src
[ -f nginx-1.15.9.tar.gz ] || wget http://nginx.org/download/nginx-1.15.9.tar.gz
tar -zxf nginx-1.15.9.tar.gz
cd nginx-1.15.9
myum pcre-devel
[ -d /usr/local/nginx ] && cp -R /usr/local/nginx /usr/local/nginx
date +%s
check_ok
./configure \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-ipv6 \
--with-http_v2_module \
--with-poll_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_dav_module \
--with-http_flv_module
#只编译不安装
make
check_ok
if [ -f /usr/local/nginx/sbin/nginx ]
then
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
check_ok
fi

cp /usr/local/src/nginx-1.15.9/objs/nginx /usr/local/nginx/sbin/
check_ok

kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
check_ok

}

read -p "Initialization completion, Enter (Y) to start update nginx1.15.6 :" n
if [ $n == 'Y' ]
then
echo "Start update==============================================================================================================================>"
update_nginx
echo "The update_nginx make done"
else
echo "Cancel the update."
fi

shell 脚本:------------------------------------------------------------------------------------------------------------------------------

4、脚本授权,运行脚本,并查看nginx版本是否升级成功
chmod o+x
./updata.sh
nginx通过shell脚本平滑升级版本

/usr/local/nginx/sbin/nginx -V
nginx通过shell脚本平滑升级版本

标签:sbin,shell,http,平滑,module,nginx,usr,local
来源: https://blog.51cto.com/byu46123/2360099

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有