在 Debian 8.4 jessie 下启动 redis 3.0.6(从 jessie-backports 安装)时,我收到以下警告/错误:
18127:M 13 Apr 15:12:38.730 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
18127:M 13 Apr 15:12:38.730 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted.
18127:M 13 Apr 15:12:38.730 # 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'.
当以 root 身份运行时ulimit -n
我得到:
65536
redis用户的打开文件限制:
$ ps -u redis
PID TTY TIME CMD
18127 ? 00:00:00 redis-server
$ sudo grep 'open files' /proc/18127/limits
Max open files 4096 4096 files
如何增加 redis 用户的打开文件限制,以便它可以为 maxclients 设置设置适当的限制?我尝试编辑/etc/security/limits.conf
和sysctl -w fs.file-max=2459017
,但对 redis 用户都没有真正起作用。
答案1
limits.conf 不适用于 systemd 服务(https://bugzilla.redhat.com/show_bug.cgi?id=754285)
因此你应该:
编辑 /lib/systemd/system/redis-server.service 并在 [Service] 部分添加以下行(在:
User=redis
和之后Group=redis
)LimitNOFILE=65536
跑步:
systemctl daemon-reload && systemctl restart redis-server
并且...它应该得到新的限制
查看:https://sskaje.me/systemd-ulimit/
祝你好运!