1. 程式人生 > >nginx平滑升級(線上)

nginx平滑升級(線上)

nginx


nginx_ngx_cache_purge第三方模塊下載地址,用於清除緩存

http://labs.frickle.com/nginx_ngx_cache_purge/

編譯安裝參數:--user=www --group=www --add-module=/usr/local/src/ngx_cache_purge-2.0 --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

註意:紅色的是添加的第三方還魂模塊解壓後的目錄

1、升級nginx和添加第三方模塊一樣。都要查看原先的nginx版本及編譯參數:

[root@localhost src]#

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

nginx version: nginx/1.12.2

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)

built with OpenSSL 1.0.1e-fips 11 Feb 2013

TLS SNI support enabled

configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.39

2、備份nginx

rsync -avz /usr/local/nginx /usr/local/nginx.bak --exclude=/usr/local/nginx/logs/*

--exclude 指定不備份的文件或者目錄

3、下載nginx的第三方緩存模塊(由於目前nginx已經是最新版本,所以沒升級)

如果是升級nginx版本。就下載nginx的新版本的包,然後解壓。最好也是和之前一樣放在/usr/local/src下面。然後進入解壓目錄,運行上面所查詢到的編譯參數。添加第三方模塊只是在編譯的時候加上紅色部分而已。如下:

[root@localhost nginx-1.12.2]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.39

--add-module=/usr/local/src/ngx_cache_purge-2.3

標紅的這個是第三方模塊解壓出來的目錄,用--add-module 指定一下即可

4、編譯完成之後,再進行make 切記,千萬不能make install

[root@localhost nginx-1.12.2]# make

5、make 編譯完,在objs目錄下有一個nginx執行文件

5.1、首先備份老的nginx的可執行文件

cp -a /usr/local/nginx/sbin/nginx{,.bak}

5.2、把objs下新的nginx可執行文件拷貝到/usr/local/nginx/sbin下

\cp objs/nginx /usr/local/nginx/sbin/ -f

5、測試一下查看是否有問題

[root@localhost nginx-1.12.2]# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

這樣表示沒問題

6、使用make upgrade 替換老的nginx進程 進行平滑升級

[root@localhost nginx-1.12.2]# make upgrade

/usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`

sleep 1

test -f /usr/local/nginx/logs/nginx.pid.oldbin

kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

7、再次執行:/usr/local/nginx/sbin/nginx -V 將會顯示新的nginx的版本及編譯的參數

[root@localhost nginx-1.12.2]# /usr/local/nginx/sbin/nginx -V

nginx version: nginx/1.12.2

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)

built with OpenSSL 1.0.1e-fips 11 Feb 2013

TLS SNI support enabled

configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre=/usr/local/src/pcre-8.39 --add-module=/usr/local/src/ngx_cache_purge-master

至此,nginx平滑升級完成



nginx平滑升級(線上)