Cannot change the maximum open files per process with sysctl
For Ubuntu 17.04. See this solution.
Prior to Ubuntu 17.04:
I don't know why the above settings don't work but it seems you can get the same result by using the /etc/security/limits.conf
file.
Set the limit in /etc/security/limits.conf
sudo bash -c "echo '* - nofile 10240' >> /etc/security/limits.conf"
*
means all users. You can replace it by a specific username.-
means bothsoft
andhard
for the type of limit to be enforced. Hard can only be modified by the superuser. Soft can be modified by a non-root user and cannot be superior to hard.nofile
is the Maximum number of open files parameter.10240
is the new limit.
Reload
Logout and log back in. sudo sysctl -p
doesn't seem to be enough to reload.
You can check the new limit with:
ulimit -n
Tested on Ubuntu 16.04 and CentOS 6. Inspired by this answer.
Max open files for working process
As a system administrator: The /etc/security/limits.conf
file controls this on most Linux installations; it allows you to set per-user limits. You'll want a line like myuser - nofile 1000
.
Within a process: The getrlimit and setrlimit calls control most per-process resource allocation limits. RLIMIT_NOFILE
controls the maximum number of file descriptors. You will need appropriate permissions to call it.
Why redis can not set maximum open file
Redis will never change the maximum open files.
This is a OS configuration and it can be configured on a per user basis also. The error is descriptive and tells you: "increase 'ulimit -n'"
You can refer to this blog post on how to increase the maximum open files descriptors:
http://www.cyberciti.biz/faq/linux-increase-the-maximum-number-of-open-files/
Maximum number of open filehandles per process on OSX (and how to increase)
found on http://krypted.com/mac-os-x/maximum-files-in-mac-os-x/:
sysctl -w kern.maxfilesperproc=20000
Ruby: Too many open files @ rb_sysopen
EMFILE
is too many files opened in your process.ENFILE
is too many files opened in the entire system.
So Errno::EMFILE
is due to the ruby process opening too many files. This limit is probably set to the default 1024
can be seen with:
$ulimit -n
1024
Instead of:
$ulimit
unlimited
You can raise the limit using this method.
How do I increase the open files limit for a non-root user?
The ulimit
command by default changes the HARD limits, which you (a user) can lower, but cannot raise.
Use the -S option to change the SOFT limit, which can range from 0-{HARD}.
I have actually aliased ulimit
to ulimit -S
, so it defaults to the soft limits all the time.
alias ulimit='ulimit -S'
As for your issue, you're missing a column in your entries in /etc/security/limits.conf
.
There should be FOUR columns, but the first is missing in your example.
* soft nofile 4096
* hard nofile 4096
The first column describes WHO the limit is to apply for. '*' is a wildcard, meaning all users. To raise the limits for root, you have to explicitly enter 'root' instead of '*'.
You also need to edit /etc/pam.d/common-session*
and add the following line to the end:
session required pam_limits.so
Related Topics
Linux: Disable Using Loopback and Send Data via Wire Between 2 Eth Cards of One Comp
Linux Ssh Bash Fork Retry: No Child Processes
Using Output of Previous Commands in Bash
In Linux, How to Find Find Directory with The Most Subdirectories or Files
How to Touch a File and Mkdir If Needed in One Line
How to Answer Yes in Bash Script
How to Check If Jboss Is Running on Unix Server
How Are Posix Threads Implemented on Linux
Live Socket Monitoring with Netlink Inet_Diag
Qemu on Raspberry Pi Arch Linux Latest Sd Image
The Repository 'Http://Dl.Google.Com/Linux/Chrome/Deb Stable Release' Is Not Signed
Difference Between Arm-None-Eabi and Arm-Linux-Gnueabi
Best Way to Build Cross Toolchains on MAC Os X
Ansible: Check If Service Is Listening on a Specific Port
How to Use Source Command Within Jenkins Pipeline Script