Nginxuptream健康檢查-創(chuàng)新互聯(lián)

upstream hello {
server 100.14.1.3:1201;
server 100.14.1.4:1201;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "HEAD /product HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
server {
listen 80;
server_name hello.youbest.com;
access_log /data/logs/nginx/hello.youbest.com.access.log main;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://hello;
}
}

潘集網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),潘集網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為潘集近千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個(gè)售后服務(wù)好的潘集做網(wǎng)站的公司定做!

首先要確認(rèn)服務(wù)類型是 http 還是tcp

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

 or

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

 然后確認(rèn)健康檢查的url是否支持 HEAD請求或者GET 請求

 [root@100-14-1-3 ~]# curl -v -XHEAD http://hello.youbest.com/product
  • About to connect() to hello.youbest.com port 80 (#0)
  • Trying 10.24.1.3... connected
  • Connected to hello.youbest.com (100.14.1.3) port 80 (#0)

    HEAD / HTTP/1.1
    User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh3/1.4.2
    Host: baidu.com
    Accept: /

    < HTTP/1.1 200 OK
    < Date: Tue, 07 Jan 2020 08:29:28 GMT
    < Server: Apache
    < Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
    < ETag: "51-47cf7e6ee8400"
    < Accept-Ranges: bytes
    < Content-Length: 81
    < Cache-Control: max-age=86400
    < Expires: Wed, 08 Jan 2020 08:29:28 GMT
    < Connection: Keep-Alive
    < Content-Type: text/html
    <

以上返回表示支持 HEAD 請求 nginx 就可以這樣做健康檢查

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

其中 /product 表示服務(wù)里面的埋點(diǎn)路徑

< HTTP/1.1 200 OK 表示返回200狀態(tài)

如果HEAD 請求不支持 參考下面baidu.com的GET 請求

[root@vhs100-14-1-3 ~]# curl -v -XGET http://baidu.com

  • About to connect() to baidu.com port 80 (#0)
  • Trying 220.181.38.148... connected
  • Connected to baidu.com (220.181.38.148) port 80 (#0)

    GET / HTTP/1.1
    User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh3/1.4.2
    Host: baidu.com
    Accept: /

    < HTTP/1.1 200 OK
    < Date: Tue, 07 Jan 2020 08:41:38 GMT
    < Server: Apache
    < Last-Modified: Tue, 12 Jan 2010 13:48:00 GMT
    < ETag: "51-47cf7e6ee8400"
    < Accept-Ranges: bytes
    < Content-Length: 81
    < Cache-Control: max-age=86400
    < Expires: Wed, 08 Jan 2020 08:41:38 GMT
    < Connection: Keep-Alive
    < Content-Type: text/html
    <
    <html>
    <meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
    </html>

  • Connection #0 to host baidu.com left intact
  • Closing connection #0

以上表示支持 GET 請求 nginx 就可以這樣做健康檢查

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

加了健康檢查后,當(dāng)后端有多臺(tái)服務(wù)器提供服務(wù)時(shí)
Down掉的機(jī)器就不會(huì)被代理轉(zhuǎn)發(fā)業(yè)務(wù)過去
從而保障業(yè)務(wù)的正常處理

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

網(wǎng)站題目:Nginxuptream健康檢查-創(chuàng)新互聯(lián)
URL鏈接:http://bm7419.com/article30/dsedpo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)公司、ChatGPT、標(biāo)簽優(yōu)化、全網(wǎng)營銷推廣、App開發(fā)虛擬主機(jī)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)