Clicky

Aumentar open-files-limit en MariaDB en CentOS 7 con systemd

mariaDB logo

Error: Out of resources when opening file '/var/tmp/#sql_

Error: Can't create/write to file '/var/tmp/#sql_

Atrás han quedado los días en que era suficiente un simple cambio en /etc/my.cnf. Entra en el nuevo mundo systemd.

systemd en sí tiene un límite que controla la cantidad de archivos que un servicio puede abrir, independientemente de lo que esté configurado en /etc/my.cnf o /etc/security/limits.conf.

Me encontré en tener que hacer esto porque yo estaba recibiendo los siguientes errores en la base de datos cuando ejecutaba mysqldump, mysqlcheck, etc:

Out of resources when opening file '/var/tmp/#sql_5d6_0.MAD' (Errcode: 24)
Out of resources when opening file '/var/tmp/#sql_531c_0.MAI' (Errcode: 24)
Can't create/write to file '/var/tmp/#sql_5d6_0.MAI' (Errcode: 2)

error 23

Para aumentar el límite de los archivos abiertos en MariaDB (open-files-limit) si ejecutas un RHEL o CentOS 7 con systemd, haz lo siguiente.

Comprobar el límite actual establecido de archivos abiertos en MariaDB:

MariaDB [(none)]> SHOW VARIABLES LIKE 'Open_files_limit';

+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| open_files_limit | 1024  |
+------------------+-------+
1 row in set (0.00 sec)

En primer lugar, crea un nuevo directorio que contendrá los cambios en el servicio MariaDB en systemd. Al hacer los cambios aquí, vamos a hacer seguro de que la actualización de paquetes que puede sobrescribir el archivo mariadb.service no eliminan sus propios cambios:

# mkdir -p /etc/systemd/system/mariadb.service.d/

A continuación, configura systemd para que el servicio MariaDB pueda abrir más archivos:

# cat /etc/systemd/system/mariadb.service.d/limits.conf

[Service]
LimitNOFILE=10000

Con el fin de que systemd tenga en cuenta esos cambios hay que recargar el demonio systemd. Esto vuelve a cargar las configuraciones que systemd conoce, no se reinicia cualquier servicio real:

# systemctl daemon-reload

Lo anterior indica a systemd que MariaDB puede abrir archivos 10000 si lo requiere. Reinicia el servicio MariaDB ahora para hacer que se guarden esos cambios:

# systemctl restart mariadb.service

Y ya está.

Volver a comprobar el límite actual establecido de archivos abiertos en MariaDB:

MariaDB [(none)]> SHOW VARIABLES LIKE 'Open_files_limit';

+------------------+-------+
| Variable_name    | Value |
+------------------+-------+
| open_files_limit | 10000  |
+------------------+-------+
1 row in set (0.00 sec)

Si es necesario aumentar el valor de /etc/systemd/system/mariadb.service.d/limits.conf

Estos cambios también son "documentados" en el archivo de servicio mariadb.service en systemd.

# cat /usr/lib/systemd/system/mariadb.service
...
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades.  If you want to customize, the
# best way is to create a file "/etc/systemd/system/mariadb.service",
# containing
#    .include /lib/systemd/system/mariadb.service
#    ...make your changes here...
# or create a file "/etc/systemd/system/mariadb.service.d/foo.conf",
# which doesn't need to include ".include" call and which will be parsed
# after the file mariadb.service itself is parsed.
#
# For more info about custom unit files, see systemd.unit(5) or
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F

# For example, if you want to increase mariadb's open-files-limit to 10000,
# you need to increase systemd's LimitNOFILE setting, so create a file named
# "/etc/systemd/system/mariadb.service.d/limits.conf" containing:
#    [Service]
#    LimitNOFILE=10000

# Note: /usr/lib/... is recommended in the .include line though /lib/...
# still works.
# Don't forget to reload systemd daemon after you change unit configuration:
# root> systemctl --system daemon-reload

 

 

Jesus_Caceres