最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

nginx后端節(jié)點(diǎn)的健康檢查和nginx平滑升級(jí)方式

 更新時(shí)間:2026年04月16日 08:49:42   作者:新手小白*  
本文介紹了Nginx反向代理的ngx_http_proxy_module和ngx_http_upstream_module模塊,以及淘寶開發(fā)的nginx_upstream_check_module模塊,并介紹了Nginx平滑升級(jí)原理及實(shí)戰(zhàn)操作,最后總結(jié)了Nginx版本升級(jí)的方法

簡介:

本文主要介紹nginx后端節(jié)點(diǎn)的健康檢查,在此之前我們先來介紹下nignx反向代理主要使用的模塊。

一、nginx原生模塊介紹

我們?cè)谑褂胣ginx做反向代理都會(huì)使用到以下兩個(gè)模塊:

1、ngx_http_proxy_module

定義允許將請(qǐng)求傳遞到另一臺(tái)服務(wù)器。

此模塊下常用指令如下:

proxy_pass
proxy_cache
proxy_connect_timeout
proxy_read_timeout
proxy_send_timeout
proxy_next_upstream

2、ngx_http_upstream_module

用于定義可由proxy_pass,fastcgi_pass等指令引用的服務(wù)器組。

此模塊下常用指令如下:

upstream
server
ip_hash

默認(rèn)負(fù)載均衡配置

http {
    upstream myapp1 {
        server srv1.example.com;
        server srv2.example.com;
        server srv3.example.com;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://myapp1;
        }
    }
}

此時(shí)nginx默認(rèn)的負(fù)載均衡策略是輪詢外,還有其他默認(rèn)參數(shù),如下:

http {
    upstream myapp1 {
        server srv1.example.com weight=1 max_fails=1 fail_timeout=10;
        server srv2.example.com weight=1 max_fails=1 fail_timeout=10;
        server srv3.example.com weight=1 max_fails=1 fail_timeout=10;
    }

    server {
        listen 80;
        proxy_send_timeout=60;
        proxy_connect_timeout=60;
        proxy_read_timeout=60;
        proxy_next_upstream=error timeout;

        location / {
            proxy_pass http://myapp1;
        }
    }
}

其中:

1.故障轉(zhuǎn)移(了解)

Syntax(語法): 	proxy_read_timeout time;
Default(默認(rèn)): 	
proxy_read_timeout 60s;
Context(上下文,能夠書寫該字段的位置): 	http, server, location
#定義從代理服務(wù)器讀取響應(yīng)的超時(shí)。 僅在兩個(gè)連續(xù)的讀操作之間設(shè)置超時(shí),而不是為整個(gè)響應(yīng)的傳輸。 如果代理服務(wù)器在此時(shí)間內(nèi)未傳輸任何內(nèi)容,則關(guān)閉連接。

Syntax: 	proxy_connect_timeout time;
Default: 	
proxy_connect_timeout 60s;
Context: 	http, server, location
#定義與代理服務(wù)器建立連接的超時(shí)。 應(yīng)該注意,此超時(shí)通常不會(huì)超過75秒。


Syntax: 	proxy_send_timeout time;
Default: 	
proxy_send_timeout 60s;
Context: 	http, server, location
#設(shè)置將請(qǐng)求傳輸?shù)酱矸?wù)器的超時(shí)。 僅在兩個(gè)連續(xù)的寫操作之間設(shè)置超時(shí),而不是為整個(gè)請(qǐng)求的傳輸。 如果代理服務(wù)器在此時(shí)間內(nèi)未收到任何內(nèi)容,則關(guān)閉連接

