Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Haproxy parameter optimization

Shulou Source: shulou.com Published: 2022-06-01 03:13:02 10月02日 Update

Commonly used optimized configurations for global:

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

Detailed description of parameters:

Mode: set the default working mode to http, or you can set it separately in the backend section

Option httplog: set the log format of records in more detail, which can be set separately in the frontend section

Option http-server-close: actively disconnect the persistent connection. This should be enabled when the persistent connection is opened.

Note: when this option is enabled, haproxy will add "Connection:close" to the header when sending a request to the back-end server, but some servers will directly deny access when they see this header

Option http-pretend-keepalive: pretend to be connected

Note: when this option is turned on, haproxy removes the header "Connection:close". This option is used with http-server-close.

Option forwardfor: forward the real IP,except of the client to the backend to exclude the specified IP address range

Timeout http-request: disconnects when the request sent by the client is incomplete within a specified time

Timeout connect: the timeout for establishing a connection

Timeout client: the timeout when the customer is inactive

Timeout http-keep-alive: long connection timeout

Timeout check: health check-up timeout

Maxconn: maximum connections

Optimization of linux system:

1. Persistent connection: if a persistent connection is not set, it will result in a large amount of timewait

two。 Reduce time_wait Tim

# cat / proc/sys/net/ipv4/tcp_fin_timeout / / View the default retention period of timewait, which defaults to 60s

Permanent effect is set in / etc/sysctl.conf

Setting method: net.ipv4.tcp_fin_timeout = 10

3. Set up time_wait rapid recycling and reuse

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

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

Default is 0, set to 1

Setting method:

Net.ipv4.tcp_tw_reuse = 1

Net.ipv4.tcp_tw_recycle = 1

4. Modify the available range of local ports

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

The default is 32768 to 61000

It is recommended to make the value of 32768 smaller so that more ports can be used, such as 1024

Setting method:

Net.ipv4.ip_local_port_range = 4000 65535

Sysctl-p makes the setting effective

5. Set the openable file descriptor and view it with ulimit-n. The default is 1024.

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

Tags: Duration customer method header time server port service parameters maximum active health client commonly used suggestions files logs more format mode Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB Redmi Shulou Tech Info MySQL