Redis: How to Increase File Descriptor Limits

Tags: November 25, 2016 8:06 PM

Problem

When you run redis server it complains can not set maximum open files because it has reached the OS max file descriptor limits. Here is the sample output.

$ ./bin/redis-server
28436:C 25 Nov 20:10:03.978 # Warning: no config file specified, using the default config. In order to specify a config file use ./bin/redis-server /path/to/redis.conf
28436:M 25 Nov 20:10:03.979 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
28436:M 25 Nov 20:10:03.979 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
28436:M 25 Nov 20:10:03.979 # 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'.
[...CUT...]

When you try to increase the maximum file descriptor using ulimit as root by issuing sudo it returns an error.

$ sudo ulimit -n 65000
sudo: ulimit: command not found

Wow, WTF is that? ulimit is a shell built so giving sudo an instruction to run a command called ulimit will not work. It will the same as statement below.

$ sudo for
sudo: for: command not found

Solution

The easiest solution is become a root user to run set the file descriptor using ulimit. Right after that run redis as normal user in single command line.

$ sudo sh -c "ulimit -n 65000 && exec su -c '/path/to/redis/bin/redis-server' rio"
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.2.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 30789
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

30789:M 25 Nov 20:33:03.362 # Server started, Redis version 3.2.5
30789:M 25 Nov 20:33:03.362 * DB loaded from disk: 0.000 seconds
30789:M 25 Nov 20:33:03.362 * The server is now ready to accept connections on port 6379

References

Share on Facebook Twitter

1 comments:

Anonymous said...

Situs Judi Slot Online Terbaik No 1 Gacor, QQ9
Pencetjudi Situs Judi Slot Online Terbaik No クイーンカジノ 1 Gacor, QQ9, QQ8. 카지노 Mesin Jackpot Deposit Pulsa Tanpa Potongan, Slot Online Pragmatic 더킹카지노 Play, Joker123,

Post a Comment