Syntax: 	proxy_next_upstream error | timeout | invalid_header | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | http_429 | non_idempotent | off ...;
Default: 	
proxy_next_upstream error timeout;
Context: 	http, server, location
#指定在何種情況下一個(gè)失敗的請(qǐng)求應(yīng)該被發(fā)送到下一臺(tái)后端服務(wù)器:
#error      和后端服務(wù)器建立連接時(shí),或者向后端服務(wù)器發(fā)送請(qǐng)求時(shí),或者從后端服務(wù)器接收響應(yīng)頭時(shí),出現(xiàn)錯(cuò)誤
#timeout    和后端服務(wù)器建立連接時(shí),或者向后端服務(wù)器發(fā)送請(qǐng)求時(shí),或者從后端服務(wù)器接收響應(yīng)頭時(shí),出現(xiàn)超時(shí)
#invalid_header  后端服務(wù)器返回空響應(yīng)或者非法響應(yīng)頭
#http_500   后端服務(wù)器返回的響應(yīng)狀態(tài)碼為500
#http_502   后端服務(wù)器返回的響應(yīng)狀態(tài)碼為502
#http_503   后端服務(wù)器返回的響應(yīng)狀態(tài)碼為503
#http_504   后端服務(wù)器返回的響應(yīng)狀態(tài)碼為504
#http_404   后端服務(wù)器返回的響應(yīng)狀態(tài)碼為404
#off        停止將請(qǐng)求發(fā)送給下一臺(tái)后端服務(wù)器

從以上幾個(gè)指令可以看出,在默認(rèn)配置下,后端節(jié)點(diǎn)一旦出現(xiàn)error和timeout情況時(shí),nginx會(huì)通過proxy_next_upstream進(jìn)行故障轉(zhuǎn)移,將發(fā)往不健康節(jié)點(diǎn)的請(qǐng)求,自動(dòng)轉(zhuǎn)移至健康節(jié)點(diǎn)。

其中timeout設(shè)置和proxy_send_timeout time、proxy_connect_timeout time、proxy_read_timeout time有關(guān)。除了error、timeout,我們可以設(shè)置更詳細(xì)的觸發(fā)條件,如http_502、http_503等。

注意:只有在沒有向客戶端發(fā)送任何數(shù)據(jù)以前,將請(qǐng)求轉(zhuǎn)給下一臺(tái)后端服務(wù)器才是可行的。也就是說,如果在傳輸響應(yīng)到客戶端時(shí)出現(xiàn)錯(cuò)誤或者超時(shí),這類錯(cuò)誤是不可能恢復(fù)的。

2.健康檢查

Syntax: 	server address [parameters];
Default: 	—
Context: 	upstream
max_fails=number   設(shè)定Nginx與服務(wù)器通信的嘗試失敗的次數(shù)。在fail_timeout參數(shù)定義的時(shí)間段內(nèi),如果失敗的次數(shù)達(dá)到此值,Nginx就認(rèn)為服務(wù)器不可用。此時(shí)在接下來的fail_timeout時(shí)間段,服務(wù)器不會(huì)再被嘗試。失敗的嘗試次數(shù)默認(rèn)是1。設(shè)為0就會(huì)停止統(tǒng)計(jì)嘗試次數(shù),即不對(duì)后端節(jié)點(diǎn)進(jìn)行健康檢查。認(rèn)為服務(wù)器是一直可用的。

fail_timeout=time  設(shè)定服務(wù)器被認(rèn)為不可用的時(shí)間段以及統(tǒng)計(jì)失敗嘗試次數(shù)的時(shí)間段。在這段時(shí)間中,服務(wù)器失敗次數(shù)達(dá)到指定的嘗試次數(shù),服務(wù)器就被認(rèn)為不可用。
默認(rèn)情況下,該超時(shí)時(shí)間是10秒。

以上有幾點(diǎn)需要解釋:

  • 1.失敗次數(shù)中的失敗是怎么定義的?官網(wǎng)解釋是指由proxy_next_upstream,fastcgi_next_upstream,uwsgi_next_upstream,scgi_next_upstream,memcached_next_upstream和grpc_next_upstream指令定義,也是前面說的error、time、http_xxx狀態(tài)碼等。
  • 2.如果mail_fail為0,此時(shí)健康檢查無效。因此此時(shí)整個(gè)nginx,只會(huì)由proxy_next_upstream判斷,進(jìn)行相關(guān)故障轉(zhuǎn)移。

小結(jié)

