简体   繁体   English

Ubuntu 16.04 Systemd Redis与ulimit问题

[英]Ubuntu 16.04 systemd redis issues with ulimit

I have been having issues with our new redis server after swapping from Ubuntu 14.04 to 16.04. 从Ubuntu 14.04切换到16.04后,我的新Redis服务器出现了问题。 The configuration of the open files limit using all the guides says to change the /etc/security/limits.conf with the following settings 使用所有指南配置打开文件的限制,请使用以下设置更改/etc/security/limits.conf。

*    soft nofile 65535
*    hard nofile 65535
root soft nofile 65535
root hard nofile 65535

And also to add to /etc/pam.d/common-session and /etc/pam.d/common-session-noninteractive 并且还要添加到/etc/pam.d/common-session和/etc/pam.d/common-session-noninteractive

session required pam_limits.so

I have made all of these changes but redis is still starting up with a file limit of 4096 which under production load we quickly reach max connections. 我进行了所有这些更改,但是redis仍以文件限制4096启动,在生产负载下,我们很快达到了最大连接数。

After much searching I finally found that systemd has a standard limit of 4096 and regardless of what you set at the system level the systemd level will always take precedence. 经过大量搜索之后,我最终发现systemd的标准限制为4096,无论您在系统级别设置什么,systemd级别始终优先。 The fix for this is to change the systemd open file limit by editing /etc/systemd/system.conf and adding the following setting 解决此问题的方法是通过编辑/etc/systemd/system.conf并添加以下设置来更改systemd打开文件的限制

DefaultLimitNOFILE=65536

It seems that there are a lot of default settings in systemd which override the system settings so have to be set in systemd 似乎systemd中有很多默认设置会覆盖系统设置,因此必须在systemd中进行设置

So if its any use for people these are my final settings for a Ubuntu 16.04 server for running production redis. 因此,如果对人有用,那么这些是我对运行生产Redis的Ubuntu 16.04服务器的最终设置。

Edit /etc/systemd/system.conf (sudo nano /etc/systemd/system.conf) and add 编辑/etc/systemd/system.conf(sudo nano /etc/systemd/system.conf)并添加

DefaultLimitNOFILE=65536

Edit /etc/security/limits.conf (sudo nano /etc/security/limits.conf) and add 编辑/etc/security/limits.conf(sudo nano /etc/security/limits.conf)并添加

*    soft nofile 64000
*    hard nofile 64000
root soft nofile 64000
root hard nofile 64000

Edit /etc/pam.d/common-session (sudo nano /etc/pam.d/common-session) and add 编辑/etc/pam.d/common-session(sudo nano /etc/pam.d/common-session)并添加

session required pam_limits.so

Edit /etc/pam.d/common-session-noninteractive (sudo nano /etc/pam.d/common-session-noninteractive) and add 编辑/etc/pam.d/common-session-noninteractive(sudo nano /etc/pam.d/common-session-noninteractive)并添加

session required pam_limits.so

Edit /etc/rc.local (sudo nano /etc/rc.local) and add 编辑/etc/rc.local(sudo nano /etc/rc.local)并添加

sysctl -w net.core.somaxconn=65535

Edit /etc/sysctl.conf (sudo nano /etc/sysctl.conf) and add 编辑/etc/sysctl.conf(sudo nano /etc/sysctl.conf)并添加

vm.overcommit_memory = 1

Edit /etc/rc.local (sudo nano /etc/rc.local) and add 编辑/etc/rc.local(sudo nano /etc/rc.local)并添加

echo never > /sys/kernel/mm/transparent_hugepage/enabled

The sysctl values net.core.somaxconn and vm.overcommit_memory are note related to ulimit or the number of open files. sysctl值net.core.somaxconnvm.overcommit_memory与ulimit或打开文件的数量有关。 They are related to: 它们与以下内容有关:

If your problem is with the limit of opened files (what ulimit -Sn/-Hn handles) then I would not suggest to play with this, unless you know exactly what you are doing. 如果您的问题在于打开文件的限制( ulimit -Sn/-Hn句柄),那么除非您确切知道自己在做什么,否则我不建议您这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM