


How to optimize kernel parameters sysctl
Adjusting kernel parameters (sysctl) can effectively optimize system performance, improve network throughput, and enhance security. 1. Network connection: Turn on net.ipv4.tcp_tw_reuse to reuse TIME-WAIT connection to avoid enabling tcp_tw_recycle in NAT environment; appropriately lower net.ipv4.tcp_fin_timeout to 15 to 30 seconds to speed up resource release; adjust net.core.somaxconn and net.ipv4.tcp_max_syn_backlog according to the load to cope with the problem of full connection queue. 2. Memory management: reduce vm.swappiness to about 10 to reduce swap usage; adjust vm.dirty_ratio and dirty_background_ratio according to IO pressure to optimize dirty page writing; configure kernel.shmall and kernel.shmmax according to shared memory requirements, but be cautious when operating in combination with monitoring data. 3. Security and stability: Turn off accept_redirects and secure_redirects in container or virtualized environment to prevent man-in-the-middle attacks; keep net.ipv4.tcp_syncookies enabled to resist SYN Flood attacks; if there are a large number of external connection requirements, expand the net.ipv4.ip_local_port_range port range to prevent exhaustion. Adjusting parameters should be continuously optimized in combination with business scenarios, and the configuration should be effective through sysctl -p.
Adjusting kernel parameters (sysctl) is an important means to optimize system performance, improve network throughput, and enhance security. But many people are not clear about how to adjust and which parameters, or they are prone to getting into pitfalls. This article will talk about a few key points to help you optimize sysctl parameters more effectively.
Network connection related: Improve concurrency and response speed
Linux systems have many adjustable parameters in terms of network, especially in high concurrency scenarios. Reasonable settings can significantly improve the stability and performance of services.
- net.ipv4.tcp_tw_reuse and tcp_tw_recycle : These two parameters control whether the socket in the TIME-WAIT state can be reused. It is generally recommended to enable
tcp_tw_reuse
, andtcp_tw_recycle
may have problems in NAT environment and is not recommended to use it. - net.ipv4.tcp_fin_timeout : Controls the timeout time of the FIN-WAIT state, the default is 60 seconds. If it is a service with more short connections, appropriately reducing this value (for example, set to 15~30) will help to release resources faster.
- net.core.somaxconn and net.ipv4.tcp_max_syn_backlog : These two affect the connection queue length. If the server often has connection rejection, it may be because the connection queue is full, adjusting these values appropriately can alleviate the problem.
If you are working on a web service or API interface, these parameters are basically a must-adjust.
Memory and cache management: Avoid OOM or performance bottlenecks
Memory-related parameter adjustments should be cautious, especially in production environments. It is best to use monitoring data to determine whether adjustments are needed.
- vm.swappiness : This parameter controls the tendency of the system to use swap, the default is 60. For servers with large amounts of memory, it can be set to 10 or lower to reduce unnecessary swap operations.
- vm.dirty_ratio and dirty_background_ratio : Controls the timing of dirty pages being written to disk. If the server frequently writes the disk, it can reduce these values appropriately to allow the data to fall off the disk earlier and avoid lag caused by centralized writing.
- kernel.shmall and kernel.shmmax : If your application uses shared memory (such as Oracle, Redis), you need to adjust these parameters according to actual needs.
It should be noted here that before adjusting memory-related parameters, it is best to check the system's load, swap usage and IO delay, otherwise it will be counterproductive.
Security and Stability: Prevent DoS attacks or abnormal crashes
Although some parameters do not directly improve performance, they play a key role in security and system stability.
- net.ipv4.conf.all.accept_redirects and secure_redirects : It is enabled by default, but it is recommended to turn off in some environments (such as containers or virtualization platforms) to prevent potential man-in-the-middle attacks.
- net.ipv4.tcp_syncookies : When enabled, it can mitigate the impact during SYN Flood attacks. It is recommended to remain enabled.
- kernel.shmall and kernel.shmmax : If your application uses shared memory (such as Oracle, Redis), you need to adjust these values according to actual needs.
Another small detail is: net.ipv4.ip_local_port_range , which determines the port range used by the client. If your service initiates a large number of external connections, you can increase this range a little (for example, expand from 32768 60999 to 1024 65535) to avoid port exhaustion.
Basically that's it. Sysctl parameter adjustment is not a one-time thing, and different business scenarios require different configurations. It is recommended to keep records before each modification and observe the effect for a period of time. Many parameters will not take effect immediately after changing them. Remember to add sysctl -p
to make the configuration take effect.
The above is the detailed content of How to optimize kernel parameters sysctl. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











When managing cron tasks, you need to pay attention to paths, environment variables and log processing. 1. Use absolute paths to avoid commands or scripts not being found due to different execution environments; 2. Explicitly declare environment variables, such as PATH and HOME, to ensure that the variables dependent on the script are available; 3. Redirect output to log files to facilitate troubleshooting; 4. Use crontab-e to edit tasks to ensure that the syntax is correct and takes effect automatically. Mastering these four key points can effectively avoid common problems.

When encountering Docker problems, you should first locate the problem, which is problems such as image construction, container operation or network configuration, and then follow the steps to check. 1. Check the container log (dockerlogs or docker-composelogs) to obtain error information; 2. Check the container status (dockerps) and resource usage (dockerstats) to determine whether there is an exception due to insufficient memory or port problems; 3. Enter the inside of the container (dockerexec) to verify the path, permissions and dependencies; 4. Review whether there are configuration errors in the Dockerfile and compose files, such as environment variable spelling or volume mount path problems, and recommend that cleanbuild avoid cache dryness

The key to writing ChefRecipes is to have clear structure, single responsibilities, and strong maintainability. ChefRecipes is a declarative configuration that defines the system status through resources, such as package installation software, service control services, file/template management files, and user management users. 1. Each Recipe should only be responsible for one task, such as installing Nginx and configuring the site; 2. Use include_recipe to control the dependency order, use notifies and subscribes to achieve event-driven; 3. Improve readability, use meaningful variable names, unified indentation, avoid hard coding, and prioritize the use of attributes over direct values. Following these principles can improve R

To manage Linux user groups, you need to master the operation of viewing, creating, deleting, modifying, and user attribute adjustment. To view user group information, you can use cat/etc/group or getentgroup, use groups [username] or id [username] to view the group to which the user belongs; use groupadd to create a group, and use groupdel to specify the GID; use groupdel to delete empty groups; use usermod-aG to add users to the group, and use usermod-g to modify the main group; use usermod-g to remove users from the group by editing /etc/group or using the vigr command; use groupmod-n (change name) or groupmod-g (change GID) to modify group properties, and remember to update the permissions of relevant files.

The steps to install Docker include updating the system and installing dependencies, adding GPG keys and repositories, installing the Docker engine, configuring user permissions, and testing the run. 1. First execute sudoaptupdate and sudoaptupgrade to update the system; 2. Install apt-transport-https, ca-certificates and other dependency packages; 3. Add the official GPG key and configure the warehouse source; 4. Run sudoaptinstall to install docker-ce, docker-ce-cli and containerd.io; 5. Add the user to the docker group to avoid using sudo; 6. Finally, dock

Adjusting kernel parameters (sysctl) can effectively optimize system performance, improve network throughput, and enhance security. 1. Network connection: Turn on net.ipv4.tcp_tw_reuse to reuse TIME-WAIT connection to avoid enabling tcp_tw_recycle in NAT environment; appropriately lower net.ipv4.tcp_fin_timeout to 15 to 30 seconds to speed up resource release; adjust net.core.somaxconn and net.ipv4.tcp_max_syn_backlog according to the load to cope with the problem of full connection queue. 2. Memory management: reduce vm.swappiness to about 10 to reduce

The three modes of SELinux are enforcing, permissive and disabled. You can use sestatus or getenforce commands to view the current status; you can use setenforce0 (permissive) or setenforce1 (enforcing) for temporary switching modes, but they can be invalid after restart; permanent changes require editing /etc/selinux/config file and restarting the system; it is recommended to use permissive mode to take into account error troubleshooting and security. Logs should be checked before operation, compatibility should be considered, and file context labels may need to be restored after switching.

To restart the service managed by systemctl in Linux, 1. First use the systemctlstatus service name to check the status and confirm whether it is necessary to restart; 2. Use the sudosystemctlrestart service name command to restart the service, and ensure that there is administrator privileges; 3. If the restart fails, you can check whether the service name is correct, whether the configuration file is wrong, or whether the service is installed successfully; 4. Further troubleshooting can be solved by viewing the log journalctl-u service name, stopping and starting the service first, or trying to reload the configuration.
