詳細完整記錄 一次 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: 參數比較重要,接下來新版本需要用到,保證沒有漏掉任何一個模塊

2 下載要升級的版本

我下載的是1.14.2 版本

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

以下是我執行的內容

./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執行文件。

[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文件

主要是爲了回退

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak

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

以下是我本機的操作命令

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

好了,大功告成

推薦下海量面試題小程序讓大家刷刷,哈哈哈哈


博客:http://blog.interviewbat.com

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