Hitting too many open file limit for apache? In the previous OS versions, changing limits like open file number would be set in
/etc/security/limits.conf
or directly inside the start up script. In some ways the new method brings better organization to the limits, but its change is very confusing to people who were expecting the same. I myself was befuddled with the open file limit with the web server saying “Too many open files” and despite changing limits in the old way (which still exists), it just wasn’t solving it.
The limits are set according to specification set here:
/usr/lib/systemd/system/[name of service].service /usr/lib/systemd/system/httpd.service // apache example /usr/lib/systemd/system/mariadb.service // mariadb example
But it’s not recommended that you edit that. It’s because that’ll be over written with package update. What you should edit is:
/etc/systemd/system/[name of service].service.d/limits.conf
Often the folder for it won’t exist either. So you’ll have to make the folder first like (with httpd example):
# mkdir -p /etc/systemd/system/httpd.service.d/
Now create/edit/append a file so that the contents would be like below.
# cat /etc/systemd/system/httpd.service.d/limits.conf [Service] LimitNOFILE=20000
Now reload the system daemon so it learns of the update. This action alone doesn’t not restart any service.
# systemctl daemon-reload
And also restart the service itself.
# systemctl restart httpd
That’s it!
How can you verify if the limit is applied correctly?
You can type
for apache or any other user that you want to check for. You can check here for man of ulimit function: http://ss64.com/bash/ulimit.html
How do we set the other parameters such as the stack size, no of process etc.
What is the corresponding parameter for it like LimitNOFILE
Can you point to the relevant link
You can look up via man systemd.exec
If you prefer online version: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
Hi,
A small correction;
The “su – apache -c ‘ulimit -aHS’ -s ‘/bin/bash'” responds to the user not the process.
To find the limits for the process, point to the PID ogf the wrapper:
e.g. for haproxy
pidof haproxy-systemd-wrapper | awk ‘{print “/proc/”$1″/limits”}’ | xargs cat | grep -i open
You can probably simplify your steps by using
systemctl edit [name of service].service
That I believe will take care of both creating the directory and file structure and take care of daemon-reload once editing is complete.
spot on! works perfectly!