Nginx的平滑升級

Nginx的平滑升級

一、查看原先系統Nginx版本和編譯參數並記錄

[root@localhost ~]# nginx -v
nginx version: nginx/1.13.12

[root@localhost ~]# nginx -V
nginx version: nginx/1.13.12
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
configure arguments: --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-http_xslt_module --with-pcre

二、下載最新版本Nginx並解壓

[root@localhost ~]# wget http://nginx.org/download/nginx-1.14.1.tar.gz
--2018-11-15 02:24:36--  http://nginx.org/download/nginx-1.14.1.tar.gz
Resolving nginx.org (nginx.org)... 95.211.80.227, 206.251.255.63, 2001:1af8:4060:a004:21::e3, ...
Connecting to nginx.org (nginx.org)|95.211.80.227|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1014040 (990K) [application/octet-stream]
Saving to: ‘nginx-1.14.1.tar.gz’

100%[==================================================================================================================================>] 1,014,040    117KB/s   in 7.6s   

2018-11-15 02:24:44 (130 KB/s) - ‘nginx-1.14.1.tar.gz’ saved [1014040/1014040]

[root@localhost ~]# tar -zxf nginx-1.14.1.tar.gz

三、編譯Nginx 1.14.1

[root@localhost ~]# cd nginx-1.14.1

[root@localhost nginx-1.14.1]# ./configure --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-http_xslt_module --with-pcre

[root@localhost nginx-1.14.1]# make    #到make這一步便可,不須要執行make install

四、備份原來的nginx啓動腳本

[root@localhost nginx-1.14.1]# cd /usr/local/nginx/sbin/

[root@localhost sbin]# mv nginx nginx_old

五、拷貝nginx-1.14.1目錄下的obj目錄下的nginx到nginx的sbin目錄下

[root@localhost sbin]# cp /root/nginx-1.14.1/objs/nginx /usr/local/nginx/sbin/

六、回到nginx-1.14.1目錄下執行make upgrade

[root@localhost sbin]# cd /root/nginx-1.14.1

[root@localhost nginx-1.14.1]# make upgrade  #這一步會將結束舊進程,並開啓新的進程進行管理nginx的任務,從而達到平滑升級的效果
/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`

這裏須要注意的是,使用make upgrade進行平滑升級時,會默認發送USR2信號到/usr/local/nginx/logs/nginx.pid,可是若是你的pid文件位置不一致,就會出現文件不存在的ERROR
而咱們須要作的是,放棄使用make upgrade,而是直接使用如下命令,假設nginx.pid的路徑爲:/var/run/nginx.pid
[root@localhost nginx-1.14.1]# /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
[root@localhost nginx-1.14.1]# kill -USR2 `cat /var/run/nginx.pid`
此時會在/var/run/下生成一個nginx.pid.oldbin的pid文件
[root@localhost nginx-1.14.1]# kill -QUIT `cat /var/run/nginx.pid.oldbin`  #退出舊進程

七、查看nginx的最新版本

[root@localhost nginx-1.14.1]# nginx -v
nginx version: nginx/1.14.1

[root@localhost nginx-1.14.1]# nginx -V
nginx version: nginx/1.14.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
configure arguments: --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_addition_module --with-http_xslt_module --with-pcre
相關文章
相關標籤/搜索