在使用nginx上述的兩個(gè)模塊由以下缺點(diǎn):

  • 1.fail_time內(nèi)的失敗檢測,超時(shí)時(shí)間以系統(tǒng)設(shè)置為主,效率低,等待超時(shí)影響性能;
  • 2.后端一旦有問題,除后端禁用的fail_time時(shí)間段,其他時(shí)間nginx會(huì)把請(qǐng)求轉(zhuǎn)發(fā)給不健康節(jié)點(diǎn)的,然后再轉(zhuǎn)發(fā)給別的服務(wù)器,這樣以來就浪費(fèi)了一次轉(zhuǎn)發(fā)。

因此除了上面介紹的nginx自帶模塊,還有一個(gè)更專業(yè)的模塊,來專門提供負(fù)載均衡器內(nèi)節(jié)點(diǎn)的健康檢查的。這個(gè)就是淘寶技術(shù)團(tuán)隊(duì)開發(fā)的nginx模塊。

二、nginx_upstream_check_module模塊

借助淘寶技術(shù)團(tuán)隊(duì)開發(fā)的nginx??靚ginx_upstream_check_module來檢測后方realserver的健康狀態(tài),如果后端服務(wù)器不可用,則會(huì)將其踢出upstream,所有的請(qǐng)求不轉(zhuǎn)發(fā)到這臺(tái)服務(wù)器。當(dāng)期恢復(fù)正常時(shí),將其加入upstream。

在淘寶自己的tengine上是自帶了該模塊的,大家可以訪問淘寶Tengine官網(wǎng)來獲取該版本的nginx,也可以到Gitbub

如果沒有使用淘寶的tengine的話,可以通過補(bǔ)丁的方式來添加該模塊到我們自己的nginx中。

下載地址1:https://github.com/yaoweibin/nginx_upstream_check_module

#打補(bǔ)丁
#注意不同版本對(duì)應(yīng)的補(bǔ)丁
cd nginx-1.6.0
patch -p1 < ../nginx_upstream_check_module-master/check_1.5.12+.patch
 ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx1.6 --sbin-path=/usr/local/nginx1.6 --conf-path=/usr/local/nginx1.6/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_sub_module --with-pcre=/usr/local/src/nginx/pcre-8.36 --with-zlib=/usr/local/src/nginx/zlib-1.2.8 --add-module=/usr/local/src/nginx/ngx_cache_purge-2.1 --add-module=/usr/local/src/nginx/headers-more-nginx-module-master --add-module=/usr/local/src/nginx/nginx_upstream_check_module-master

make
#不要執(zhí)行make install命令

cd /usr/local/nginx1.6
#備份命令
cp nginx nginx.bak
nginx -s stop
cp -r /usr/local/src/nginx/nginx-1.6.0/objs/nginx .

打完補(bǔ)丁后,可進(jìn)行如下配置:

 http {

        upstream cluster {

            # simple round-robin

            server 192.168.0.1:80;
            server 192.168.0.2:80;

            check interval=5000 rise=1 fall=3 timeout=4000;

            #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello;

            #check interval=3000 rise=2 fall=5 timeout=1000 type=http;
            #check_http_send "HEAD / HTTP/1.0\r\n\r\n";
            #check_http_expect_alive http_2xx http_3xx;
        }

        server {
            listen 80;

            location / {
                proxy_pass http://cluster;
            }

            location /status {
                check_status;

                access_log   off;
                allow SOME.IP.ADD.RESS;
                deny all;
           }
        }

    }

其中:

Syntax:  check interval=milliseconds [fall=count] [rise=count] [timeout=milliseconds] [default_down=true|false] [type=tcp|http|ssl_hello|mysql|ajp] [port=check_port]
Default: 如果沒有配置參數(shù),默認(rèn)值是:interval=30000 fall=5 rise=2 timeout=1000 default_down=true type=tcp
Context: upstream
 
