nginx版本的平滑升級

 


   nginx版本的平滑升級

    前幾天我同事晚上值班沒事的時候,把公司客戶的一些nginx服務器進行了升級,這種操作我還從來沒有做過,也挺好奇的,今天閒來沒事就在網上找了類似的文檔,進行了操作,並把其過程記錄了下來……

1.查看自己服務器nginx的版本和最早自己編譯安裝是的參數

  1. [root@localhost ~]# /usr/local/nginx/sbin/nginx -V 
  2.  nginx version: nginx/1.2.1 
  3.  built by gcc 4.1.2 20080704 (Red Hat 4.1.2-46) 
  4.  TLS SNI support disabled 
  5.  configure arguments: --prefix=/usr/local --sbin-path=/usr/sbin/nginx \
  6. --conf-path=/usr/local/nginx/conf/nginx.conf \
  7. --error-log-path=/var/log/nginx/error.log \
  8. --http-log-path=/var/log/nginx/access.log \
  9. --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock \
  10. --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module \
  11. --with-http_stub_status_module --with-http_gzip_static_module \
  12. --http-client-body-temp-path=/var/tmp/nginx/client/ \
  13. --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  14. --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  15. --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  16. --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre 

2.在這裏http://nginx.org/en/download.html找到最新的nginx版本,並下載到服務器上

3.對新版本進行解壓並編譯,其中安裝目錄必須和原來的一樣,但是可以添加一些新的參數

  1. [root@localhost ~]# tar xvf nginx-1.2.4.tar.gz   
  2. [root@localhost ~]# cd nginx-1.2.4 
  3. [root@localhost nginx-1.2.4]# ./configure --prefix=/usr/local \ 
  4.   --sbin-path=/usr/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf \ 
  5.   --error-log-path=/var/log/nginx/error.log \ 
  6.   --http-log-path=/var/log/nginx/access.log \ 
  7.   --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock \ 
  8.   --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module \ 
  9.   --with-http_stub_status_module --with-http_gzip_static_module \ 
  10.   --http-client-body-temp-path=/var/tmp/nginx/client/ \ 
  11.   --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 
  12.   --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ 
  13.   --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ 
  14.   --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre 

4.只執行make命令,不需要make install

  1. [root@localhost nginx-1.2.4]# make 

5.替換nginx的一個二進制文件

  1. [root@localhost nginx-1.2.4]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak  
  2. [root@localhost nginx-1.2.4]# cp objs/nginx /usr/local/nginx/sbin/ 

6.進行測試是否成功

  1. [root@localhost nginx-1.2.4]# /usr/local/nginx/sbin/nginx -t 
  2.  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 
  3.  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful 

7.執行命令進行平滑升級

  1. [root@localhost nginx-1.2.4]# make upgrade
  2.  /usr/sbin/nginx -t 
  3.  nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok 
  4.  nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful 
  5.  kill -USR2 `cat /var/run/nginx/nginx.pid` 
  6.  sleep 1 
  7.  test -f /var/run/nginx/nginx.pid.oldbin 
  8.  kill -QUIT `cat /var/run/nginx/nginx.pid.oldbin` 

make upgrade執行命令後顯示的信息,其實顯示的就是都執行了哪幾個命令,也可以自己手動執行那個kill命令

8.在次查看版本信息

  1. [root@localhost nginx-1.2.4]# /usr/local/nginx/sbin/nginx -V  
  2.  nginx version: nginx/1.2.4 
  3.  built by gcc 4.1.2 20080704 (Red Hat 4.1.2-46) 
  4.  TLS SNI support disabled 
  5.  configure arguments: --prefix=/usr/local --sbin-path=/usr/sbin/nginx 
  6. --conf-path=/usr/local/nginx/conf/nginx.conf \
  7. --error-log-path=/var/log/nginx/error.log \
  8. --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid \
  9. --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx \
  10. --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module \
  11. --with-http_gzip_static_module \
  12. --http-client-body-temp-path=/var/tmp/nginx/client/ 
  13. --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  14. --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  15. --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  16. --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre 

nginx升級完成!

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章