有時候nginx發佈了新BUG或者添加了新的功能時,想要更新的時候服務又不能中斷,這時候就要用到nginx的平滑升級了。html
該腳本一樣適用於添加新擴展,添加新擴展的時候只須要把更新的版本修改成當前版本,更新的時候把須要添加的擴展加上去便可。nginx
我這裏nginx安裝目錄爲/usr/local/nginxshell
當前系統,阿里雲ECS CentOS 7.4 64位bash
# /usr/local/nginx/sbin/nginx -V阿里雲
這裏的擴展要記錄下來(重要),等下升級的時候用到,若是有須要添加新信息能夠一塊兒編譯。spa
cnl_function.sh cnl_install_lnmp_init.sh 下載地址code
更新的時候請修改本身的安裝目錄htm
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腳本目錄執行該腳本,按提示執行便可。blog
執行完能夠看到nginx版本已經升級爲1.15.6ip