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 9999999
* hard nproc 9999999
* soft nofile 9999999
* hard nofile 9999999
root soft nproc 9999999
root hard nproc 9999999
root soft nofile 9999999
root hard nofile 9999999

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

session required pam_limits.so

Edit the following file /etc/systemd/user.conf: – Add the following line

DefaultLimitNOFILE=9999999

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

fs.file-max=9999999
vm.max_map_count=9999999

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=9999999
# processes/threads
LimitNPROC=9999999
# 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 22.04 Modify Open File Limits

Leave a Reply

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