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

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

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

2、查看nginx版本与编译信息
/usr/local/nginx/sbin/nginx -V

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

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

/usr/local/nginx/sbin/nginx -V

原文地址:https://blog.51cto.com/byu46123/2360099

时间: 2024-12-09 10:02:01

nginx通过shell脚本平滑升级版本的相关文章

nginx重载配置文件及平滑升级

Nginx命令行选项 启动.停止.重启nginx命令 如何重新加载nginx配置文件 nginx程序不重启平滑升级可执行文件 一.Nginx命令行选项 不像许多其他软件系统,Nginx 仅有几个命令行参数,完全通过配置文件来配置 -c </path/to/config> 为 Nginx 指定一个配置文件,来代替缺省的. -t 不运行,而仅仅测试配置文件.nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件. -v 显示 nginx 的版本. -V 显示 nginx 的版

Nginx平滑升级版本!

一.解释nginx的平滑升级 随着nginx越来越流行使用,并且nginx的优势也越来越明显,nginx的版本迭代也开始了加速模式,1.9.0版本的nginx更新了许多新功能,例如stream四层代理功能.伴随着nginx的广泛应用,版本升级必然是越来越快的,线上业务不能停,此时nginx的升级就是运维的重要工作了,下面就带大家一起来理解下nginx平滑升级. 二.nginx平滑升级原理 多进程模式下的请求分配方式 Nginx默认工作在多进程模式下,即主进程(master process)启动后

nginx添加模块与平滑升级

Nginx 添加第三方模块 众所周知Nginx是分成一个个模块的,比如core模块,gzip模块,proxy模块,每个模块负责不同的功能,除了基本的模块,有些模块可以选择编译或不编译进Nginx.官网文档中的Modules reference部分列出了nginx源码包的所有模块.我们可以按照自己服务器的需要来定制出一个最适合自己的Nginx服务器. 除了Nginx官网源码包提供了各种模块,Nginx还有各种各样的第三方模块.官方文档NGINX 3rd Party Modules也列出了Nginx

Nginx服务器 安装 与平滑升级详细介绍 &nbsp; 简单使用1

#nginx -V (-V 可以显示出当时的标准,添加了什么模块) [[email protected] nginx-1.8.0]# ./configure --help |grep proxy --without-http_proxy_module        disable ngx_http_proxy_module --http-proxy-temp-path=PATH        set path to store http proxy temporary files --with-

nginx编译安装和平滑升级

1.1.1  本文档为nginx安装及配置文档,主要实现http反向代理功能:作用是将nginx作为前端服务器,通过访问规则代理转发至后端对应的tomcat服务器 部署环境: 系统版本:Linux version 2.6.32-431.el6.x86_64(`cat /proc/version`) 安装及配置: 1安装nginx依赖环境 安装pcre库 #wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.21.ta

Nginx在线服务状态下平滑升级或新增模块的详细操作

今天应开发的需求,需要在Nginx增加一个模块,并不能影响现有的业务,所以就必须要平滑升级Nginx,好了,不多说了 1:查看现有的nginx编译参数 /usr/local/nginx/sbin/nginx -V 2:按照安装nginx的方法进行安装,只需要到make,千万不要make install 3: 备份旧版本的nginx可执行文件(期间nginx不会停止服务) mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old

Nginx在线服务状态下平滑升级或新增模块

nginx在使用过程中,有时需要在不影响当前业务的情况下,进行升级或新增模块.nginx的升级有两种方法:1.半自动化升级:2.手动升级 不过都需要先查看安装的nginx版本和配置信息,然后前往官网下载所需的版本,并上传 [[email protected] ~]# nginx -V nginx version: nginx/1.14.1 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --pre

安装nginx 服务shell脚本

!/bin/bash wget http://nginx.org/download/nginx-1.10.2.tar.gz tar -xf nginx-1.10.2.tar.gz cd nginx-1.10.2 yum -y install gcc pcre-devel openssl-devel ./configure make make install

通过shell脚本查看python版本并比较

a.py import sys print(".".join(sys.version.split()[0].split(".")[:2])) test.sh #!/bin/sh zero=0 x=`python a.py` y="3.6" status=`echo "$x >= $y" | bc` echo $status if [[ $status -eq $zero ]];then echo "bu >