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

Nginx負(fù)載均衡健康檢查性能提升

 更新時(shí)間:2023年10月27日 09:55:27   作者:ChengKe_dawn  
這篇文章主要為大家介紹了Nginx負(fù)載均衡健康檢查性能提升,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

前言

在Nginx官方模塊提供的模塊中,沒有對(duì)負(fù)載均衡后端節(jié)點(diǎn)的健康檢查模塊 但可以使用第三方模塊 nginx_upstream_check_module 來檢測(cè)后端服務(wù)器的健康狀態(tài)。我安裝Nginx的方式,是通過 yum 安裝的,通過 yum 安裝的沒有 nginx_upstream_check_module 這個(gè)模塊,所以我們需要先給 Nginx 把這個(gè)模塊安裝好。

如果你已經(jīng)yum安裝過Nginx,那么建議最好是先 yum remove nginx 卸載一下,暫時(shí)沒有找到找能不卸載然后給Nginx配置這個(gè)模塊的辦法。

安裝配置

  • 安裝依賴包
yum -y install gcc glibc gcc-c++ openssl-devel pcre-devel patch
  • 下載nginx源碼包和nginx_upstream_check模塊第三方模塊

Nginx官方地址 

cd /usr/local
wget https://nginx.org/download/nginx-1.21.4.tar.gz
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/refs/heads/master.zip

該第三方模塊在 github 上的地址為:可以去查看,也給出了配置的示例,很詳細(xì)。地址

  • 解壓Nginx源碼包和第三方模塊
tar -zxvf nginx-1.21.4.tar.gz
unzip nginx_upstream_check_module-master.zip

添加Nginx模塊

cd nginx-1.21.4/
patch -p1 < ../nginx_upstream_check_module-master/check_1.20.1+.patch

 p1代表在Nginx目錄,p0是不在Nginx目錄

  • 編譯Nginx,需要添加upstream_check第三方模塊

通過 nginx -V 查看


將以上內(nèi)容復(fù)制下來

重新編譯的時(shí)候加上 --add-module=/usr/local/nginx_patch/nginx_upstream_check_module-master。 模塊地址就是你下載 nginx_upstream_check_module 到本地的地址。(但是有時(shí)候nginx -v會(huì)失敗,但是不會(huì)又太大影響,直接復(fù)制下面的命令也是可以的)

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --add-module=/usr/local/nginx_patch/nginx_upstream_check_module-master --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
  • 編譯安裝
make && make install

  • 啟動(dòng)NGINX(防止因?yàn)閳?bào)錯(cuò)為啟動(dòng)成功)
suho /usr/sbin/nginx

 此時(shí)可能會(huì)報(bào)錯(cuò)沒有發(fā)現(xiàn)某個(gè)文件夾,但是不影響,你去對(duì)應(yīng)的目錄創(chuàng)建一個(gè)即可

nginx -t 檢查nginx配置是否正確
nginx -s reload 重新加載配置文件

博主的nginx.conf配置(其實(shí)建議最好的每個(gè)站點(diǎn)的配置文件獨(dú)立開,但是我偷懶了并沒有)

注意,這配置文件通用性比較高,但是也是需要依賴自己的需求修改部分配置,博主是在兩臺(tái)服務(wù)器之間進(jìn)行搭建的兩臺(tái)NGINX,雙方進(jìn)行心跳檢測(cè),ip為內(nèi)網(wǎng)和彈性兩個(gè),10.75.25.207對(duì)應(yīng)的內(nèi)網(wǎng)是10.75.28.14

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/
user root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
    worker_connections 1024;
}
http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    map $time_iso8601 $logdate {
    '~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
    default    'date-not-found';
    }
