设置文件最大打开数
#系统
vim /etc/sysctl.conf
#添加
fs.file-max = 655350
sysctl -p
#用户
vim /etc/security/limits.conf
#添加
* hard nofile 655350
* soft nofile 655350
root soft nproc 655350
root hard nproc 655350
root soft nofile 655350
root hard nofile 655350
注意L这个每个用户都要配置,有些说只有root用户才需要写出来,但是有时候测试的时候发现普通用户没有写在这没有生效
test soft nproc 655350
test hard nproc 655350
test soft nofile 655350
test hard nofile 655350
#Systemd
sed -i '/DefaultLimitNOFILE/c DefaultLimitNOFILE=655350' /etc/systemd/*.conf
systemctl daemon-reexec
搞定,重启即可。。。重启后可以查看ulimit -n是否显示为655350
验证
#打开新的终端
#ssh remote_user@host
#查看系统限制
cat /proc/sys/fs/file-max
#查看用户硬限制
ulimit -Hn
#查看用户软限制
ulimit -Sn
#查看某进程的限制
cat /proc/PID/limits # 将 PID 替换为具体的进程 ID
#查看其他用户限制
su - www -c 'ulimit -aHS' -s '/bin/bash'
