詳細完整記錄 一次 nginx 平滑升級

今天忽然收到百度雲郵件提醒,發現高危漏洞。嚇得我趕忙登錄百度雲查看,原來是nginx 的舊版本有漏洞,須要升級nginx

問題是服務器上運行着不少服務,如何平滑的進行升級呢?接下來看我表演,哈哈面試

第一步 準備工做

1 查看當前的版本信息:

執行以下命令:/usr/local/nginx/sbin/nginx -V
小程序

nginx version: nginx/1.1.10
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_addition_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-http_v2_module

複製代碼

顯示當前版本爲1.1.10 ,最後面有configure arguments: 參數比較重要,接下來新版本須要用到,保證沒有漏掉任何一個模塊
bash

2 下載要升級的版本

我下載的是1.14.2 版本服務器

第二步 在源碼目錄下執行 ./configure +第一步看到的configure arguments 後面的參數

如下是我執行的內容ui

./configure --prefix=/usr/local/nginx \
--with-http_addition_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_dav_module --with-http_v2_module 
複製代碼

第三步 在源碼目錄下執行 make,切記不要make install

此時make編譯完後會在安裝目錄下生成一個objs目錄且在該目錄下有一個nginx執行文件。spa

[root@xxxxx nginx-1.14.2]# make
make -f objs/Makefile
make[1]: Entering directory `/usr/local/download/nginx-1.14.2' cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/nginx.o \ src/core/nginx.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_log.o \ src/core/ngx_log.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_palloc.o \ src/core/ngx_palloc.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_array.o \ src/core/ngx_array.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_list.o \ src/core/ngx_list.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_hash.o \ src/core/ngx_hash.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ -o objs/src/core/ngx_buf.o \ src/core/ngx_buf.c cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \ 複製代碼

第四步 備份原來老的nginx文件

主要是爲了回退unix

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
複製代碼

第五步 將新編譯的目錄copy 到 原來的安裝目錄下

如下是我本機的操做命令code

cp objs/nginx /usr/local/nginx/sbin/

複製代碼

第六步 在源碼目錄下使用make upgrade替換老的nginx進程

[root@xxx nginx-1.14.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`

複製代碼

第七步 執行/usr/local/nginx/sbin/nginx -V查看nginx最新的版本及編譯的參數

[root@xxxx nginx-1.14.2]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_addition_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-http_v2_module

複製代碼

好了,大功告成cdn

看完兩件事

若是你以爲這篇內容對你挺有啓發,我想邀請你幫我2個小忙:

  1. 點贊,讓更多的人也能看到這篇內容(收藏不點贊,都是耍流氓 -_-)
  2. 關注公衆號「面試bat」,不按期分享原創知識,原創不易,請多支持(裏面還提供刷題小程序哦)。

相關文章
相關標籤/搜索