我想在 ubuntu(所有进程,所有用户)上设置系统范围的 ulimit。
我该如何设置?
谢谢
J.P
我正在运行 Ubuntu 10.04 (lucid) samba 文件服务器。我有一个 Windows 7 客户端,它可以打开大量文件,同时一次复制数千个小文件。它收到错误“打开的文件太多”,此时等待几秒钟并单击“再试一次”继续下载。
我发现许多参考文献都说要增加 Samba 可用的打开文件的数量来解决问题。我认为这是一个好主意,我正在拼命尝试这样做……但无论我做什么,它都拒绝打开超过 1024 个文件,并且复制问题不会消失!
这是我尝试过的:
我给自己定ulimit -n 25000。
我还将 /etc/security/limits.conf 设置为:
* soft nofiles 25000
* hard nofiles 65000
root soft nofiles 25000
root hard nofiles 65000
Run Code Online (Sandbox Code Playgroud)
我确保 /etc/security/limits.d 中没有任何内容会覆盖其中的任何内容。
我已经检查过 sysctl fs.file-max = 199468 这已经足够了。
我找不到任何可能干扰 samba 的 apparmor 配置文件。
我limit nofile 25000 65000在 /etc/init/smbd.conf 中添加了一个节
我在 smb.conf 中设置了 max open files = 50000 并确认它通过 samba 日志文件生效:
[2011/10/28 01:30:16, 0] smbd/open.c:151(fd_open)
Too many open files, …Run Code Online (Sandbox Code Playgroud) 我的系统
* - stack 131072ulimit -s返回:131072max_stack_depth = 126MB
我的问题
在引导期间,会出现以下消息:
* The PostgreSQL server failed to start. Please check the log output:
2018-01-24 09:27:53 MST LOG: invalid value for parameter "max_stack_depth": 129024
2018-01-24 09:27:53 MST DETAIL: "max_stack_depth" must not exceed 7680kB.
2018-01-24 09:27:53 MST HINT: Increase the platform's stack depth limit via "ulimit …Run Code Online (Sandbox Code Playgroud) 我有一个 ubuntu 系统,我有一个定期运行的脚本。我需要限制此脚本可以使用的最大内存量。AFAIKulimit是执行此操作的命令,但是我无法使其正常工作。
例如,我有以下脚本:
#! /bin/bash
ulimit -m 1024
X="x"
seq 100 | while read LINE ; do
X="$X$X"
done
Run Code Online (Sandbox Code Playgroud)
这应该使$X规模增长,而这个例子正是我想要限制的那种事情。但是 ulimit 调用似乎不起作用。我可以正常运行脚本,它不会死,并向top我显示脚本获得了大量内存。我究竟做错了什么?如何强制此脚本从不使用超过一定数量的内存?
Ulimit 手册页建议 -r 选项将设置它,但它似乎只对 root 用户有效,并且没有等效的通过 /etc/security/limits 设置它?
有任何想法吗?
我在 Ubuntu 10.04 64 位上运行 Squid 2.7。我遇到了 Squid 耗尽文件描述符的问题,/var/log/squid/cache.log 中显示以下错误:
警告!您的缓存已用完文件描述符
我检查过:
鱿鱼客户端经理:信息 | grep '文件描述'
它显示我只有 1024 个可用的文件描述符。
我更改了 /etc/security/limits.conf,在末尾添加了以下内容:
* soft nofile 32768
* hard nofile 32768
proxy soft nofile 32768
proxy hard nofile 32768
Run Code Online (Sandbox Code Playgroud)
将其添加到 /etc/squid/squid.conf 中:
max_filedescriptors 32768
Run Code Online (Sandbox Code Playgroud)
还更改了/etc/default/squid:
SQUID_MAXFD=32768
Run Code Online (Sandbox Code Playgroud)
什么都没有解决。最后我编辑/etc/init.d/squid添加“ulimit -n 32768”:
#!/bin/sh -e
# upstart-job
#
# Symlink target for initscripts that have been converted to Upstart.
set -e
ulimit -n 32768
<... snipped ...>
Run Code Online (Sandbox Code Playgroud)
成功了!:)
我必须在实时生产 Squid 服务器极其缓慢的压力下完成这一切,所以我确信这不是正确的方法。
但正确的做法是什么?
我可以通过ulimit -n 20000文件描述符限制手动设置,它工作正常。要在机器重新启动后对每个用户也有这个限制,我可以添加
* soft nofile 20000
Run Code Online (Sandbox Code Playgroud)
到/etc/security/limits.conf?
我无法尝试,因为我无法真正重新启动服务器。
我想了解这里发生了什么。
linvx$ ( ulimit -u 123; /bin/echo nst )
nst
linvx$ ( ulimit -u 122; /bin/echo nst )
-bash: fork: Resource temporarily unavailable
Terminated
linvx$ ( ulimit -u 123; /bin/echo one; /bin/echo two; /bin/echo three )
one
two
three
linvx$ ( ulimit -u 123; /bin/echo one & /bin/echo two & /bin/echo three )
-bash: fork: Resource temporarily unavailable
Terminated
one
Run Code Online (Sandbox Code Playgroud)
我推测前 122 个进程是由 Bash 本身使用的,其余的ulimit进程控制着我允许拥有的并发进程数。文档对此不是很清楚。我错过了什么吗?
更重要的是,对于现实世界的部署,我怎么知道什么样的ulimit才是现实的?它是一个长时间运行的守护进程,它根据需要产生工作线程,并在负载减少时收获它们。我已经让它使服务器旋转数次。最重要的限制可能是内存,我现在每个进程的内存限制为 200M,但我想弄清楚如何对子进程的数量实施限制(该程序确实允许我配置最大值,但是如何我知道那部分代码没有错误吗?)
附录:在较新的系统上,我得到了更高的数字和略有不同的行为。
xubuntu12.04$ ( ulimit -u 206; /bin/echo nst ) …Run Code Online (Sandbox Code Playgroud) 在共享服务器 (Debian Jessie) 上,有一些内存限制(和其他限制,例如进程数)适用于在/etc/security/limits.conf.
然而,这些限制似乎不适用于由 cron 启动的进程,有时人们的 cron 工作会意外地破坏所有其他人的性能。
有什么方法可以将限制应用limits.conf到 cron 作业吗?或者,如果这不可能,至少对所有用户的 cron 作业实施一些限制?
Cron 似乎在 cron cgroup 中运行所有作业,而不是在用户的 cgroup 中,因此这也不是一种简单的方法:(
在 JAVA 应用程序上的 Ubuntu 14.04 服务器中,我们收到了 Postgres(使用 Postgresql 9.5)的 Too many Open files 错误。
我们在 /etc/security/limits.conf 中设置以下内容
* soft nofile 16384
* hard nofile 16384
root soft nofile 16384
root hard nofile 16384
postgres soft nofile 16384
postgres hard nofile 16384
Run Code Online (Sandbox Code Playgroud)
还要在 /etc/sysctl.conf 中设置以下内容
kern.maxfiles=20480
kern.maxfilesperproc=18000
Run Code Online (Sandbox Code Playgroud)
另请在以 Postgres 用户身份运行时查看以下结果:
-> ulimit -Hn
16384
-> ulimit -Sn
16384
-> cat /proc/sys/fs/file-max
100268
Run Code Online (Sandbox Code Playgroud)
重新启动服务器并检查 Postgres 的 ulimit 后为 100268。但是在检查 postgres 下打开文件的限制时,它仍然是 1024 和 4096
# cat /proc/1072/limits
Max open files 1024 4096 …Run Code Online (Sandbox Code Playgroud) ulimit ×10
ubuntu ×4
linux ×3
postgresql ×2
unix ×2
ansible ×1
bash ×1
cron ×1
debian ×1
filesystems ×1
limits ×1
memory ×1
samba ×1
squid ×1
ubuntu-10.04 ×1
ubuntu-14.04 ×1
ubuntu-9.04 ×1