Ubuntu 18.04 修改 ulimit

1,报错too many open files

  • 设置ulimit
  • open files默认为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) 514927
max locked memory       (kbytes, -l) 16384
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) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 514927
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

2,修改open files

  • vim /etc/security/limits.conf添加
* soft     nproc          65535
* hard     nproc          65535
* soft     nofile         65535
* hard     nofile         65535

root soft     nproc          65535
root hard     nproc          65535
root soft     nofile         65535
root hard     nofile         65535

bro soft     nproc          65535
bro hard     nproc          65535
bro soft     nofile         65535
bro hard     nofile         65535
  • vim /etc/pam.d/common-session添加
session required pam_limits.so
  • vim /etc/pam.d/common-session-noninteractive添加
session required pam_limits.so
  • vim /etc/systemd/system.conf修改
DefaultLimitNOFILE=65535
  • 重启
  • 修改成功open files 65535
# 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) 514927
max locked memory       (kbytes, -l) 16384
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 65535
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

3,通过设置环境变量修改

  • vim /etc/profile 增加
ulimit -n 65535
# ulimit -n
65535

参考:

  1. Ubuntu 设置 ulimit
  2. How to increase max open files limit on Ubuntu 18.04?
  3. 修改linux 最大文件限制数 ulimit

猜你喜欢

转载自blog.csdn.net/u010953692/article/details/106485112
今日推荐