Linux 如何在 Ubuntu 中增加 Neo4j 的最大文件打开限制 (ulimit)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21515463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:56:40  来源:igfitidea点击:

How to increase Neo4j's maximum file open limit (ulimit) in Ubuntu?

linuxubuntuneo4jlimitulimit

提问by theharshest

Currently ulimit -nshows 10000. I want to increase it to 40000. I've edited "/etc/sysctl.conf" and put fs.file-max=40000. I've also edited /etc/security/limits.confand updated hard and soft values. But still ulimit shows 10000. After making all these changes I rebooted my laptop. I've access to root password.

目前ulimit -n显示10000. 我想把它增加到40000. 我已经编辑了“/etc/sysctl.conf”并将fs.file-max=40000. 我还编辑/etc/security/limits.conf和更新了硬值和软值。但仍然 ulimit 显示10000. 完成所有这些更改后,我重新启动了我的笔记本电脑。我可以访问root密码。

usr_name@usr_name-lap:/etc$ /sbin/sysctl fs.file-max
fs.file-max = 500000

Added following lines in /etc/security/limits.conf-

/etc/security/limits.conf-中添加了以下几行

*     soft    nofile          40000
*     hard    nofile          40000

I also added following line in /etc/pam.d/su-

我还添加了以下行/etc/pam.d/su-

session??? required?? pam_limits.so

I've tried every possible way as given on other forums, but I can reach up to a maximum limit of 10000, not beyond that. What can be the issue?

我已经尝试了其他论坛上给出的所有可能的方法,但我可以达到的最大限制为10000,不能超过。可能是什么问题?

I'm making this change because neo4jthrows maximum open file limits reached error.

我进行此更改是因为neo4j引发最大打开文件限制达到错误。

采纳答案by Martin Larivière

I am using Debian but this solution should work fine with Ubuntu.
You have to add a line in the neo4j-servicescript.
Here is what I have done :

我正在使用 Debian,但此解决方案应该适用于 Ubuntu。
您必须在neo4j-service脚本中添加一行。
这是我所做的:

nano /etc/init.d/neo4j-service
Add ? ulimit –n 40000? just before the start-stop-daemon linein the do_start section

nano /etc/init.d/neo4j-service
添加?ulimit –n 40000? 就在之前启动-停止守护线do_start节

Note that I am using version 2.0 Enterprise edition. Hope this will help you.

请注意,我使用的是 2.0 企业版。希望这会帮助你。

回答by abligh

You could alter the init script for neo4jto do a ulimit -n 40000before running neo4j.

你可以改变为init脚本neo4julimit -n 40000运行前neo4j

However, I can't help but feel you are barking up the wrong tree. Does neo4jlegitimately need more than 10,000 open file descriptors? This sounds very much like a bug in neo4jor the way you are using it. I would try to address that.

然而,我不禁觉得你在吠错树。是否neo4j合法需要1个万多打开的文件描述符?这听起来很像一个错误neo4j或您使用它的方式。我会尝试解决这个问题。

回答by Sambhav Sharma

What you are doing will not work for root user. Maybe you are running your services as root and hence you don't get to see the change.

您正在做的事情对 root 用户不起作用。也许您以 root 身份运行您的服务,因此您看不到更改。

To increase the ulimit for root user you should replace the *by root. *does not apply for root user. Rest is the same as you did. I will re-quote it here.

要增加 root 用户的 ulimit,您应该用*root替换。*不适用于root用户。休息和你一样。我会在这里重新引用它。

Add the following lines to the file: /etc/security/limits.conf

将以下行添加到文件中: /etc/security/limits.conf

root soft  nofile 40000

root hard  nofile 40000

And then add following line in the file: /etc/pam.d/common-session

然后在文件中添加以下行: /etc/pam.d/common-session

session required pam_limits.so

This will update the ulimit for root user. As mentioned in comments, you may don't even have to reboot to see the change.

