/etc/security/limits.conf

本文深入探讨了Linux内核中资源限制的概念,包括核心文件大小、数据大小、最大文件打开数、RSS内存使用、堆栈大小、CPU时间、进程数量、地址空间限制等关键参数。了解这些限制对于优化系统性能至关重要。

* soft core unlimited 

* hard core unlimited 

* soft data unlimited

* hard data unlimited

* soft fsize unlimited

* hard fsize unlimited

* soft memlock -1 

* hard memlock -1 

* soft nofile 20000

* hard nofile 20000

* soft rss unlimited

* hard rss unlimited

* soft stack unlimited

* hard stack unlimited

* soft cpu unlimited

* hard cpu unlimited

* soft nproc unlimited

* hard nproc unlimited

* soft as unlimited

* hard as unlimited

* soft maxlogins unlimited

* hard maxlogins unlimited

* soft maxsyslogins unlimited

* hard maxsyslogins unlimited

* soft priority 0

* hard priority 0

* soft locks unlimited

* hard locks unlimited

* soft sigpending unlimited

* hard sigpending unlimited

* soft msgqueue unlimited

* hard msgqueue unlimited

* soft nice 0

* hard nice 0

* soft rtprio unlimited

* hard rtprio unlimited

 

 

core

limits the core file size (KB)

 

data

maximum data size (KB)

 

fsize

maximum filesize (KB)

 

memlock

maximum locked-in-memory address space (KB)

 

nofile

maximum number of open files

 

rss

maximum resident set size (KB) (Ignored in Linux 2.4.30 and higher)

 

stack

maximum stack size (KB)

 

cpu

maximum CPU time (minutes)

 

nproc

maximum number of processes

 

as

address space limit (KB)

 

maxlogins

maximum number of logins for this user except for this with uid=0

 

maxsyslogins

maximum number of logins on system

 

priority

the priority to run user process with (negative values boost process priority)

 

locks

maximum locked files (Linux 2.4 and higher)

 

sigpending

maximum number of pending signals (Linux 2.6 and higher)

 

msqqueue

maximum memory used by POSIX message queues (bytes) (Linux

2.6 and higher)

 

nice

maximum nice priority allowed to raise to (Linux 2.6.12 and higher) values: [-20,19]

 

rtprio

maximum realtime priority allowed for non-privileged processes (Linux 2.6.12 and higher)

 

chroot

the directory to chroot the user to

 

为了配置 ELK(Elasticsearch, Logstash, Kibana)相关服务在 Linux 系统上的文件描述符限制,需要修改 `/etc/security/limits.conf` 文件。以下是具体步骤和配置建议: 1. **增加文件描述符限制** 需要为运行 ELK 服务的用户(通常是 `elasticsearch` 用户或其他指定用户)设置软限制(soft limit)和硬限制(hard limit)。推荐配置如下: ``` elasticsearch soft nofile 65536 elasticsearch hard nofile 131072 ``` 上述配置表示将 `elasticsearch` 用户的软限制设置为 65536,硬限制设置为 131072。 2. **优化内存锁定权限** Elasticsearch 推荐不限制内存锁定,以提高性能并避免交换内存的影响。可以添加以下配置: ``` elasticsearch soft memlock unlimited elasticsearch hard memlock unlimited ``` 3. **进程数限制** Elasticsearch 可能会启动多个线程来处理请求,因此需要适当增加进程数限制: ``` elasticsearch soft nproc 2048 elasticsearch hard nproc 4096 ``` 4. **临时生效的方法** 如果希望立即生效而不重启系统,可以通过 `ulimit` 命令手动调整当前会话的文件描述符限制: ```bash ulimit -n 65536 ``` 5. **确保 PAM 配置支持** 在某些情况下,如果发现修改 `/etc/security/limits.conf` 后仍然无法生效,可能是因为 PAM(Pluggable Authentication Modules)配置不完整。请检查 `/etc/pam.d/login`, `/etc/pam.d/system-auth`, 和 `/etc/pam.d/sshd` 文件中是否包含以下行: ``` session required pam_limits.so ``` 这将确保 PAM 会读取并应用 `limits.conf` 中的配置[^3]。 6. **内核参数优化** 对于 Elasticsearch,还需要调整内核参数以支持更大的内存映射区域数。编辑 `/etc/sysctl.conf` 文件,并添加以下内容: ``` vm.max_map_count=262144 ``` 应用更改后,使用以下命令使配置生效: ```bash sysctl -p ``` ### 示例配置 ```conf # /etc/security/limits.conf elasticsearch soft nofile 65536 elasticsearch hard nofile 131072 elasticsearch soft memlock unlimited elasticsearch hard memlock unlimited elasticsearch soft nproc 2048 elasticsearch hard nproc 4096 ``` ### 注意事项 - 修改完配置文件后,必须重新启动系统或重新登录以使新的限制生效。 - 如果 ELK 相关服务由其他用户运行,则需替换 `elasticsearch` 为实际使用的用户名。 - 确保所有节点(尤其是集群部署时)都进行了相同的配置,以保持一致性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值