微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