萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Linux 如何調大可開啟檔案描述符上限?ulimit 與 limits.conf 完整設定

現象

安裝 Oracle Grid Infrastructure 檢查失敗:目前上限 1024,需求 65536。

暫時調整 (當前 Shell)

ulimit -n 65536

需 root 權限;普通用戶無法超過 hard limit。

永久生效:修改 /etc/security/limits.conf

# 針對 oracle 與 grid 用戶
oracle soft nofile 65536
oracle hard nofile 65536
grid   soft nofile 65536
grid   hard nofile 65536

# 同步調整進程數
oracle soft nproc 16384
oracle hard nproc 16384
grid   soft nproc 16384
grid   hard nproc 16384

必要配合:/etc/pam.d/login

確認包含:
session required pam_limits.so

系統層面:/etc/sysctl.conf

fs.file-max = 6815744

套用:sysctl -p

驗證

重新登入目標用戶,執行 ulimit -a 確認 open files 顯示 65536。

關鍵點

  • 修改 limits.conf 後必須「重新登入」生效,當前 Shell 不受影響。
  • root 可直接 ulimit -n 修改自身上限,但不影響其他用戶。
  • /etc/profile 中的 ulimit 設定僅對登入 Shell 生效,優先級低於 limits.conf。
copyright © 萬盛學電腦網 all rights reserved