本文主要是介绍Ubuntu 18.04 修改 ulimit,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Ubuntu 18.04 修改 ulimit
- 1,报错`too many open files`
- 2,修改`open files `
- 3,通过设置环境变量修改
- 4,~~pen files修改为1048576~~
- 5,永久修改 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 65535root soft nproc 65535
root hard nproc 65535
root soft nofile 65535
root hard nofile 65535bro 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
8565
为进程,查看Max open files
# cat /proc/8565/limits
Limit Soft Limit Hard Limit Units
Max cpu time unlimited unlimited seconds
Max file size unlimited unlimited bytes
Max data size unlimited unlimited bytes
Max stack size 8388608 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 65535 65535 processes
Max open files 65535 65535 files
Max locked memory 16777216 16777216 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 514927 514927 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
3,通过设置环境变量修改
vim /etc/profile
增加
ulimit -n 65535
# ulimit -n
65535
4,pen files修改为1048576
# cat /proc/sys/fs/file-max
19768128
# cat /proc/sys/fs/nr_open
1048576
- 当前值 hard 值
ulimit -a
# ulimit -Sa | grep -ni "open"
8:open files (-n) 1024
# ulimit -Ha | grep -ni "open"
8:open files (-n) 1048576
5,永久修改 ulimit
# ulimit -a | grep -ni "open"
8:open files (-n) 1024
# ulimit -Sa | grep -ni "open"
8:open files (-n) 1024
# ulimit -Ha | grep -ni "open"
8:open files (-n) 1048576
- 修改
# vim /etc/systemd/user.conf
#DefaultLimitNOFILE=
DefaultLimitNOFILE=1048576# vim /etc/systemd/system.conf
#DefaultLimitNOFILE=
DefaultLimitNOFILE=1048576
vim /etc/security/limits.conf
- 添加
* soft nproc 1048576
* hard nproc 1048576
* soft nofile 1048576
* hard nofile 1048576root soft nproc 1048576
root hard nproc 1048576
root soft nofile 1048576
root hard nofile 1048576bro soft nproc 1048576
bro hard nproc 1048576
bro soft nofile 1048576
bro hard nofile 1048576
reboot
# ulimit -a | grep -ni "open"
8:open files (-n) 1048576
# ulimit -Sa | grep -ni "open"
8:open files (-n) 1048576
参考:
- Ubuntu 设置 ulimit
- How to increase max open files limit on Ubuntu 18.04?
- 修改linux 最大文件限制数 ulimit
- linux 系统下open-file文件数限制修改
- ulimit 资源限制无效
- linux - Openfire进程未遵循limits.conf中的ulimit nofiles值
- Filecoin 资源分享 Ulimit 问题
- 修改 ulimit
这篇关于Ubuntu 18.04 修改 ulimit的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!