Ubuntu ulimit ихэсгэх

Дусал нэвтэрхий толь-с
03:13, 17 Арванхоёрдугаар сар 2020-ий байдлаарх Almas (Яриа | оруулсан хувь нэмэр) хэрэглэгчийн хийсэн залруулга

Set Permanently ulimit -n / open files in ubuntu


Few days ago, my golang app in development server halted, then i check app’s log.

2018/03/26 10:06:56.373 [server.go:2921] [HTTP] http: Accept error: accept tcp [::]:80: accept4: too many open files; retrying in 1s

so, i check ulimit in my server, got open files configuration is default, 1024. Then i try set to 65535 which is that configuration is standart configuration in production server to avoid that error. Just typing as following :

  1. set limit

user@ubuntu:~$ ulimit -n 65535

When i relogin, i check again open files configuration, got 1024 or back to default. So, i want to set that new configuration (65535) permanently in my server. You can do it with following steps below :

  1. available limit

user@ubuntu:~$ ulimit -n 1024

  1. To increase the available limit to say 65535

user@ubuntu:~$ sudo vim /etc/sysctl.conf

  1. add the following line to it

fs.file-max = 65535

  1. run this to refresh with new config

user@ubuntu:~$ sudo sysctl -p

if you got error “sysctl: permission denied on key ‘fs.file-max’”, you can skip that step, then you doing steps as below :

  1. edit the following file

user@ubuntu:~$ sudo vim /etc/security/limits.conf

  1. add following lines to it
  • soft nproc 65535
  • hard nproc 65535
  • soft nofile 65535
  • hard nofile 65535

root soft nproc 65535 root hard nproc 65535 root soft nofile 65535 root hard nofile 65535

  1. edit the following file

user@ubuntu:~$ sudo vim /etc/pam.d/common-session

  1. add this line to it

session required pam_limits.so

  1. logout and login and try the following command

user@ubuntu:~$ ulimit -n 65535

[1]