溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

haproxy參數(shù)優(yōu)化

發(fā)布時(shí)間:2020-08-01 21:11:07 來源:網(wǎng)絡(luò) 閱讀:19325 作者:weilovepan520 欄目:網(wǎng)絡(luò)安全

global常用的優(yōu)化配置:

    mode                    http

    log                     global

    option                  httplog

    option http-server-close

    option http-pretend-keepalive

    option forwardfor       except 127.0.0.0/8

    retries                 3

    timeout http-request    10s

    timeout queue           1m

    timeout connect         10s

    timeout client          1m

    timeout server          1m

    timeout http-keep-alive 10s

    timeout check           10s

    maxconn                 655350

參數(shù)詳解

    mode:設(shè)置默認(rèn)工作模式為http,也可以在backend段中單獨(dú)設(shè)置

    option httplog:設(shè)置記錄的日志格式更為詳細(xì),可以在frontend段中單獨(dú)設(shè)置

    option http-server-close:主動(dòng)斷開長連接,當(dāng)開啟長連接時(shí),應(yīng)該開啟此項(xiàng)

    注:當(dāng)開啟此選項(xiàng)時(shí),haproxy在向后端服務(wù)器發(fā)送請求時(shí),會在header中添加“Connection:close”,但是有些服務(wù)器看到此頭部時(shí),直接 會拒絕訪問

    option http-pretend-keepalive:假裝自己是保持連接的

    注:當(dāng)開啟此選項(xiàng)時(shí),haproxy會去掉頭部“Connection:close”,此選項(xiàng)與http-server-close一起使用

    option forwardfor:向后端轉(zhuǎn)發(fā)客戶端的真實(shí)IP,except表示排除指定的網(wǎng)段

    timeout http-request:當(dāng)客戶端發(fā)送的請求,在指定時(shí)間內(nèi)發(fā)送不完整時(shí),斷開連接

    timeout connect:建立連接的超時(shí)時(shí)長

    timeout client:當(dāng)客戶超過多久不活動(dòng)時(shí)的超時(shí)時(shí)長

    timeout http-keep-alive:長連接超時(shí)時(shí)長

    timeout check:健康檢查超時(shí)時(shí)長

    maxconn:最大連接數(shù)

linux系統(tǒng)的優(yōu)化:   

    1.長連接:如果不設(shè)置長連接,會造成大量的timewait

    2.縮短time_wait時(shí)間

      #cat /proc/sys/net/ipv4/tcp_fin_timeout  //查看timewait的默認(rèn)保持時(shí)長,默認(rèn)為60s

      永久生效在/etc/sysctl.conf中設(shè)置

      設(shè)置方法:net.ipv4.tcp_fin_timeout = 10

    3.設(shè)置time_wait快速回收和重用

      #cat /proc/sys/net/ipv4/tcp_tw_reuse

      #cat /proc/sys/net/ipv4/tcp_tw_recycle

      默認(rèn)為0,設(shè)置為1

      設(shè)置方法:

        net.ipv4.tcp_tw_reuse = 1

        net.ipv4.tcp_tw_recycle = 1

    4.修改本地端口可用范圍

      #cat /proc/sys/net/ipv4/ip_local_port_range

      默認(rèn)為32768到61000

      建議把32768的值設(shè)的小一點(diǎn),以便可以使用更多的端口,如設(shè)為1024

      設(shè)置方法:

        net.ipv4.ip_local_port_range = 4000 65535

        sysctl -p使設(shè)置生效

    5.設(shè)置可打開文件描述符,用ulimit -n進(jìn)行查看,默認(rèn)為1024

      echo '*  -  nofile  65535' >> /etc/security/limits.conf


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI