Modify Linux kernel parameters to improve the performance of Nginx servers at High Times concurrent high-concurrency Nginx servers in Linux. when the number of TCPTIME_WAIT sockets frequently reaches two or 30 thousand, the server is easily dragged to death. By modifying Linux kernel parameters, you can reduce the number of TIME_WAIT sockets on the Nginx server. Add the following lines to vi/etc/sysctl. conf: reference net. ipv4.tcp _ f
Modifying Linux kernel parameters improves the performance of Nginx servers during high Time
When the number of TCP TIME_WAIT sockets frequently reaches two or 30 thousand for a high-concurrency Nginx server in a concurrent Linux, the server is easily dragged to death. PassModify Linux kernel parametersTo reduce the number of TIME_WAIT sockets on the Nginx server.
Vi/etc/sysctl. conf
Add the following lines:
Reference
Net. ipv4.tcp _ fin_timeout = 30
Net. ipv4.tcp _ keepalive_time = 1200
Net. ipv4.tcp _ syncookies = 1
Net. ipv4.tcp _ tw_reuse = 1
Net. ipv4.tcp _ tw_recycle = 1
Net. ipv4.ip _ local_port_range = 1024 65000
Net. ipv4.tcp _ max_syn_backlog = 8192
Net. ipv4.tcp _ max_tw_buckets = 5000
Simple description:
Net. ipv4.tcp _ syncookies = 1 indicates enabling SYN Cookies. When a SYN wait queue overflows, cookies are enabled to prevent a small number of SYN attacks. The default value is 0, indicating that the process is disabled;
Net. ipv4.tcp _ tw_reuse = 1 indicates Enabling reuse. Allow TIME-WAIT sockets to be re-used for a new TCP connection. the default value is 0, indicating that the TCP connection is disabled;
Net. ipv4.tcp _ tw_recycle = 1 indicates to enable quick recovery of TIME-WAIT sockets in TCP connections. the default value is 0, indicating to disable it.
Net. ipv4.tcp _ fin_timeout = 30 indicates that if the socket is disabled by the local end, this parameter determines the time it remains in the FIN-WAIT-2 state.
Net. ipv4.tcp _ keepalive_time = 1200 indicates the frequency of keepalive messages sent by TCP when keepalive is in use. The default value is 2 hours, which is changed to 20 minutes.
Net. ipv4.ip _ local_port_range = 1024 65000 indicates the port range used for external connection. The default value is small: 32768 to 61000, which is changed to 1024 to 65000.
Net. ipv4.tcp _ max_syn_backlog = 8192 indicates the length of the SYN queue. the default value is 1024. the length of the queue is 8192, which can accommodate more network connections waiting for connection.
Net. ipv4.tcp _ max_tw_buckets = 5000 indicates that the system maintains the maximum number of TIME_WAIT sockets at the same time. if this number is exceeded, the TIME_WAIT socket is immediately cleared and warning information is printed. The default value is 180000, which is changed to 5000. For servers such as Apache and Nginx, the number of TIME_WAIT sockets can be greatly reduced by parameters in the previous lines, but the effect on Squid is not great. This parameter can control the maximum number of TIME_WAIT sockets to prevent the Squid server from being dragged to death by a large number of TIME_WAIT sockets.
Echo "================================== execute the following command to make the configuration take effect: =========================================" # a command that takes effect immediately after the http://jimmyli.jimmyli.jimmyli.blog.51cto.com changes the Linux kernel parameters!
/Sbin/sysctl-p
Nginx optimization
Use FastCGI cache
Fastcgi_cache TEST
Enable FastCGI cache and specify a name for it. I personally think it is very useful to enable cache, which can effectively reduce the CPU load and prevent 502 errors.
Fastcgi_cache_path/usr/local/nginx/fastcgi_cache levels =
Keys_zone = TEST: 10 m
Inactive = 5 m;
This command specifies a path for the FastCGI cache, the directory structure level, the storage time of the keyword region, and the non-active deletion time.
For stress testing, webbench is used. the test result can only be used as a reference.
There will be other parameter modifications that have been made earlier in the future. if you have time, share them. You are welcome to discuss and communicate with each other. Deduction: ⑥ ()
This article is from the "Jimmy Li I stand on the shoulders of giants" blog, please be sure to keep this source http://jimmyli.blog.51cto.com/3190309/600839