linux服務器升級nginx


1、簡介

  有時候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

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM