Location>code7788 >text

Modify the number of file open handles for Linux services

Popularity:433 ℃/2024-10-26 18:43:53

In bash, there is an ulimit command that provides control over the resources available to a shell and the processes started by that shell. This includes the number of open file descriptors, the maximum number of processes for a user, the size of the coredump file, and so on.

In centos 5/6 and other versions, the resource limit configuration can be set in /etc/security/ for each user such as root/user or * for all users. Of course, /etc/security// can be configured in /etc/security/, the system is loaded first and then loads the configuration files under the directory in alphabetical order, and the later loaded configuration overrides the previous configuration. An example configuration is as follows:

However, on CentOS 7 / RHEL 7 systems, Systemd is used instead of the previous SysV, so the configuration scope of the /etc/security/ file is narrowed down a bit. The configuration here applies only to resource restrictions for users logged in via PAM authentication; it does not take effect on resource restrictions for systemd's services. Limits for logged-in users are the same as above, and can be configured via /etc/security/ and .
For systemd service resource limit, how to configure it?

global configuration in the files /etc/systemd/ and /etc/systemd/. Also, all .conf files in the two corresponding directories /etc/systemd// are loaded..conf and /etc/systemd//.conf

which is used by the system instance and used by the user instance. For general sevice, it is sufficient to use the configuration in. /*.conf will override the configuration in the

To enable global validation, you can modify the /etc/systemd/ file
Add in section [Service].
DefaultLimitCORE=infinity
DefaultLimitNOFILE=65535
DefaultLimitNPROC=65535

Changes to the file require a restart of the server to take effect

Modify file limits for individual services, such as
Then add it to the [Service] section of the corresponding service file.
Below:
image

To modify a single service, you need to Reload it again with the following command
systemctl daemon-reload
Then restart the service to take effect
Check if it's in effect
View the limit setting for a process:
cat /proc/YOUR-PID/limits

https://blog./kusorz/1917143