这将更新 root 用户的 ulimit。正如评论中提到的,您甚至可能不必重新启动即可看到更改。

回答by minhas23

1) Check sysctl file-maxlimit:

1) 检查 sysctlfile-max限制:

$ cat /proc/sys/fs/file-max

If the limit is lower than your desired value, open the sysctl.confand add this line at the end of file:

如果限制低于您想要的值,请打开sysctl.conf并在文件末尾添加以下行:

fs.file-max = 65536

Finally, apply sysctllimits:

最后,应用sysctl限制:

$ sysctl -p 

2) Edit /etc/security/limits.confand add below the mentioned

2)编辑/etc/security/limits.conf并添加下面提到的

* soft     nproc          65535    
* hard     nproc          65535   
* soft     nofile         65535   
* hard     nofile         65535

These limits won't apply for rootuser, if you want to change rootlimits you have to do that explicitly:

这些限制不适用于root用户,如果您想更改root限制,您必须明确地这样做:

root soft     nofile         65535   
root hard     nofile         65535
...

3) Reboot system or add following line to the end of /etc/pam.d/common-session:

3) 重新启动系统或在末尾添加以下行/etc/pam.d/common-session

session required pam_limits.so

Logout and login again.

注销并重新登录。

4) Check soft limits:

4) 检查软限制:

$ ulimit -a

and hard limits:

和硬限制:

$ ulimit -Ha
....

open files                      (-n) 65535

Reference : http://ithubinfo.blogspot.in/2013/07/how-to-increase-ulimit-open-file-and.html

参考:http: //ithubinfo.blogspot.in/2013/07/how-to-increase-ulimit-open-file-and.html

回答by Brett

I was having the same issue, and got it to work by adding entries to /etc/security/limits.d/90-somefile.conf. Note that in order to see the limits working, I had to log out completely from the ssh session, and then log back in.

我遇到了同样的问题,并通过将条目添加到/etc/security/limits.d/90-somefile.conf. 请注意,为了查看限制是否有效,我必须从 ssh 会话中完全注销,然后重新登录。

I wanted to set the limit for a specific user that runs a service, but it seems that I was getting the limit that was set for the user I was logging in as. Here's an example to show how the ulimit is set based on authenticated user, and not the effective user:

我想为运行服务的特定用户设置限制,但似乎我得到了为我登录的用户设置的限制。下面的示例展示了如何根据经过身份验证的用户而不是有效用户设置 ulimit:

$ sudo cat /etc/security/limits.d/90-nofiles.conf
loginuser    soft    nofile   10240
loginuser    hard    nofile   10240
root         soft    nofile   10241
root         hard    nofile   10241
serviceuser  soft    nofile   10242
serviceuser  hard    nofile   10242

$ whoami
loginuser
$ ulimit -n
10240
$ sudo -i
# ulimit -n
10240    # loginuser's limit
# su - serviceuser
$ ulimit -n
10240    # still loginuser's limit.

You can use an *to specify an increase for all users. If I restart the service as the user I logged in, and add ulimit -nto the init script, I see that the initial login user's limits are in place. I have not had a chance to verify which user's limits are used during a system boot or of determining what the actual nofile limit is of the service I am running (which is started with start-stop-daemon).

您可以使用*来为所有用户指定增加。如果我以我登录的用户身份重新启动服务,并添加ulimit -n到 init 脚本中,我会看到初始登录用户的限制已经到位。我还没有机会验证在系统启动期间使用了哪些用户限制,也没有机会确定我正在运行的服务(由 start-stop-daemon 启动)的实际 nofile 限制是多少。

There's 2 approaches that are working for now:

目前有两种方法有效:

  1. add a ulimit adjustment to the init script, just before start-stop-daemon.
  2. wildcard or more extensive ulimit settings in the security file.
  1. 在 init 脚本中添加 ulimit 调整,就在 start-stop-daemon 之前。
  2. 通配符或更广泛的 ulimit 设置在安全文件中。