send_timeout 30;
    client_body_buffer_size 40m;
    proxy_buffer_size 128k; 
    proxy_buffers 4 128k; 
    proxy_busy_buffers_size 128k;
    # access_log /var/log/nginx/access.log main;
    access_log  /var/log/nginx/access-$logdate.log main;
    server_tokens off;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;
    include             /usr/local/nginx/conf/mime.types;
    default_type        application/octet-stream;
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    server {
        listen       80;
        #listen 443 ssl http2;
        server_name  10.75.28.14 10.75.25.207;
        index  index.html;
        root /data/wwwroot/paizhu/dist/;
        gzip on; 
        gzip_buffers 32 4K; 
        gzip_comp_level 6; 
        gzip_min_length 200;
        # access_log /var/log/nginx/host.access_.log main; 
        gzip_types application/javascript text/css text/xml; 
        gzip_disable "MSIE [1-6]\."; 
        #配置禁用gzip條件,支持正則。此處表示ie6及以下不啟用gzip(因?yàn)閕e低版本不支持)
        gzip_vary on;
        #SSL-END
        location /status {
            check_status;
            access_log   off;
        }
        location /file {
            alias /data/wwwroot/upload;
            try_files $uri @mongrel;
        }
        location @mongrel {
            if ($http_lan_check = "1") {
                return 404;
            }
            proxy_pass http://10.75.28.37:80;
            proxy_set_header lan-check "1";
        }
        location /oss {
            rewrite ^/oss(.*)$ /$1 break;
            proxy_pass http://szpzjdgzglxt.oss111b-cn-sx-zjsxzwy01-d01-a.inner.zjsxzwy.cn/;
            #proxy_set_header Host $host; OSS的反向代理,需要去掉來源地址,政務(wù)云是這樣
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header Upgrade $http_upgrade;
            proxy_http_version 1.1;
            add_header X-Cache $upstream_cache_status;
        }
        location /manage {
            proxy_pass http://manage;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header Upgrade $http_upgrade;
            #proxy_set_header Connection $connection_upgrade;
            proxy_http_version 1.1;
            # proxy_hide_header Upgrade;
            add_header X-Cache $upstream_cache_status;
            #Set Nginx Cache
            set $static_fileyb8cQBoU 0;
            if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
            {
                set $static_fileyb8cQBoU 1;
                expires 1m;
            }
            if ( $static_fileyb8cQBoU = 0 )
            {
                add_header Cache-Control no-cache;
            }
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    upstream manage {
        least_conn;
        server 10.75.28.14:500 weight=1 max_fails=2 fail_timeout=10s; # 服務(wù)實(shí)例1
        server 10.75.28.14:501 weight=1 max_fails=2 fail_timeout=10s; # 服務(wù)實(shí)例2
        server 10.75.28.37:500 weight=1 max_fails=2 fail_timeout=10s; # 服務(wù)實(shí)例3
        server 10.75.28.37:501 weight=1 max_fails=2 fail_timeout=10s; # 服務(wù)實(shí)例4
        check interval=3000 rise=2 fall=5 timeout=1000 type=http;
        check_http_send "GET /manage/heartbeat HTTP/1.0\r\n\r\n";
        check_http_expect_alive http_2xx http_3xx;
    }
}

效果圖

正常狀態(tài)

掉線狀態(tài)

以上就是Nginx負(fù)載均衡健康檢查性能提升的詳細(xì)內(nèi)容,更多關(guān)于Nginx負(fù)載均衡的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Nginx跨域設(shè)置Access-Control-Allow-Origin無效的解決辦法

    Nginx跨域設(shè)置Access-Control-Allow-Origin無效的解決辦法

    今天小編就為大家分享一篇關(guān)于Nginx跨域設(shè)置Access-Control-Allow-Origin無效的解決辦法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-02-02
  • nginx https 443端口配置的方法

    nginx https 443端口配置的方法

    本文主要介紹了nginx https 443端口配置的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-03-03
  • Nginx中使用Lua腳本與圖片的縮略圖處理的實(shí)現(xiàn)

    Nginx中使用Lua腳本與圖片的縮略圖處理的實(shí)現(xiàn)

    本文主要介紹了Nginx中使用Lua腳本與圖片的縮略圖處理的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • nginx部署前端項(xiàng)目的超級(jí)詳細(xì)步驟記錄

    nginx部署前端項(xiàng)目的超級(jí)詳細(xì)步驟記錄

    眾所周知Nginx是一款高性能的http服務(wù)器/反向代理服務(wù)器及電子郵件(IMAP/POP3)代理服務(wù)器,這篇文章主要給大家介紹了關(guān)于nginx部署前端項(xiàng)目的超級(jí)詳細(xì)步驟,需要的朋友可以參考下
    2023-02-02
  • nginx 502 Bad Gateway 錯(cuò)誤解決辦法

    nginx 502 Bad Gateway 錯(cuò)誤解決辦法

    一些運(yùn)行在Nginx上的網(wǎng)站有時(shí)候會(huì)出現(xiàn)“502 Bad Gateway”錯(cuò)誤,有些時(shí)候甚至頻繁的出現(xiàn)。以下是小編搜集整理的一些Nginx 502錯(cuò)誤的排查方法,供參考
    2013-10-10
  • Nginx限制IP訪問的實(shí)現(xiàn)示例

    Nginx限制IP訪問的實(shí)現(xiàn)示例

    限制某些IP地址訪問網(wǎng)站是一個(gè)常見的需求,本文主要介紹了Nginx限制IP訪問的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-06-06
  • nginx負(fù)載均衡配置方式

    nginx負(fù)載均衡配置方式

    這篇文章主要介紹了nginx負(fù)載均衡配置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2025-06-06
  • prometheus監(jiān)控nginx的兩種方式

    prometheus監(jiān)控nginx的兩種方式

    這篇文章主要介紹了兩種不同的Nginx監(jiān)控方法,第一種是nginx自帶的tub_status模塊進(jìn)行監(jiān)控,第二種是用vts監(jiān)控工具進(jìn)行監(jiān)控,都是基于prometheus、grafana結(jié)合第三方模塊或監(jiān)控工具搭建,文中通過圖文結(jié)合的方式介紹的非常詳細(xì),需要的朋友可以參考下
    2024-05-05
  • 通過nginx做mysql的負(fù)載均衡實(shí)現(xiàn)過程

    通過nginx做mysql的負(fù)載均衡實(shí)現(xiàn)過程

    Nginx stream模塊用于DNS和主從MySQL的TCP/UDP代理與負(fù)載均衡,安裝需編譯啟用或通過yum安裝,配置stream塊及upstream實(shí)現(xiàn)轉(zhuǎn)發(fā)和輪詢,測(cè)試后驗(yàn)證端口監(jiān)聽狀態(tài)
    2025-07-07
  • Nginx請(qǐng)求轉(zhuǎn)發(fā)配置指南

    Nginx請(qǐng)求轉(zhuǎn)發(fā)配置指南

    Nginx 是一款高性能的 HTTP 和反向代理服務(wù)器,也是一個(gè) IMAP/POP3/SMTP 代理服務(wù)器,本文檔將介紹如何使用 Nginx 配置請(qǐng)求轉(zhuǎn)發(fā),并解釋一些常用的配置參數(shù),需要的朋友可以參考下
    2024-10-10

最新評(píng)論

昌吉市| 蓬安县| 武山县| 杭州市| 景东| 天柱县| 盈江县| 万宁市| 秦皇岛市| 安泽县| 楚雄市| 英德市| 淮南市| 鄂州市| 静海县| 云梦县| 金平| 盱眙县| 团风县| 正阳县| 通辽市| 达拉特旗| 昌平区| 峨眉山市| 米脂县| 芦山县| 黑水县| 德格县| 泾源县| 滕州市| 松江区| 三穗县| 榆社县| 封丘县| 开化县| 忻州市| 绥宁县| 永昌县| 新沂市| 雅安市| 兰坪|