2016-04-27 114 views
3
​​

1167:M 13年4月26日:00:34.667#Redis的不能设置最大打开文件到10032,因为操作系统错误的:不允许操作。 1167:M 26 Apr 13:00:34.667#当前最大打开文件数为4096. maxclients已减少到4064以弥补低限。如果你需要更高的maxclients增加'ulimit -n'。 1167:M 26 Apr 13:00:34.685#创建服务器TCP侦听套接字192.34.62.56:6379:名称或服务未知 1135:M 26 Apr 20:34:24.308#您要求maxclients 10000最大10032个文件描述符。 1135:M 26 Apr 20:34:24.309#由于操作系统错误,Redis无法将最大打开文件设置为10032:操作不允许。 1135:M 26 Apr 20:34:24.309#当前的最大打开文件数是4096. maxclients已被降低到4064以弥补较低的ulimit。如果你需要更高的maxclients增加'ulimit -n'。 1135:M 26 Apr 20:34:24.330#创建服务器TCP监听套接字192.34.62.56:6379:名称或服务未知为什么Redis的不能设置最大打开文件

回答

0

你只需要在控制台命令:

sudo ulimit -n 65535 
+0

命令在16.04 Ubuntu上找不到 – user1735921

5

嗯,这是一个有点晚了这个职位,但因为我只花了很多时间(整个晚上)来配置在Ubuntu 16.04新的Redis服务器3.0.6。我想我应该写下我如何做,这样别人就不必浪费时间...

对于新安装的redis服务器,您可能会在redis日志文件中看到以下问题,它是/var/log/redis/redis-server.log

最大打开文件

3917:M 16 Sep 21:59:47.834 # You requested maxclients of 10000 requiring at least 10032 max file descriptors. 
3917:M 16 Sep 21:59:47.834 # Redis can't set maximum open files to 10032 because of OS error: Operation not permitted. 
3917:M 16 Sep 21:59:47.834 # 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'. 

我已经看到了很多帖子,告诉您的修改

/etc/security/limits.conf 
redis soft nofile 10000 
redis hard nofile 10000 

/etc/sysctl.conf 
fs.file-max = 100000 

这可能在Ubuntu 14.04的工作,但它肯定不是作品在Ubuntu 16.04。我想这与改变从新贵到systemd有关,但我不是Linux内核的专家!

为了解决这个问题,你必须做的systemd方式

/etc/systemd/system/redis.service 
[Service] 
... 
User=redis 
Group=redis 
# should be fine as long as you add it under [Service] block 
LimitNOFILE=65536 
... 

然后,你必须守护进程重新装载并重新启动服务

sudo systemctl daemon-reload 
sudo systemctl restart redis.service 

要检查是否正常工作,尝试猫过程限制

cat /run/redis/redis-server.pid 
cat /proc/PID/limits 

,你会看到

Max open files   65536    65536    files  
Max locked memory   65536    65536    bytes 

在这个阶段,最大打开文件就解决了。

插槽最大连接

2222:M 16 Sep 20:38:44.637 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 

内存过量

2222:M 16 Sep 20:38:44.637 # Server started, Redis version 3.0.6 
2222:M 16 Sep 20:38:44.637 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect. 

因为这两个是相关的,我们会马上解决这个问题。

sudo vi /etc/sysctl.conf 

# Add at the bottom of file 
vm.overcommit_memory = 1 
net.core.somaxconn=1024 

现在对于这些CONFIGS工作,你需要重新加载配置

sudo sysctl -p 

透明大内存页

1565:M 16 Sep 22:48:00.993 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 

要永久解决这个问题,按照日志的建议,并修改rc.local

sudo vi /etc/rc.local 

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then 
    echo never > /sys/kernel/mm/transparent_hugepage/enabled 
fi 

这需要你重新启动,备份你的数据或做任何你需要的,然后才能真正做到!

sudo reboot 

现在再次检查你的redis日志,你应该有一个redis服务器没有任何错误或警告。