macos os x 终端、ssh 和太多打开的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10095796/
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-10-21 09:03:17  来源:igfitidea点击:

Os x terminal, ssh , and too many open files

macossolrsshterminal

提问by jayunit100

Hi guys : I have some code that runs several rest queries over a connection that is ssh forwarded to an AWS machine (fyi: these queries are hitting a Solr server running on this machine), and the queries run against my localhost (which is forwarded to the AWS instance).

大家好:我有一些代码可以通过 ssh 转发到 AWS 机器的连接运行多个其余查询(仅供参考:这些查询正在访问在本机上运行的 Solr 服务器),并且查询针对我的本地主机运行(已转发到 AWS 实例)。

The code initially runs great getting data as necessary, but after running for a while, the code stalls (in eclipse).

该代码最初运行良好,需要时获取数据,但运行一段时间后,代码停止(在 eclipse 中)。

At this exact moment, the terminal (i.e. where I have started my ssh tunnel) goes completely frozen, filling up with the String :

在这个确切的时刻,终端(即我开始我的 ssh 隧道的地方)完全冻结,用 String 填充:

"accept : too many open files"

“接受:打开的文件太多”

Because this infinite print is not associated with a bash terminal (i.e. I can't tell wether the ssh connection is still alive or not, and there is no text indicating which shell im in... just unpridled, relentless print statements) I cant tell wether it's coming from amazon, or from my client terminal.

因为这个无限打印与 bash 终端无关(即我无法判断 ssh 连接是否仍然存在,并且没有文本表明我在哪个 shell 中......只是无耻的、无情的打印语句)我不能告诉它是来自亚马逊还是来自我的客户端。

I want to find the cause of this behavior and pinpoint the machine which is causing my terminal to explode

我想找到这种行为的原因并查明导致我的终端爆炸的机器

To test which of the two machines was causing the infinite print outs of the error, I ran the ulimit command on the server... and found that the max number of open files allowed (on the aws server) was well above the amount of open files (also determined using ulimit) at any given time while the client program (running from my ide)is executing.

为了测试两台机器中的哪一台导致了错误的无限打印,我在服务器上运行了 ulimit 命令......发现允许的最大打开文件数(在 aws 服务器上)远高于在客户端程序(从我的 ide 运行)执行时的任何给定时间打开文件(也使用 ulimit 确定)

I did the same test on my client , and found no significant increase in the number of open files.

我对我的客户端做了同样的测试,发现打开文件的数量没有显着增加。

Some side details : I'm running several hundreds of queries into a SOLR server that has over 100GB of data in a short time period.

一些侧面细节:我正在对一个在短时间内拥有超过 100GB 数据的 SOLR 服务器运行数百个查询。

Any hints on how to determine why my sshd mac os x terminal is dying and infinitely printing this messagewould be potentially very useful to me. Of course, wether or not they were specific to solr. That said, any insights into why this would happen when using a solr service may also helpto solve this problem.

关于如何确定我的 sshd mac os x 终端为什么会死掉并无限打印此消息的任何提示对我来说可能非常有用。当然,无论它们是否特定于 solr。也就是说,对使用 solr 服务时为什么会发生这种情况的任何见解也可能有助于解决这个问题。

回答by nickdos

You could try looking at ulimit(via Terminal type):

您可以尝试查看ulimit(通过终端类型):

ulimit -a

Specifically, check the value for open files. On my machine (OS X) it reports 256. You might want to try increasing it to 512:

具体来说,检查 的值open files。在我的机器 (OS X) 上,它报告 256。您可能想尝试将其增加到 512:

ulimit -n 512

回答by ethicalhack3r

This seems to have worked for me:

这似乎对我有用:

echo 'kern.maxfiles=20480' | sudo tee -a /etc/sysctl.conf
echo -e 'limit maxfiles 8192 20480\nlimit maxproc 1000 2000' | sudo tee -a /etc/launchd.conf
echo 'ulimit -n 4096' | sudo tee -a /etc/profile

Then restart OS X.

然后重新启动 OS X。

https://superuser.com/questions/302754/increase-the-maximum-number-of-open-file-descriptors-in-snow-leopard

https://superuser.com/questions/302754/increase-the-maximum-number-of-open-file-descriptors-in-snow-leopard

回答by geekosaur

There isn't enough information here to be certain, but it sounds like sshis hitting its per-process file descriptor limit while trying to accept connections to the forwarded socket locally, which in turn suggests that already open connections are not being closed in a timely fashion. You can run sshwith -dto see details of connections and disconnections; you might want to capture its stderr and use a script to track the socket operations as they'll be buried in a lot of other debug information.

这里没有足够的信息可以确定,但听起来像是ssh在尝试在本地接受到转发套接字的连接时达到了每个进程的文件描述符限制,这反过来表明已经打开的连接没有被及时关闭时尚。您可以运行sshwith-d查看连接和断开连接的详细信息;您可能想要捕获它的 stderr 并使用脚本来跟踪套接字操作,因为它们将隐藏在许多其他调试信息中。

Note that sshitself may limit its open file descriptors beyond the default to avoid denial of service attacks on its forwarded port; I don't see any indication of this in the documentation, but it's the kind of thing I would expect.

请注意,ssh它本身可能会限制其打开的文件描述符超出默认值,以避免对其转发端口的拒绝服务攻击;我在文档中没有看到任何关于这一点的迹象,但这是我所期望的。

回答by UserszrKs

sudo launchctl limit maxfiles 1000000 unlimited

or

或者

sudo sysctl -w kern.maxfilesperproc=1000000
sudo sysctl -w kern.maxfilesperproc=18000

To make the change permanent, use sudo to put your settings in /etc/sysctl.conf (which you may have to create), like this:

要使更改永久化,请使用 sudo 将您的设置放在 /etc/sysctl.conf(您可能必须创建)中,如下所示:

kern.maxfiles=20480 
kern.maxfilesperproc=18000

Note - select the number at your own risk

注意 - 选择号码风险自负

回答by Mohamed Anees A

The following command helped me,

以下命令帮助了我,

launchctl limit maxfiles