在CentOS系统中,ulimit
命令用于设置用户进程的资源限制。以下是一些关于CentOS ulimit
的最佳实践:
ulimit -a
命令查看所有资源限制。/etc/security/limits.conf
文件来永久更改FD限制。* soft nofile 65536
* hard nofile 65536
/etc/security/limits.d/
目录下创建单独的配置文件。* soft memlock unlimited
* hard memlock unlimited
* soft nproc 4096
* hard nproc 4096
* soft nproc 4096
* hard nproc 4096
* soft stack 8388608
* hard stack 8388608
* soft nofile 65536
* hard nofile 65536
auditd
或其他监控工具记录资源使用异常。以下是一个示例/etc/security/limits.conf
文件的部分内容:
# /etc/security/limits.conf
#
# Example of the limit configuration file.
#
# The '*' wildcard can be used to specify all users.
# The ':' separator within fields signifies 'OR'.
# The default user class is 'user'. Other classes such as 'root' are also
# possible (e.g., 'root hard nofile 4096').
# User-specific limits
* soft nofile 65536
* hard nofile 65536
* soft nproc 4096
* hard nproc 4096
* soft memlock unlimited
* hard memlock unlimited
# Specific user limits
@developers soft nofile 65536
@developers hard nofile 65536
@developers soft nproc 8192
@developers hard nproc 8192
# System-wide limits
root soft nofile 65536
root hard nofile 65536
root soft nproc unlimited
root hard nproc unlimited
通过遵循这些最佳实践,您可以确保CentOS系统中的资源限制设置既安全又高效。