、简介
有时候nginx发布了新BUG或者添加了新的功能时,想要更新的时候服务又不能中断,这时候就要用到nginx的平滑升级了。
该脚本同样适用于添加新扩展,添加新扩展的时候只需要把更新的版本修改为当前版本,更新的时候把需要添加的扩展加上去即可。
我这里nginx安装目录为/usr/local/nginx
当前系统,阿里云ECS CentOS 7.4 64位
2、查看nginx版本与编译信息
# /usr/local/nginx/sbin/nginx -V
这里的扩展要记录下来(重要),等下升级的时候用到,如果有需要添加新信息可以一起编译。
2、使用shell升级
cnl_function.sh cnl_install_lnmp_init.sh 下载地址
更新的时候请修改自己的安装目录
复制代码
1 #!/bin/bash
2 source ./cnl_function.sh
3 source ./cnl_install_lnmp_init.sh
4 #function of install nginx
5 update_nginx(){
6 cd /usr/local/src
7 [ -f nginx-1.15.6.tar.gz ] || wget http://nginx.org/download/nginx-1.15.6.tar.gz
8 tar -zxf nginx-1.15.6.tar.gz
9 cd nginx-1.15.6
10 myum pcre-devel
11 [ -d /usr/local/nginx ] && cp -R /usr/local/nginx /usr/local/nginx_`date +%s`
12 check_ok
13 ./configure \
14 --prefix=/usr/local/nginx \
15 --with-http_stub_status_module \
16 --with-http_ssl_module \
17 --with-ipv6 \
18 --with-http_v2_module \
19 --with-poll_module \
20 --with-http_realip_module \
21 --with-http_sub_module \
22 --with-http_gzip_static_module \
23 --with-http_dav_module \
24 --with-http_flv_module
25 #只编译不安装
26 make
27 check_ok
28 if [ -f /usr/local/nginx/sbin/nginx ]
29 then
30 mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
31 check_ok
32 fi
33
34 cp /usr/local/src/nginx-1.15.6/objs/nginx /usr/local/nginx/sbin/
35 check_ok
36
37 kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
38 check_ok
39
40 }
41
42 read -p "Initialization completion, Enter (Y) to start update nginx1.15.6 :" n
43 if [ $n == 'Y' ]
44 then
45 echo "Start update==============================================================================================================================>"
46 update_nginx
47 echo "The update_nginx make done"
48 else
49 echo "Cancel the update."
50 fi
复制代码
进到shell脚本目录执行该脚本,按提示执行即可。
执行完可以看到nginx版本已经升级为1.15.6
https://www.cnblogs.com/chennl/p/10172060.html