Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> 關於 Linux

Linux 修改 ulimit 與 limits.conf 突破預設 1024 檔案描述符限制

編輯:關於 Linux

高併發測試 (如 Tsung) 常因系統預設 ulimit -n 1024 導致 TCP 連線數受限。本文從臨時修改失效分析到永久生效的完整配置流程。

問題背景

Tsung 壓測僅能建立 1013 連線 (1024 - 系統佔用 11)。

解決方案演進

  1. 臨時修改失效:ulimit -n 65535 當前 Shell 生效,重新登入失效,且 Tsung 子進程未繼承。
  2. 永久修改 /etc/security/limits.conf:
    * soft nofile 65535
    * hard nofile 65535
    重新登入生效,驗證 ulimit -n 為 65535,Tsung 可突破限制。

補充:核心層面與 PAM 配置

  • 檢查核心上限:cat /proc/sys/fs/file-max,不足時修改 /etc/sysctl.conf:fs.file-max = 2048 (或更大)。
  • limits.conf 中 soft (當前生效上限) 與 hard (可調整上限) 需同時設定,用 - 同時生效:* - nofile 2048。
  • 確保 PAM 載入 limits 模組:/etc/pam.d/login 與 /etc/pam.d/xdm 含 session required /lib/security/pam_limits.so。
  • Shell 配置文件動態加載:.bashrc 加入 ulimit -HSn 2048。

完整配置後,普通用戶會話即可擁有足夠檔案描述符額度。

Copyright © Windows教程網 All Rights Reserved