{"id":12425,"date":"2019-03-26T23:38:01","date_gmt":"2019-03-26T23:38:01","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=12425"},"modified":"2019-03-26T23:38:01","modified_gmt":"2019-03-26T23:38:01","slug":"how-to-increase-number-of-open-files-limit-in-linux","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/how-to-increase-number-of-open-files-limit-in-linux\/","title":{"rendered":"How to Increase Number of Open Files Limit in Linux"},"content":{"rendered":"<p>In Linux, you can change the maximum amount of open files. You may modify this number by using the\u00a0<strong>ulimit<\/strong>command. It grants you the ability to control the resources available for the shell or process started by it.<\/p>\n<p><b>Read Also:<\/b>\u00a0<a href=\"https:\/\/www.tecmint.com\/set-limits-on-user-processes-using-ulimit-in-linux\/\" target=\"_blank\" rel=\"noopener\">Set Linux Running Processes Limits on Per-Userl Level<\/a><\/p>\n<p>In this short tutorial we will show you how to check your current limit of open files and files descriptions, but to do so, you will need to have root access to your system.<\/p>\n<p>First, Lets see how we can find out the maximum number of opened file descriptors on your Linux system.<\/p>\n<h3>Find Linux Open File Limit<\/h3>\n<p>The value is stored in:<\/p>\n<pre># cat \/proc\/sys\/fs\/file-max\r\n\r\n<strong>818354<\/strong><\/pre>\n<p>The number you will see, shows the number of files that a user can have opened per login session. The result might be different depending on your system.<\/p>\n<p>For example on a\u00a0<strong>CentOS<\/strong>\u00a0server of mine, the limit was set to\u00a0<strong>818354<\/strong>, while on\u00a0<strong>Ubuntu<\/strong>\u00a0server that I run at home the default limit was set to\u00a0<strong>176772<\/strong>.<\/p>\n<p>If you want to see the hard and soft limits, you can use the following commands:<\/p>\n<h4>Check Hard Limit in Linux<\/h4>\n<pre># ulimit -Hn\r\n\r\n<strong>4096<\/strong>\r\n<\/pre>\n<h4>Check Soft Limits in Linux<\/h4>\n<pre># ulimit -Sn\r\n\r\n<strong>1024<\/strong>\r\n<\/pre>\n<p>To see the hard and soft values for different users, you can simply switch user with\u00a0<strong>\u201csu\u201d<\/strong>\u00a0to the user which limits you want to check.<\/p>\n<p>For example:<\/p>\n<pre># su marin\r\n$ ulimit -Sn\r\n\r\n<strong>1024<\/strong>\r\n<\/pre>\n<pre>$ ulimit -Hn\r\n\r\n<strong>4096<\/strong>\r\n<\/pre>\n<h3>How to Check System wide File Descriptors Limits in Linux<\/h3>\n<p>If you are running a server, some of your applications may require higher limits for opened file descriptors. A good example for such are\u00a0<strong>MySQL\/MariaDB<\/strong>\u00a0services or\u00a0<strong>Apache<\/strong>\u00a0web server.<\/p>\n<p>You can increase the limit of opened files in Linux by editing the kernel directive\u00a0<code>fs.file-max<\/code>. For that purpose, you can use the\u00a0<strong>sysctl<\/strong>\u00a0utility.<\/p>\n<p><strong>Sysctl<\/strong>\u00a0is used to\u00a0<a href=\"https:\/\/www.tecmint.com\/change-modify-linux-kernel-runtime-parameters\/\" target=\"_blank\" rel=\"noopener\">configure kernel parameters at runtime<\/a>.<\/p>\n<p>For example, to increase open file limit to\u00a0<strong>500000<\/strong>, you can use the following command as root:<\/p>\n<pre># sysctl -w fs.file-max=500000\r\n<\/pre>\n<p>You can check the current value for opened files with the following command:<\/p>\n<pre>$ cat \/proc\/sys\/fs\/file-max\r\n<\/pre>\n<p>With the above command the changes you have made will only remain active until the next reboot. If you wish to apply them permanently, you will have to edit the following file:<\/p>\n<pre># vi \/etc\/sysctl.conf\r\n<\/pre>\n<p>Add the following line:<\/p>\n<pre>fs.file-max=500000<\/pre>\n<p>Of course, you can change the number per your needs. To verify the changes again use:<\/p>\n<pre># cat \/proc\/sys\/fs\/file-max\r\n<\/pre>\n<p>Users will need to logout and login again for the changes to take effect. If you want to apply the limit immediately, you can use the following command:<\/p>\n<pre># sysctl -p\r\n<\/pre>\n<h3>Set User Level Open File limits in Linux<\/h3>\n<p>The above examples, showed how to set global limits, but you may want to apply limits per user basis. For that purpose, as user root, you will need to edit the following file:<\/p>\n<pre># vi \/etc\/security\/limits.conf\r\n<\/pre>\n<p>If you are a Linux administrator, I suggest you that you become very familiar with that file and what you can do to it. Read all of the comments in it as it provides great flexibility in terms of managing system resources by limiting users\/groups on different levels.<\/p>\n<p>The lines that you should add take the following parameters:<\/p>\n<pre>&lt;domain&gt; \u00a0 \u00a0 \u00a0 \u00a0&lt;type&gt; \u00a0&lt;item&gt; \u00a0&lt;value&gt;\r\n<\/pre>\n<p>Here is an example of setting a soft and hard limits for user\u00a0<strong>marin<\/strong>:<\/p>\n<pre>## Example hard limit for max opened files\r\n<strong>marin \u00a0 \u00a0 \u00a0 \u00a0hard nofile 4096<\/strong>\r\n## Example soft\u00a0limit for max opened files\r\n<strong>marin \u00a0 \u00a0 \u00a0 \u00a0soft nofile 1024<\/strong>\r\n<\/pre>\n<h3>Final thoughts<\/h3>\n<p>This brief article showed you a basic example of how you can check and configure global and user level limits\u00a0for maximum number of opened files.<\/p>\n<p>While we just scratched the surface, I highly encourage you to have a more detailed look and read regarding\u00a0<strong>\/etc\/sysctl.conf<\/strong>\u00a0and\u00a0<strong>\/etc\/security\/limits.conf<\/strong>\u00a0and learn how to use them. They will be of great help for you one day.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/increase-set-open-file-limits-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Linux, you can change the maximum amount of open files. You may modify this number by using the\u00a0ulimitcommand. It grants you the ability to control the resources available for the shell or process started by it. Read Also:\u00a0Set Linux Running Processes Limits on Per-Userl Level In this short tutorial we will show you how &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/26\/how-to-increase-number-of-open-files-limit-in-linux\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Increase Number of Open Files Limit in Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12425","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=12425"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12425\/revisions"}],"predecessor-version":[{"id":12426,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/12425\/revisions\/12426"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=12425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=12425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=12425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}