該指令可以打開后端服務(wù)器的健康檢查功能。指令后面的參數(shù)意義是:
interval:向后端發(fā)送的健康檢查包的間隔,單位為毫秒。
fall(fall_count): 如果連續(xù)失敗次數(shù)達(dá)到fall_count,服務(wù)器就被認(rèn)為是down。
rise(rise_count): 如果連續(xù)成功次數(shù)達(dá)到rise_count,服務(wù)器就被認(rèn)為是up。
timeout: 后端健康請(qǐng)求的超時(shí)時(shí)間,單位毫秒。
default_down: 設(shè)定初始時(shí)服務(wù)器的狀態(tài),如果是true,就說明默認(rèn)是down的,如果是false,就是up的。默認(rèn)值是true,也就是一開始服務(wù)器認(rèn)為是不可用,要等健康檢查包達(dá)到一定成功次數(shù)以后才會(huì)被認(rèn)為是健康的。
type:健康檢查包的類型,現(xiàn)在支持以下多種類型:
     tcp:簡單的tcp連接,如果連接成功,就說明后端正常。
     ssl_hello:發(fā)送一個(gè)初始的SSL hello包并接受服務(wù)器的SSL hello包。
     http:發(fā)送HTTP請(qǐng)求,通過后端的回復(fù)包的狀態(tài)來判斷后端是否存活。
     mysql: 向mysql服務(wù)器連接,通過接收服務(wù)器的greeting包來判斷后端是否存活。
     ajp:向后端發(fā)送AJP協(xié)議的Cping包,通過接收Cpong包來判斷后端是否存活。
     port: 指定后端服務(wù)器的檢查端口。你可以指定不同于真實(shí)服務(wù)的后端服務(wù)器的端口,比如后端提供的是443端口的應(yīng)用,你可以去檢查80端口的狀態(tài)來判斷后端健康狀況。默認(rèn)是0,表示跟后端server提供真實(shí)服務(wù)的端口一樣。該選項(xiàng)出現(xiàn)于Tengine-1.4.0。
     
Syntax: check_keepalive_requests request_num
Default: 1
Context: upstream
該指令可以配置一個(gè)連接發(fā)送的請(qǐng)求數(shù),其默認(rèn)值為1,表示Tengine完成1次請(qǐng)求后即關(guān)閉連接。
 
Syntax: check_http_send http_packet
Default: "GET / HTTP/1.0\r\n\r\n"
Context: upstream
該指令可以配置http健康檢查包發(fā)送的請(qǐng)求內(nèi)容。為了減少傳輸數(shù)據(jù)量,推薦采用"HEAD"方法。
 
當(dāng)采用長連接進(jìn)行健康檢查時(shí),需在該指令中添加keep-alive請(qǐng)求頭,如:"HEAD / HTTP/1.1\r\nConnection: keep-alive\r\n\r\n"。 同時(shí),在采用"GET"方法的情況下,請(qǐng)求uri的size不宜過大,確??梢栽?個(gè)interval內(nèi)傳輸完成,否則會(huì)被健康檢查模塊視為后端服務(wù)器或網(wǎng)絡(luò)異常。

Syntax: check_http_expect_alive [ http_2xx | http_3xx | http_4xx | http_5xx ]
Default: http_2xx | http_3xx
Context: upstream
該指令指定HTTP回復(fù)的成功狀態(tài),默認(rèn)認(rèn)為2XX和3XX的狀態(tài)是健康的。

例子如下:

server{
        listen 80;
        
        upstream test{
        	server 192.168.3.12:8080 weight=5 max_fails=3 fail_timeout=10s;
       		server 192.168.3.13:8080 weight=5 max_fails=3 fail_timeout=10s;
       		 
        	check interval=5000 rise=1 fall=3 timeout=4000 type=http default_down=false;
      		check_http_send "HEAD /index.html HTTP/1.0\r\n\r\n";
      	 	check_http_expect_alive http_2xx http_3xx;
       }

        location / {

                proxy_set_header X-Real-IP        $remote_addr;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_pass http://test;
                proxy_next_upstream error timeout  http_500 http_502 http_503;
        }
	#后端階段健康狀態(tài)監(jiān)控
        location /status {
                check_status;
                access_log off;
        }
}

以上我們同時(shí)使用了nginx原生的及淘寶的健康檢查模塊,但是淘寶的間隔時(shí)是毫秒級(jí),而且可以自定義監(jiān)控url,定制監(jiān)控頁,響應(yīng)速度快,比原生的敏感度要高。

