系统版本

# cat /etc/issue
Ubuntu 18.04.5 LTS \n \l
# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.5 LTS
Release:	18.04
Codename:	bionic

查看 ulimit

# cat /proc/sys/fs/file-max
52782466
# ulimit -Hn
1048576
# ulimit -Sn
1024

临时修改

ulimit -n 1024000

永久修改

系统修改

# echo 'fs.file-max = 1024000' | tee -a /etc/sysctl.conf
fs.file-max = 1024000
# cat /etc/sysctl.conf | grep fs.file-max
fs.file-max = 1024000
# sysctl -p
fs.file-max = 1024000

用户修改

tee -a /etc/security/limits.conf << EOF
*               hard    nofile          1024000
*               soft    nofile          1024000
root            hard    nofile          1024000
root            soft    nofile          1024000
EOF
# cat /etc/security/limits.conf

*               hard    nofile          1024000
*               soft    nofile          1024000
root            hard    nofile          1024000
root            soft    nofile          1024000

systemd 修改

# grep -irl DefaultLimitNOFILE /etc/systemd/
/etc/systemd/system.conf
/etc/systemd/user.conf
sed -i '/DefaultLimitNOFILE/c DefaultLimitNOFILE=1048576' /etc/systemd/*.conf
systemctl daemon-reexec

重启

reboot
# ulimit -n
1024000
# ulimit -Hn
1024000
# ulimit -Sn
1024000

参考

  1. Ubuntu 永久修改 ulimit -n

更多推荐