By default is seems the soft and hard open files limits on MariaDB in CentOS 7 are 1024 and 4096 respectfully. You can see these limits by first getting the process ID:
|
1 |
cat /var/run/mariadb/mariadb.pid |
And then looking at the limits in the proc filesystem:
|
1 |
cat /proc/XXXXX/limits |
You’ll see something like this:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@web1 ~]# cat /proc/7688/limits Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 31209 31209 processes Max open files 1024 4096 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 31209 31209 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us |
Notice the numbers for “Max open files”.
If you run into problems with MariaDB failing and you see errors like this in the log:
|
1 |
[ERROR] Error in accept: Too many open files |
Then you need to increase the open files limits by editing:
|
1 |
/usr/lib/systemd/system/mariadb.service |
and adding this line:
|
1 |
LimitNOFILE=infinity |
to the “[Service]” section. Then reload the systemctl daemon:
|
1 |
systemctl daemon-reload |
and restart the MariaDB service:
|
1 |
/sbin/service mariadb restart |
Now the limit will be increased. For example:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[root@web1 ~]# cat /proc/9910/limits Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 31209 31209 processes Max open files 65536 65536 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 31209 31209 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us |
UPDATE: We’ve seen similar problems with nginx. The solution is similar … increase the limits for the nginx service.
UPDATE: As noted by Bastiaan Welmers in the comments, it better to copy the service control file then to edit:
|
1 |
cp /usr/lib/systemd/system/mariadb.service /etc/systemd/system/ |
UPDATE:
As describe here:
Create an override file with:
|
1 |
systemctl edit mariadb.service |
or:
|
1 |
/etc/systemd/system/mariadb.service.d/override.conf |
Put the modified settings in the override file:
|
1 2 |
[Service] LimitNOFILE=infinity |
Reload systemd config:
|
1 |
systemctl --system daemon-reload |
And restart mariadb:
|
1 |
systemctl restart mariadb.service |
UPDATE:
On server with Plesk, view the current open files limit with:
|
1 |
egrep "open files" /proc/$(cat `plesk db -Ne "show variables like 'pid_file'" | awk '{print $2}'`)/limits |
UPDATE:
On Ubuntu 22 and possibly other environments some additional steps were necessary to the limit.
The kernel contains a compiled default upper limit for open files. The limit can be shown with:
|
1 |
cat /proc/sys/fs/nr_open |
Ubuntu 22 sets the limit to 1048576. The limit can be increased on the fly with:
|
1 |
echo 16777216 > /proc/sys/fs/nr_open |
or to change permanently:
|
1 |
echo "fs.nr_open = 16777216" > /etc/sysctl.d/nr_open.conf |
For Apache, the upper limit may be set to 8192 with this line:
|
1 |
APACHE_ULIMIT_MAX_FILES='ulimit -n 8192' |
in:
|
1 |
/etc/apache2/envvars |
The line may be commented out in which case the 8192 default limit is applied. To change, uncomment and set desired value.





One Response
One should never edit files that resist in /usr/lib since they are overwritten on system update. Instead copy the service file to /etc/systemd and make your changes there.