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

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脚本平滑升级版本

转载于:https://blog.51cto.com/byu46123/2360099

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值