To check current limits

ulimit -a

Edit /etc/security/limits.conf – Add the following lines, also remember like root is a username, you should add all the usernames on which you wish to increase the limit

* soft nproc 100000
* hard nproc 100000
* soft nofile 100000
* hard nofile 100000
root soft nproc 100000
root hard nproc 100000
root soft nofile 100000
root hard nofile 100000

Edit /etc/pam.d/common-session – Add the following line

session required pam_limits.so

Edit /etc/sysctl.conf – Add the following line

fs.file-max = 1000000

Edit individual service file like for MongoDB Database – Edit /lib/systemd/system/mongod.service

[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target

[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --config /etc/mongod.conf
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=1000000
# processes/threads
LimitNPROC=1000000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

[Install]
WantedBy=multi-user.target

Run the following command in terminal

systemctl daemon-reload

Done

Ubuntu 16.04 Modify Open File Limits

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.