The following is the optimization section, the premise of optimization is that the kernel version requires more than 3.7, view the kernel version, execute the command
Uname-a
will return your kernel information.
Then we have to do some optimizations, which is the main reason to choose the CentOS 7 x64 system.
After rebooting, we re-login the server with putty.
First we want to enable TCP Fast Open in the system
Run command
Echo 3 >/proc/sys/net/ipv4/tcp_fastopen
Requires restart after also effective TCP Fast Open, to edit sysctl.conf
Run
Vi/etc/sysctl.conf
Press keyboard I to enter edit mode, the cursor moves to the bottom blank line, copy the following content.
———————————————— Copy the following ————————
Net.ipv4.tcp_fastopen = 3
———————————————— Copy the above content ————————
After the copy is complete, return to a car, leave blank line for bottom, press Esc key to exit edit mode, enter: Wq Enter, save and exit.
Increase the number of TCP connections
Run command
Vi/etc/security/limits.conf
Press keyboard I to enter edit mode, the cursor moves to the bottom # End of file line above the blank space
, copy the following content.
———————————————— Copy the following ————————
* Soft Nofile 51200
* Hard Nofile 51200
———————————————— Copy the above content ————————
After the copy is complete, return to a car, leave blank line for bottom, press Esc key to exit edit mode, enter: Wq Enter, save and exit.
Run command
Ulimit-n 51200
Then we need to adjust the TCP congestion control algorithm to Hybla
First, TCP congestion control algorithm under popular science:
The quality of the lines between China and the US is not very good, the RTT is longer and often drops packets. TCP is designed to solve the problem of reliable transmission on unreliable lines, that is, in order to solve the packet loss, but the packet loss makes the TCP transmission speed decrease greatly. The HTTP protocol uses the TCP protocol at the transport layer, so the speed of the page download depends on the speed of the TCP single-threaded download (because the Web page is a single-threaded download). Packet loss is the main reason for the significant decrease of TCP transmission speed, which is the TCP congestion control algorithm, which is the mechanism of packet loss retransmission.
Several TCP congestion control algorithms are available in the Linux kernel, each of which is suitable for different environments.
1) Reno is the most basic congestion control algorithm and the experimental prototype of TCP protocol.
2) The BIC is suitable for cases with high RTT but very rare drops, such as lines between North America and Europe, which is the default algorithm for the Linux kernel between 2.6.8 to 2.6.18.
3) Cubic is a modified version of the BIC, the applicable environment is a bit wider than the BIC, it is the default algorithm of the Linux kernel after 2.6.19.
4) Hybla is suitable for high latency, high packet loss rates of the network, such as satellite links-the same applies to the link between China and the United States.
The job we need to do is to change the TCP congestion control algorithm to the HYBLA algorithm and optimize the TCP parameters.
Run
Sysctl Net.ipv4.tcp_available_congestion_control
will get Net.ipv4.tcp_available_congestion_control = Cubic Reno
Indicates that our system TCP congestion control algorithm can only choose cubic or Reno calculation, Hybla algorithm is not enabled, we will enable the HYBLA algorithm.
Run
/sbin/modprobe Tcp_hybla
Sysctl Net.ipv4.tcp_available_congestion_control
Get Net.ipv4.tcp_available_congestion_control = Cubic Reno Hybla
This indicates that the HYBLA is ready to use.
Run
cp/etc/sysctl.conf/root/
This is a copy of the sysctl.conf file, make a backup
Modify the sysctl.conf file to optimize TCP parameters
Vi/etc/sysctl.conf
Press keyboard I to enter edit mode, the cursor moves to the next line of Net.ipv4.tcp_fastopen = 3 just copied, copy the following.
———————————————— Copy the following ————————
Fs.file-max = 51200
#提高整个系统的文件限制
Net.core.rmem_max = 67108864
Net.core.wmem_max = 67108864
Net.core.netdev_max_backlog = 250000
Net.core.somaxconn = 3240000
Net.ipv4.tcp_syncookies = 1
Net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
Net.ipv4.tcp_fin_timeout = 30
Net.ipv4.tcp_keepalive_time = 1200
Net.ipv4.ip_local_port_range = 10000 65000
Net.ipv4.tcp_max_syn_backlog = 8192
Net.ipv4.tcp_max_tw_buckets = 5000
Net.ipv4.tcp_fastopen = 3
Net.ipv4.tcp_rmem = 4096 87380 67108864
Net.ipv4.tcp_wmem = 4096 65536 67108864
net.ipv4.tcp_mtu_probing = 1
Net.ipv4.tcp_congestion_control = Hybla
———————————————— Copy the above content ————————
After the copy is complete, return to a car, leave blank line for bottom, press Esc key to exit edit mode, enter: Wq Enter, save and exit.
Run
Sysctl-p
Make the above configuration effective.
At this point, the optimization is complete. You can enjoy it.
Note: If you need to check whether TCP Fast Open is running
Sysctl Net.ipv4.tcp_fastopen
Get Net.ipv4.tcp_fastopen = 3, indicating that it has been successfully applied.
CentOS Optimization One