2014年12月18日 星期四

CentOS 7, systemd, redis, max open files

在CentOS 7安裝好Redis,預設redis會開啟10000的檔案,所以啟動之後log總會顯示以下錯誤:
Current maximum open files is 1024. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
即使修改/etc/security/limits.conf也沒有用,這個檔案一開頭就說:
This file sets the resource limits for the users logged in via PAM.
It does not affect resource limits of the system services.
因為CentOS 7用systemd換掉ntsysv,網路上有提示解法,就是修改redis的systemd配置檔案/lib/systemd/system/redis.service正確來說是/etc/systemd/system/redis.service.d/limit.conf,把LimitNOFILE=10240後面的數字改成所需的。

修改之後,要先重新載入systemd,否則會出現警告。如下
$ service redis restart
Redirecting to /bin/systemctl restart  redis.service
Warning: Unit file of redis.service changed on disk, 'systemctl daemon-reload' recommended.