Ubuntu /etc/security/limits.conf 不生效問題


一、問題描述

修改 /etc/security/limits.conf ,重啟之后不生效

內容如下:

* soft nofile 2048576
* hard nofile 2048576
root soft nofile 2048576
root hard nofile 2048576
* soft nproc 80480
* hard nproc 80960
root soft nproc 80480
root hard nproc 80960

 

二、解決問題

根據網上資料的說法有幾種

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) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 7832 max locked memory (kbytes, -l) 64 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) 80480 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited

 

最后終於找到原因了,是因為 內核參數沒有配置

# 編輯配置文件
vi /etc/sysctl.conf
 
fs.nr_open = 10000000
 
# 重新加載
sysctl -p

 

再次重啟,效果如下:

root@ubuntu:~# 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) 31392 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 2048576 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) 80480 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited

 

本文參考鏈接:

https://blog.51cto.com/jonyisme/1919075

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM