linux - 无法使用 sysctl 更改每个进程的最大打开文件数

标签 linux centos6 ubuntu-16.04

我的实际限制是 1024:

$ ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 95979
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 1024
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

我试过:

sysctl -w fs.file-max=100000

并附加到 /etc/sysctl.conf:

fs.file-max = 100000

即使在 Ubuntu 16.04 和 CentOS 6 上运行 sysctl -p 重新加载设置和/或重新启动后也没有成功。

它始终保持设置为 1024


这个问题是 other question 的延伸.

最佳答案

适用于 Ubuntu 17.04。参见 this solution .

Ubuntu 17.04 之前:

我不知道为什么上述设置不起作用,但使用 /etc/security/limits.conf file 似乎可以得到相同的结果。 .

/etc/security/limits.conf中设置限制

sudo bash -c "echo '* - nofile 10240' >> /etc/security/limits.conf"
  • * 表示所有用户。您可以将其替换为特定的用户名。
  • - 表示 type of limit to be enforcedsofthard . Hard 只能由 super 用户修改。 Soft 可以由非 root 用户修改,并且不能优于 hard。
  • nofile最大打开文件数参数。
  • 10240 是新的限制。

重新加载

注销并重新登录。sudo sysctl -p 似乎不足以重新加载。

您可以通过以下方式检查新限制:

ulimit -n

在 Ubuntu 16.04 和 CentOS 6 上测试。受此启发 answer .

关于linux - 无法使用 sysctl 更改每个进程的最大打开文件数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40617651/

相关文章:

linux - lua:bad argument #2 to '?' (起始索引越界)

java - 如何在linux中用包编译java文件

angularjs - yo angular-fullstack 在本地 linux 上安装失败

c++ - 程序删除其他用户的文件 - 权限被拒绝

php - sh : ffmpeg: command not found when run command through php

linux - linux下创建负载均衡器和radius认证

linux - 需要有关使用 sed 格式化行的帮助

vagrant - Vagrant 中共享文件夹的 Git 问题

c - "PGC-I-0222-Redundant definition for symbol"是什么

nginx - 如何使用 nginx 安装 postgresql 和 phppgadmin?