Limits resource limitation under CentOS 7.x host


The reason for writing this article isCentos 7.xEnvironmental InstallationMySQLSometimes I met with a problem.Centos 6.xEnvironmental InstallationMySQLIn/etc/security/limits.confFile pairs open filesnofileRestriction, restartMySQLIt will take effect afterwards, but it will take effect afterwards.Centos 7.xThe environment is useless.

Analytical findings/etc/security/limits.confIt only works for PAM login users, but if it passes throughsystemdStart the service. This configuration file does not work. For systems-initiated services, priority (the latter overrides the former) plays a role in:

  • /etc/systemd/system.conf Setting global default values for system-level services(PSThe system needs to be restarted to take effect, such as:
% vi /etc/systemd/system.conf 
  • Services themselves, such asmysqlProcess:
% vi /usr/lib/systemd/system/mysqld.service
LimitNOFILE = 20000
% systemctl deamon-reload
% systemctl restart mysqld


% cat /proc/13010/limits 
Limit                     Soft Limit           Hard Limit           Units     
Max open files            20000                20000                files 

Be carefulThe above is just for system-level services, even for usesystemctl start/stopManagement services, and forsystemctl –userManaged user-level services(PSVery rarely used and requires special configuration), environment variables, orlimitsLimitations are limited by the following documents:

  1. ~/.config/systemd/user.confForHOMEUsers can configure this directory again.
  2. /etc/systemd/user.confUser-level default configuration;
  3. /etc/systemd/system/[email protected]/Effective for all user-level management services;
  4. /etc/systemd/system/[email protected]<uid>.service.dEffective for specific users;

Reference documents: