Categories
Linux

Systemd services do not respect the settings in limits.conf or limits.d files.

We ran into a need to increase file descriptors for RabbitMQ running on RHEL 6. The simple solution was to add a file owned by root to /etc/security/limits.d/

85-rabbitmq.conf


# Default limit for rabbitmq which needs more
# file handles than the default user settings 

rabbitmq          soft    nofile   	49152
rabbitmq          hard    nofile	49152

And after restarting RabbitMQ, the new file descriptors count is reflected in the web admin home page.

Some time passed and we had decided to migrate to RHEL 7. We also upgraded to RabbitMQ 3.6.6. After the migration, it was discovered that the file descriptors limit was back to the default value. It was quite clear that our 85-rabbitmq.conf limits file was being ignored. After some research, it appears that systemd services will ignore the limits values.

The solution is to edit the systemd service file and add the limits value to the service. So to increase RabbitMQ’s file descriptors on RHEL / CentOS 7

vi /lib/systemd/system/rabbitmq-server.service

Add LimitNOFILE to the Service section


[Unit]
Description=RabbitMQ broker
After=syslog.target network.target

[Service]
Type=notify
User=rabbitmq
Group=rabbitmq
WorkingDirectory=/var/lib/rabbitmq
ExecStart=/usr/sbin/rabbitmq-server
ExecStop=/usr/sbin/rabbitmqctl stop
NotifyAccess=all
TimeoutStartSec=3600
LimitNOFILE=49152

[Install]
WantedBy=multi-user.target

A reference to all the limits settings can be found here https://www.freedesktop.org/software/systemd/man/systemd.exec.html#

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.