回答by Layke

I have lots of trouble getting this to work.

我有很多麻烦让这个工作。

Using the following allows you to update it regardless of your user permission.

无论您的用户许可如何,使用以下内容都可以让您更新它。

sudo sysctl -w fs.inotify.max_user_watches=100000

sudo sysctl -w fs.inotify.max_user_watches=100000

Edit

编辑

Just saw this from another user also on another stackexchange site (both work, but this version permanentlyupdates the system setting, rather than temporarily):

刚刚在另一个 stackexchange 站点上从另一个用户那里看到了这个(两者都有效,但这个版本会永久更新系统设置,而不是临时更新):

echo fs.inotify.max_user_watches=100000 | sudo tee -a /etc/sysctl.conf; 
sudo sysctl -p

回答by Mahattam

Try run this command it will create a *_limits.conffile under /etc/security/limits.d

尝试运行此命令,它将*_limits.conf在下面创建一个文件/etc/security/limits.d

echo "* soft nofile 102400" > /etc/security/limits.d/*_limits.conf && echo "* hard nofile 102400" >> /etc/security/limits.d/*_limits.conf

Just exit from terminal and login again and verify by ulimit -nit will set for * users

只需退出终端并再次登录并验证ulimit -n它会为 * 用户设置

回答by Sandeep kr gupta

ULIMIT configuration:

超限配置:

  1. Login by root
  2. vi security/limits.conf
  3. Make Below entry

    Ulimit configuration start for websiteuser

    website   soft   nofile    8192
    website   hard   nofile    8192
    website   soft   nproc    4096
    website   hard   nproc    8192
    website   soft   core    unlimited
    website   hard   core    unlimited
    
  4. Make Below entry for ALL USER

    Ulimit configuration for every user

    *   soft   nofile    8192
    *   hard   nofile    8192
    *   soft   nproc    4096
    *   hard   nproc    8192
    *   soft   core    unlimited
    *   hard   core    unlimited
    
  5. After modifying the file, user need to logoff and login again to see the new values.

  1. 以root身份登录
  2. vi 安全/限制.conf
  3. 在下面输入

    网站用户的Ulimit 配置启动

    website   soft   nofile    8192
    website   hard   nofile    8192
    website   soft   nproc    4096
    website   hard   nproc    8192
    website   soft   core    unlimited
    website   hard   core    unlimited
    
  4. 为所有用户输入以下条目

    每个用户的 Ulimit 配置

    *   soft   nofile    8192
    *   hard   nofile    8192
    *   soft   nproc    4096
    *   hard   nproc    8192
    *   soft   core    unlimited
    *   hard   core    unlimited
    
  5. 修改文件后,用户需要注销并再次登录才能看到新的值。

回答by jorfus

tl;dr set both the soft and hard limits

tl;dr 设置软限制和硬限制

I'm sure it's working as intended but I'll add it here just in case. For completeness the limit is set here (see below for syntax): /etc/security/limits.conf

我确定它按预期工作,但我会在这里添加它以防万一。为了完整起见,这里设置了限制(语法见下文):/etc/security/limits.conf

some_user       soft    nofile          60000
some_user       hard    nofile          60000

and activated with the following in /etc/pam.d/common-session:

并使用 /etc/pam.d/common-session 中的以下内容激活:

session required pam_limits.so

If you set only the hard limit, ulimit -awill show the default (1024): If you set only the soft the limit ulimit -a will show (4096)

如果仅设置硬限制,ulimit -a将显示默认值 (1024):如果仅设置软限制,则 ulimit -a 将显示 (4096)

If you set them both ulimit -awill show the soft limit (up to the hard limit of course)

如果你设置它们,它们ulimit -a都会显示软限制(当然是硬限制)

回答by bigkahunaburger

I did it like this

我是这样做的

echo "NEO4J_ULIMIT_NOFILE=50000" >> neo4j
mv neo4j /etc/default/