Modifying Kernel Parameters
Purpose
Modify kernel parameters of the operating system to improve server performance.
Procedure
- Open the sysctl.conf file:
1vim /etc/sysctl.conf - Press i to enter the insert mode, and add the following kernel parameter settings to the file:
1 2 3 4 5 6 7 8 9 10
net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_keepalive_time = 60 net.ipv4.tcp_fin_timeout = 1 net.ipv4.tcp_max_tw_buckets = 5000 net.ipv4.ip_local_port_range = 1024 65500 net.core.somaxconn = 65535 net.ipv4.tcp_max_syn_backlog = 262144 net.core.netdev_max_backlog = 262144 net.core.rmem_max = 16777216 net.core.wmem_max = 16777216
Table 1 describes the kernel parameters.Table 1 Kernel parameter description Linux Kernel Parameter
Description
Current Value
Default Value
net.ipv4.tcp_tw_reuse
TIME-WAIT sockets can be reused for new TCP connections. The value 1 indicates enabled, while the value 0 indicates disabled.
1
0
net.ipv4.tcp_keepalive_time
Specifies the interval (in seconds), at which a keepalive message is sent. This message checks whether a TCP connection is valid.
60
7200
net.ipv4.tcp_fin_timeout
Specifies the maximum duration for the socket to remain in FIN_WAIT_2 state.
1
60
net.ipv4.tcp_max_tw_buckets
Specifies the maximum number of TIME_WAIT connections. Reducing the number of TIME_WAIT connections can prevent excessive TIME_WAIT connections from occupying network resources and reduce the latency.
5000
262144
net.ipv4.ip_local_port_range
Specifies the range of the ports that can be used. Increasing the number of available ports can prevent performance dip when ports are occupied by a large number of connections.
1024 65500
32768 61000
net.core.somaxconn
Specifies the maximum length of the listening queue for each port in the OS. This parameter applies globally.
65535
128
net.ipv4.tcp_max_syn_backlog
Specifies the SYN queue length. More network connections can be supported by increasing the queue length.
262144
1024
net.core.netdev_max_backlog
Specifies the maximum number of data packets that can be sent to the queue when the packet receive rate at each network port is higher than the data packet processing rate of the kernel.
262144
1000
net.core.rmem_max
Specifies the maximum read buffer of the OS socket.
16777216
131071
net.core.wmem_max
Specifies the maximum write buffer of the OS socket. Increasing the buffer size can prevent buffer overflow caused by a large number of new connections.
16777216
131071
net.netfilter.nf_conntrack_max
Specifies the maximum number of connection tracking entries.
0
65536
When a container is used, the nf_conntrack module cannot be disabled. In this case, you need to add kernel parameter settings related to nf_conntrack to the /etc/sysctl.conf file to prevent packet loss caused by full table records.1net.netfilter.nf_conntrack_max=0
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Make the configuration take effect.
1/sbin/sysctl -p