0

Is there a way to increase the ulimit -n (open files) for an Amazon EC2 instance? I am running an amazon m3.2xlarge ubuntu instance for testing purposes. The ulimit -Hn is 4096 but I need over 10k. I have even tried temporarily getting higher instance types but no luck.

I have googled around for quite a while but there are only topics on this that are a few years old. Most suggest changing the limits.conf file found in /etc/security/limits.conf but the limit is read only so I cannot change permissions.

Are there any alternative ways to change this ?

Edit - my etc/security/limits.conf file

#*               soft    core            0
#root            hard    core            100000
root            soft    nofile          16500
root            hard    nofile          16500
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#ftp             -       chroot          /ftp
#@student        -       maxlogins       4
JerryFox
  • 615
  • 2
  • 13
  • 25

2 Answers2

4

I ran into this issue recently and resulted in editing /etc/security/limits.conf in my UserData script. It ended up looking something like this:

#!/bin/bash
echo "*   hard  nofile  65535" | tee --append /etc/security/limits.conf
echo "*   soft  nofile  65535" | tee --append /etc/security/limits.conf

Note that the 'user' for the limits.conf is *, meaning all users will have 65535 as their limit.

gorbot
  • 101
  • 1
  • 5
  • gorbot: Did this actually work for you, editing the /etc/security/limits.conf file on instance launch? I was under the impression that you would need to somehow reboot the instance after making the edits in order for changes to that file to take effect – matt5784 Feb 23 '21 at 05:40
3

If you set up the instance or you have sudo privileges, you can change those configuration files. Just prepend your command to open the file with sudo, (example sudo vi /etc/security/limits.conf).

datasage
  • 19,153
  • 2
  • 48
  • 54
  • thanks! I was able to edit the file but it still has not helped changing the ulimit unfortunately – JerryFox Jul 21 '14 at 17:00
  • I believe the config settings are only used at boot. Each version of Linux handles this a bit differently, but you will probably need to reboot to take advantage of the new limits. – datasage Jul 21 '14 at 17:13
  • hmm I rebooted a couple of times. Maybe my limits.conf file is not correct, Ive included it in the post – JerryFox Jul 21 '14 at 17:23
  • I think the `#` is treating the line as a comment. – datasage Jul 21 '14 at 17:50
  • Yeah I thought that might have been the case when checking out some of the other files but even uncommenting those two specifically & rebooting, the maximum is still 4096 (no change) – JerryFox Jul 21 '14 at 18:02
  • Finally got it following http://stackoverflow.com/questions/10558876/from-terminal-in-ubuntu-change-ulimit-for-file-descriptor-number?rq=1 Needed to uncomment something from /parm.d/su – JerryFox Jul 21 '14 at 18:08
  • Also note that, per the comment in the top of the file on my EC2 instances, the settings in this file only apply to "users logged in via PAM". – BogeyMan Apr 17 '20 at 03:00