2016-04-27 119 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服務器沒有任何錯誤或警告。