一、问题描述
修改 /etc/security/limits.conf ,重启之后不生效
内容如下:
* soft nofile
* hard nofile
root soft nofile
root hard nofile
* soft nproc
* hard nproc
root soft nproc
root hard nproc
二、解决问题
根据网上资料的说法有几种
1. 修改 /etc/ssh/sshd_config
开启这2项
UsePAM yes
UseLogin yes
2. 以下几个文件
/etc/pam.d/login
/etc/pam.d/su
/etc/pam.d/sshd
确保开启了pam_limits.so
session required pam_limits.so
3. 重启系统
注意:修改了/etc/security/limits.conf ,必须要重启,才能生效。
以上几个,都测试了一下,open files没有生效!max user processes倒是生效了
root@ubuntu:~# ulimit -a
core file size (blocks, -c)
data seg size (kbytes, -d) unlimited
scheduling priority (-e)
file size (blocks, -f) unlimited
pending signals (-i)
max locked memory (kbytes, -l)
max memory size (kbytes, -m) unlimited
open files (-n)
pipe size ( bytes, -p)
POSIX message queues (bytes, -q)
real-time priority (-r)
stack size (kbytes, -s)
cpu time (seconds, -t) unlimited
max user processes (-u)
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
最后终于找到原因了,是因为 内核参数没有配置
# 编辑配置文件
vi /etc/sysctl.conf fs.nr_open = # 重新加载
sysctl -p
再次重启,效果如下:
root@ubuntu:~# ulimit -a
core file size (blocks, -c)
data seg size (kbytes, -d) unlimited
scheduling priority (-e)
file size (blocks, -f) unlimited
pending signals (-i)
max locked memory (kbytes, -l)
max memory size (kbytes, -m) unlimited
open files (-n) 2048576
pipe size ( bytes, -p)
POSIX message queues (bytes, -q)
real-time priority (-r)
stack size (kbytes, -s)
cpu time (seconds, -t) unlimited
max user processes (-u)
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
本文参考链接: