Last Updated: September 18, 2016
·
14.01K
· zentralmaschine

When Redis can't set maximum open files

Problem

Say, you are on a Debian or Ubuntu system and you just ran into the problem that your Redis instance needs more open file descriptors, but your system is not allowing this.
So basically when you see this error in your logs:

# You requested maxclients of 10000 requiring at least 10032 max file descriptors.
# Redis can't set maximum open files to 10032 because of OS error: Operation not permitted
# Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.

You then might think: "It's nice that I can use ulimit -n to adjust that number, but how can I make it persistent through server restarts?"
That is where the trouble starts. You start searching the internets for how to increase max open file limits. You'll probably find a bunch of tipps that will tell you to configure your /etc/security/limits.conf accordingly, but then it doesn't work, because your redis user doesn't even use a login shell so no pam.
You hang your head in sorrow and think about giving up on computers and become a florist.

But...

Solution

Actually, Redis's init script will check if a ULIMIT variable is set and call ulimit -n $ULIMIT before starting the Redis instance.
In order to set the ULIMIT var, simply open up /etc/defaults/redis-server and uncomment the ULIMIT=65536. Restart your Redis and it will set the ulimit for your redis user correctly.

Hope this helps someone

(PS Only tested on Ubuntu)