系统文件数限制

  1. 配置ulimit -a

注:nofile最大值1048576,且不能设置为unlimited,否则无法ssh登陆,noproc可以

vim /etc/security/limits.conf  
* soft nofile 655360
* hard nofile 655360
* soft nproc  655360
* hard nproc  655360

vim /etc/security/limits.d/20-nproc.conf
* soft nofile 655360
* hard nofile 655360
* soft nproc 655360
* hard nproc 655360

echo "vm.max_map_count=655360" >> /etc/sysctl.conf && sysctl -p

  1. Systemd下的最大打开文件数设置(针对centos7及以上)

在Systemd替代了之前的SysV后,/etc/security/limits.conf 文件的配置作用域缩小了一些。limits.conf这里的配置,只适用于通过PAM认证登录用户的资源限制,它对systemd的service的资源限制不生效。对于systemd service的资源限制的配置如下:

修改/etc/systemd/system.conf和/etc/systemd/user.conf

DefaultLimitCORE=infinity
DefaultLimitNOFILE=655360
DefaultLimitNPROC=655360

查看一个进程的limit设置

cat /proc/[PID]/limits

针对单个Service,也可以设置,以nginx为例。编辑 /usr/lib/systemd/system/nginx.service 文件,或者 /usr/lib/systemd/system/nginx.service.d/my-limit.conf 文件,做如下配置

[Service]
 LimitCORE=infinity
 LimitNOFILE=655360
 LimitNPROC=655360

然后运行如下命令,才能生效。

sudo systemctl daemon-reload
sudo systemctl restart nginx.service


系统文件数限制
https://www.hechunyu.com/archives/1698117491965
作者
chunyu
发布于
2019年07月15日
许可协议