<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] # 記錄真實IP地址 有時候我們需要在容器中獲取客戶端真實的IP等信息,而經過NginxIngressController轉發后,這些信息不一定拿得到,所以我們需要對NginxIngressController進行配置。 ```shell $ kubectl -n ingress-nginx edit configmap ingress-nginx-controller # 在 data 字段添加下面三行 data: # 源地址附加到 X-Forwarded-For 標頭,而不是替換它 compute-full-forwarded-for: "true" # 設置用于標識客戶端的原始 IP 地址的標頭字段。 默認值:X-Forwarded-For forwarded-for-header: X-Forwarded-For # 當期望將 X-Forwarded-* 的標頭信息傳遞給后端服務時,需要設置為true use-forwarded-headers: "true" # 重啟 ingress-nginx-controller 容器 $ kubectl -n ingress-nginx delete pod -l app.kubernetes.io/component=controller pod "ingress-nginx-controller-6c979c5b47-hrb4k" deleted ``` > 請注意:如果在 `ingress-nginx-controller` 高可用上的負載均衡器沒有傳遞 `X-Forwarded-For` 的話,同樣是獲取不到真實IP地址的。 如果 `ingress-nginx-controller` 是高可用的話,那么會出現多個節點有pod,必定是有一個負載均衡器。那么就獲取不到真實IP地址,使用 `nginx` 做七層代理的話,需要在 `location` 加上以下幾行參數 ```shell map $http_x_forwarded_for $full_x_forwarded_for { default "$http_x_forwarded_for, $realip_remote_addr"; '' "$realip_remote_addr"; } # Allow websocket connections proxy_set_header Upgrade $http_upgrade; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $full_x_forwarded_for; # Pass the original X-Forwarded-For proxy_set_header X-Original-Forwarded-For $http_x_forwarded_for; ``` 完整的nginx示例: ![](../images/Snipaste_2021-09-24_17-37-09.png) 下面的日志是通過 `ingress` 設置的域名訪問,客戶端收集的日志 ```shell 20.0.135.128 - - [24/Sep/2021:07:04:29 +0000] "GET /test/demo/ HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36" "192.168.31.1, 192.168.31.103" ``` > 該行的第一個段是指 `上一級的訪問IP地址` 。最后一段是指 `真實客戶端IP地址, 反向代理的后端IP地址`。 # 優化參數 ```shell $ kubectl -n ingress-nginx edit cm ingress-nginx-controller # 在 data 字段添加下面內容 data: # 客戶端請求頭部的緩沖區大小,這個可以根據你的系統分頁大小來設置,一般一個請求頭的大小不會超過 1k,不過由于一般系統分頁都要大于1k,所以這里設置為分頁大小。分頁大小可以用命令getconf PAGESIZE取得。 client-header-buffer-size: 4k # 設置保持活動的客戶端連接在服務器端保持打開狀態的時間 keep-alive: "60" # 設置可以通過一個保持活動連接提供的最大請求數。 # nginx 與 client 保持的一個長連接能處理的請求數量,默認 100,高并發場景建議調高。 # 參考: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#keep-alive-requests keep-alive-requests: "10000" # 設置每個工作進程可以打開的最大并發連接數 # 參考: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#max-worker-connections max-worker-connections: "65535" # 設置每個工作進程可以打開的最大文件數 max-worker-open-files: "65535" # nginx 與 upstream 保持長連接的最大空閑連接數 (不是最大連接數),默認 32,在高并發下場景下調大,避免頻繁建聯導致 TIME_WAIT 飆升。 # 參考: https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/configmap/#upstream-keepalive-connections upstream-keepalive-connections: "10000" # 設置可以通過一個 keepalive 連接服務的最大請求數。 發出最大請求數后,連接關閉。 upstream-keepalive-requests: "100" # 設置超時,在此期間,與 upstream servers 的空閑保持連接將保持打開狀態。 upstream-keepalive-timeout: "60" # 重啟 ingress-nginx-controller 容器 $ kubectl -n ingress-nginx delete pod -l app.kubernetes.io/component=controller pod "ingress-nginx-controller-6c979c5b47-csmcj" deleted ``` # 內核調優 ```shell # 臨時臨時 kubectl patch deployment -n ingress-nginx nginx-ingress-controller \ --patch="$(curl https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/docs/examples/customization/sysctl/patch.json)" # 永久生效 # 在 ingress-nginx-controller 容器的 deploy.spec.template.spec 添加 initContainers initContainers: - name: sysctl image: alpine:3.13 securityContext: privileged: true command: - sh - -c - | sysctl -w net.core.somaxconn=32768 sysctl -w net.ipv4.ip_local_port_range='32768 65535' sysctl -w net.ipv4.tcp_tw_reuse=1 ``` **變化:** - 積壓隊列設置net.core.somaxconn從128到32768 - 臨時端口設置net.ipv4.ip_local_port_range從32768 60999到32768 65535(符合端口規劃) - 開啟 `TIME_WAIT` 重用,即允許將 `TIME_WAIT` 連接重新用于新的 TCP 連接
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看