三、使用阿里巴巴的tengine實(shí)現(xiàn)后端節(jié)點(diǎn)狀態(tài)檢查

1、安裝tengine

unzip tengine-3.1.0.zip
cd tengine-3.1.0/
./configure --prefix=/usr/local/tengine --add-module=/root/tengine-3.1.0/modules/ngx_http_upstream_check_module && make && make install

2、修改配置文件

user  nginx;
worker_processes  1;
error_log  logs/error.log  info;
error_log  "pipe:rollback logs/error_log interval=1d baknum=7 maxsize=2G";
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    access_log  "pipe:rollback logs/access_log interval=1d baknum=7 maxsize=2G"  main;
    sendfile        on;
    keepalive_timeout  65;
    gzip  on;
    upstream webs {
        
		    server 192.168.166.10:80;
		    server 192.168.166.13:80;
            check interval=5000 rise=1 fall=3 timeout=4000 type=http default_down=false;
      		check_http_send "HEAD /index.html HTTP/1.0\r\n\r\n";
      	 	check_http_expect_alive http_2xx http_3xx;
    }
    server {
        listen       80;
        server_name  localhost;
        location / {
            proxy_pass http://webs;
        }
        location /status {
            check_status html;
            access_log   off;
            allow all;
            deny all;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

3.1 Nginx平滑升級(jí)原理

  • 在不停掉老進(jìn)程的情況下,啟動(dòng)新進(jìn)程。
  • 老進(jìn)程負(fù)責(zé)處理仍然沒有處理完的請(qǐng)求,但不再接受處理請(qǐng)求。
  • 新進(jìn)程接受新請(qǐng)求。
  • 老進(jìn)程處理完所有請(qǐng)求,關(guān)閉所有連接后,停止。

3.2 Nginx信號(hào)

3.2.1主進(jìn)程支持的信號(hào)
  • TERM,INT:立刻退出;
  • QUIT:等待工作進(jìn)程結(jié)束后再退出;
  • KILL:強(qiáng)制終止進(jìn)程;
  • HUP:重新加載配置文件,使用新的配置啟動(dòng)工作進(jìn)程,并逐步關(guān)閉舊進(jìn)程;
  • USR1:重新打開日志文件;
  • USR2:啟動(dòng)新的主進(jìn)程,實(shí)現(xiàn)熱升級(jí);
  • WINCH:逐步關(guān)閉工作進(jìn)程。
3.2.2 工作進(jìn)程支持的信號(hào)
  • TERM,INT:立刻退出;
  • QUIT:等待請(qǐng)求處理結(jié)束后再退出;
  • USR1:重新打開日志文。

3.3 平滑升級(jí)實(shí)戰(zhàn)

3.3.1 Nginx添加新模塊

在已編譯安裝Nginx的基礎(chǔ)上添加–with-http_image_filter_module模塊。

(1)進(jìn)入Nginx解壓目錄

[root@nginx-proxy ~]# cd /usr/local/nginx-1.18.0/

(2)查看Nginx已安裝的模塊

[root@nginx-proxy nginx-1.18.0]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
configure arguments: --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi

(3)添加新模塊

[root@nginx-proxy nginx-1.18.0]# ./configure --prefix=/usr/local/nginx --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --with-http_image_filter_module

(4)進(jìn)行make操作

按照原來的編譯參數(shù)安裝 nginx 的方法進(jìn)行安裝,只需要到 make,千萬不要 make install 。如果make install 會(huì)將原來的配置文件覆蓋。下面給Nginx添加–with-http_image_filter_module模塊。

[root@nginx-proxy nginx-1.18.0]# make

(5)備份原Nginx二進(jìn)制文件

[root@nginx-proxy nginx-1.18.0]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
#備份的命令必須在當(dāng)前路徑下

(6)復(fù)制新的nginx二進(jìn)制文件,進(jìn)入新的nginx源碼包

[root@nginx-proxy nginx-1.18.0]# cp /usr/local/nginx-1.18.0/objs/nginx /usr/local/nginx/sbin/

(7)測試新版本的nginx是否正常

[root@nginx-proxy nginx-1.18.0]# /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

(8)給nginx發(fā)送平滑遷移信號(hào)

若不清楚Nginx.pid的路徑,可查看nginx配置文件,里面有對(duì)應(yīng)的路徑。

[root@nginx-proxy logs]# kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`

(9)查看nginx pid,會(huì)出現(xiàn)一個(gè)nginx.pid.oldbin

即在不停掉老進(jìn)程的情況下啟動(dòng)新進(jìn)程。

[root@nginx-proxy ~]# ll /usr/local/nginx/logs/
total 8
-rw-r--r-- 1 root root 5 Sep 25 13:32 nginx.pid
-rw-r--r-- 1 root root 5 Sep 25 13:27 nginx.pid.oldbin

(10)關(guān)閉舊的Nginx進(jìn)程

[root@nginx-proxy ~]# kill -WINCH `cat /usr/local/nginx/logs/nginx.pid.oldbin`

(11)結(jié)束工作進(jìn)程,完成此次升級(jí)

[root@nginx-proxy ~]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

(12)驗(yàn)證Nginx是否升級(jí)成功

[root@nginx-proxy ~]# /usr/local/nginx/sbin/nginx -V

3.3.2 Nginx版本升級(jí)

安裝Nginx1.6版本

(1)下載Nginx1.6/1.18版本包

[root@zrs ~]# wget http://nginx.org/download/nginx-1.6.3.tar.gz
[root@zrs ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz

(2)安裝依賴環(huán)境

[root@zrs ~]# yum install -y gcc gcc-c++ pcre-devel openssl-devel zlib-devel

(3)進(jìn)行安裝

[root@zrs ~]# tar zxf  nginx-1.6.3.tar.gz -C /usr/local/
[root@zrs ~]# cd /usr/local/nginx-1.6.3/
[root@zrs nginx-1.6.3]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[root@zrs nginx-1.6.3]# make && make install
[root@zrs nginx-1.6.3]# useradd -M -s /sbin/nologin nginx

(4)啟動(dòng)Nginx服務(wù)

[root@zrs nginx-1.6.3]# /usr/local/nginx/sbin/nginx      #啟動(dòng)Nginx服務(wù)
[root@zrs nginx-1.6.3]# netstat -lntp | grep 'nginx'     #檢測是否開啟
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      3633/nginx: master
[root@zrs nginx-1.6.3]# /usr/local/nginx/sbin/nginx -t   #檢測Nginx的配置是否正確
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

(5)查看Nginx版本和模塊

[root@zrs nginx-1.6.3]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.6.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
升級(jí)Nginx1.6

將 nginx1.6版本進(jìn)行升級(jí)(升級(jí)為Nginx1.18版本)并在不影響業(yè)務(wù)的情況下添加 SSL 和 pcre 模塊。

(1)升級(jí)

[root@zrs ~]# tar xzf nginx-1.18.0.tar.gz -C /usr/local/
[root@zrs ~]# cd /usr/local/nginx-1.18.0/
[root@zrs nginx-1.18.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre   #升級(jí)并添加相關(guān)模塊

(2)進(jìn)行make

注意:這里不能進(jìn)行,make install 操作,否則將會(huì)被覆蓋,可能會(huì)影響線上業(yè)務(wù)。

[root@zrs nginx-1.18.0]# make

(3)拷貝Nginx1.18版本的二進(jìn)制文件到1.6版本

[root@zrs ~]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak  #先備份一份
[root@zrs ~]# cp /usr/local/nginx-1.18.0/objs/nginx /usr/local/nginx/sbin/

(4)啟動(dòng)新的主進(jìn)程,實(shí)現(xiàn)熱升級(jí)

[root@zrs ~]# kill -USR2 $(cat /usr/local/nginx/logs/nginx.pid)

(5)查看升級(jí)后的版本

[root@zrs ~]# /usr/local/nginx/sbin/nginx -V

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Nginx?proxy、rewrite、alias配置過程

    Nginx?proxy、rewrite、alias配置過程

    這篇文章主要介紹了Nginx?proxy、rewrite、alias配置過程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • nginx如何通過proxy_pass設(shè)置反向代理,隱藏端口號(hào)

    nginx如何通過proxy_pass設(shè)置反向代理,隱藏端口號(hào)

    這篇文章主要介紹了nginx如何通過proxy_pass設(shè)置反向代理,隱藏端口號(hào)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • Nginx增添api接口的實(shí)現(xiàn)方法

    Nginx增添api接口的實(shí)現(xiàn)方法

    這篇文章給大家介紹了Nginx增添api接口的方法,文章通過代碼示例介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,具有一定的參考價(jià)值,需要的朋友可以參考下
    2023-10-10
  • 使用Nginx搭建流媒體服務(wù)器實(shí)現(xiàn)直播功能

    使用Nginx搭建流媒體服務(wù)器實(shí)現(xiàn)直播功能

    這篇文章主要介紹了使用Nginx搭建流媒體服務(wù)器實(shí)現(xiàn)直播功能,本文通過實(shí)例圖文相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-07-07
  • nginx.conf配置文件結(jié)構(gòu)小結(jié)

    nginx.conf配置文件結(jié)構(gòu)小結(jié)

    本文主要介紹了nginx.conf配置文件結(jié)構(gòu)小結(jié),nginx.conf主要由events、http、server、location、upstream等塊配置項(xiàng)和一些行配置項(xiàng)組成,文中通過示例代碼介紹的非常詳細(xì),需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • 詳解nginx?中l(wèi)ocation和?proxy_pass的匹配規(guī)則

    詳解nginx?中l(wèi)ocation和?proxy_pass的匹配規(guī)則

    location是Nginx中用來匹配客戶端請(qǐng)求URI的指令,決定如何處理特定路徑的請(qǐng)求,它定義了請(qǐng)求的路由規(guī)則,后續(xù)的配置(如?proxy_pass)會(huì)應(yīng)用在匹配的請(qǐng)求上,這篇文章主要介紹了nginxlocation和proxy_pass的匹配規(guī)則,需要的朋友可以參考下
    2025-04-04
  • Keepalived實(shí)現(xiàn)Nginx負(fù)載均衡高可用的示例代碼

    Keepalived實(shí)現(xiàn)Nginx負(fù)載均衡高可用的示例代碼

    這篇文章主要介紹了Keepalived實(shí)現(xiàn)Nginx負(fù)載均衡高可用的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • 詳解Nginx虛擬主機(jī)配置中server_name的具體寫法

    詳解Nginx虛擬主機(jī)配置中server_name的具體寫法

    這篇文章主要介紹了Nginx虛擬主機(jī)配置中server_name的具體寫法,server_name服務(wù)器名是虛擬主機(jī)中必須配置的重要參數(shù),需要的朋友可以參考下
    2016-03-03
  • 使用nginx實(shí)現(xiàn)一個(gè)端口和ip訪問多個(gè)vue前端的全過程

    使用nginx實(shí)現(xiàn)一個(gè)端口和ip訪問多個(gè)vue前端的全過程

    為滿足單端口訪問多個(gè)前端應(yīng)用的需求,需要對(duì)nginx進(jìn)行配置,同時(shí)修改vue項(xiàng)目的publicPath參數(shù),這篇文章主要介紹了使用nginx實(shí)現(xiàn)一個(gè)端口和ip訪問多個(gè)vue前端的相關(guān)資料,需要的朋友可以參考下
    2024-09-09
  • nginx全局變量整理小結(jié)

    nginx全局變量整理小結(jié)

    nginx全局變量整理小結(jié),方便需要的朋友
    2012-11-11

最新評(píng)論

家居| 茂名市| 航空| 东明县| 莒南县| 华亭县| 石棉县| 浮梁县| 紫云| 鄢陵县| 来安县| 奉节县| 深州市| 宿松县| 宁波市| 丹凤县| 临朐县| 桑植县| 神池县| 桃园县| 涞水县| 包头市| 莫力| 灵石县| 清镇市| 安陆市| 铜陵市| 东台市| 宣化县| 巴马| 天柱县| 郓城县| 高陵县| 铜梁县| 耒阳市| 鸡东县| 商南县| 沐川县| 射阳县| 深水埗区| 齐河县|