在CentOS系統中,ulimit
命令用于設置或獲取用戶進程的資源限制。以下是配置ulimit
的方法:
查看當前限制:
ulimit -a
設置單個資源限制:
ulimit -f <size_in_kb>
ulimit -u <number_of_processes>
ulimit -n <number_of_open_files>
ulimit -t <seconds>
ulimit -m <memory_in_kb>
設置所有資源限制:
ulimit -a <soft_limit> <hard_limit>
例如:
ulimit -a 4096 8192
要使ulimit
設置在系統重啟后仍然有效,需要修改系統配置文件。
編輯 /etc/security/limits.conf
文件:
打開文件并添加以下行來設置用戶或組的資源限制:
<username> soft <resource> <limit>
<username> hard <resource> <limit>
例如,為user1
設置最大打開文件數為65535:
user1 soft nofile 65535
user1 hard nofile 65535
編輯 /etc/pam.d/common-session
和 /etc/pam.d/common-session-noninteractive
文件:
添加以下行以確保PAM模塊加載資源限制配置:
session required pam_limits.so
編輯 /etc/systemd/system.conf
和 /etc/systemd/user.conf
文件(適用于systemd):
添加以下行來設置系統范圍和用戶范圍的資源限制:
DefaultLimitNOFILE=65535
或者針對特定用戶:
[User@<username>]
LimitNOFILE=65535
重新加載systemd配置:
systemctl daemon-reload
重啟系統:
reboot
ulimit
設置時,請確保不會超過系統或硬件的限制。通過以上步驟,您可以在CentOS系統中配置ulimit
以滿足您的需求。