Nginx平滑升級及回滾實(shí)驗(yàn)
一、實(shí)驗(yàn)核心目的
Nginx是生產(chǎn)環(huán)境中最常用的Web服務(wù)器/反向代理,平滑升級/回滾 是為了在不中斷業(yè)務(wù)(用戶無感知)的前提下,完成Nginx版本更新或故障回退。如果直接stop/start Nginx,會導(dǎo)致短暫的服務(wù)不可用,這在生產(chǎn)環(huán)境是絕對不允許的,本實(shí)驗(yàn)就是解決這個核心問題。
二、實(shí)驗(yàn)整體流程拆解
整個實(shí)驗(yàn)分為3個核心階段:下載新版本源碼→編譯并平滑升級→版本回滾,下面逐階段講解。
1.下載高版本的軟件
[root@Nginx ~]# wget https://nginx.org/download/nginx-1.29.4.tar.gz
2.對于新版本的軟件進(jìn)行源碼編譯并進(jìn)行平滑升級
#編譯nginx隱藏版本 [root@Nginx ~]# tar zxf nginx-1.29.4.tar.gz [root@Nginx ~]# cd nginx-1.29.4/src/core/ [root@Nginx core]# vim nginx.h #define nginx_version 1029004 #define NGINX_VERSION "" #define NGINX_VER "TIMINGLEE/" NGINX_VERSION #文件編輯完成后進(jìn)行源碼編譯即可 [root@Nginx core]# cd ../../ [root@Nginx nginx-1.29.4]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module [root@Nginx nginx-1.29.4]# make [root@Nginx nginx-1.29.4]# cd objs/ [root@Nginx objs]# ls autoconf.err nginx ngx_auto_config.h ngx_modules.c src Makefile nginx.8 ngx_auto_headers.h ngx_modules.o [root@Nginx objs]# cd /usr/local/nginx/sbin/ [root@Nginx sbin]# ls nginx [root@Nginx sbin]#cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old -p [root@Nginx sbin]# \cp -f /root/nginx-1.29.4/objs/nginx /usr/local/nginx/sbin/nginx [root@Nginx sbin]# ls /usr/local/nginx/logs/ access.log error.log nginx.pid [root@Nginx sbin]# ps aux | grep nginx root 1643 0.0 0.1 14688 2360 ? Ss 09:55 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 1644 0.0 0.2 14888 3896 ? S 09:55 0:00 nginx: worker process [root@Nginx sbin]# kill -USR2 1643 #nginx master進(jìn)程id [root@Nginx sbin]# ps aux | grep nginx root 1643 0.0 0.1 14688 2744 ? Ss 09:55 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 1644 0.0 0.2 14888 3896 ? S 09:55 0:00 nginx: worker process root 4919 0.0 0.4 14716 7936 ? S 10:24 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 4921 0.0 0.2 14916 4156 ? S 10:24 0:00 nginx: worker process root 4923 0.0 0.1 6636 2176 pts/0 S+ 10:25 0:00 grep --color=auto nginx [root@Nginx sbin]# ls /usr/local/nginx/logs/ access.log error.log nginx.pid nginx.pid.oldbin #測試效果 [root@Nginx sbin]# nginx -V nginx version: TIMINGLEE/ built by gcc 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC) built with OpenSSL 3.2.2 4 Jun 2024 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module #回收舊版本子進(jìn)程 [root@Nginx sbin]# ps aux | grep nginx root 1643 0.0 0.1 14688 2744 ? Ss 09:55 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 1644 0.0 0.2 14888 3896 ? S 09:55 0:00 nginx: worker process root 4919 0.0 0.4 14716 7936 ? S 10:24 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 4921 0.0 0.2 14916 4156 ? S 10:24 0:00 nginx: worker process root 4929 0.0 0.1 6636 2176 pts/0 S+ 10:27 0:00 grep --color=auto nginx [root@Nginx sbin]# kill -WINCH 1643 [root@Nginx sbin]# ps aux | grep nginx root 1643 0.0 0.1 14688 2744 ? Ss 09:55 0:00 nginx: process /usr/local/nginx/sbin/nginx root 4919 0.0 0.4 14716 7936 ? S 10:24 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 4921 0.0 0.2 14916 4156 ? S 10:24 0:00 nginx: worker process root 4932 0.0 0.1 6636 2176 pts/0 S+ 10:28 0:00 grep --color=auto nginx
3.版本回退|版本回滾
[root@Nginx sbin]# cd /usr/local/nginx/sbin/ [root@Nginx sbin]# cp nginx nginx.new -p [root@Nginx sbin]# \cp nginx.old nginx -pf [root@Nginx sbin]# ps aux | grep nginx root 1643 0.0 0.1 14688 2744 ? Ss 09:55 0:00 nginx: master process /usr/local/nginx/sbin/nginx root 4919 0.0 0.4 14716 7936 ? S 10:24 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 4921 0.0 0.2 14916 4156 ? S 10:24 0:00 nginx: worker process [root@Nginx sbin]# kill -HUP 1643 [root@Nginx sbin]# ps aux | grep nginx root 1643 0.0 0.1 14688 2744 ? Ss 09:55 0:00 nginx: master process /usr/local/nginx/sbin/nginx root 4919 0.0 0.4 14716 7936 ? S 10:24 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 4921 0.0 0.2 14916 4156 ? S 10:24 0:00 nginx: worker process nginx 4963 0.0 0.2 14888 3896 ? S 10:32 0:00 nginx: worker process root 4965 0.0 0.1 6636 2176 pts/0 S+ 10:32 0:00 grep --color=auto nginx [root@Nginx sbin]# nginx -V nginx version: nginx/1.28.1 built by gcc 11.5.0 20240719 (Red Hat 11.5.0-5) (GCC) built with OpenSSL 3.2.2 4 Jun 2024 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module #回收新版本進(jìn)程 [root@Nginx sbin]# kill -WINCH 4919 [root@Nginx sbin]# ps aux | grep nginx root 1643 0.0 0.1 14688 2744 ? Ss 09:55 0:00 nginx: master process /usr/local/nginx/sbin/nginx root 4919 0.0 0.4 14716 7936 ? S 10:24 0:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 4963 0.0 0.2 14888 3896 ? S 10:32 0:00 nginx: worker process root 4969 0.0 0.1 6636 2176 pts/0 S+ 10:34 0:00 grep --color=auto nginx
Nginx 信號大全(生產(chǎn)常用)

到此這篇關(guān)于Nginx平滑升級及回滾實(shí)驗(yàn)的文章就介紹到這了,更多相關(guān)Nginx平滑升級及回滾內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解Nginx反向代理實(shí)現(xiàn)會話(session)保持的兩種方式
這篇文章主要介紹了詳解Nginx反向代理實(shí)現(xiàn)會話(session)保持的兩種方式,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Ubuntu使用nginx搭建webdav文件服務(wù)器的詳細(xì)過程
今天通過本文給大家分享Ubuntu使用nginx搭建webdav文件服務(wù)器的詳細(xì)過程,在這小編提示大家在安裝nginx時需要先安裝nginx-full,具體安裝方法跟隨小編一起通過本文學(xué)習(xí)下吧2021-05-05

