ulimit /etc/security/limits.conf

本文深入解析Linux系统中limits.conf文件的作用与用法,详细介绍了limits.conf中的各种参数及其含义,包括核心文件大小限制、数据大小限制、最大文件大小等,并通过具体实例展示了如何配置用户或组的资源限制。
/etc/security/limits.conf 2011-11-19 15:51:18
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。 http://liuleideshitou.blog.51cto.com/2062845/719179

[root@localhost ~]# cat /etc/security/limits.conf
# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain>        <type>  <item>  <value>
#
#Where:
#<domain> can be:
#        - an user name
#        - a group name, with @group syntax
#        - the wildcard *, for default entry
#        - the wildcard %, can be also used with %group syntax,
#                 for maxlogin limit
#
#<type> can have the two values:
#        - "soft" for enforcing the soft limits
#        - "hard" for enforcing hard limits
#
#<item> can be one of the following:
#        - core - limits the core file size (KB)  ---限制内核文件的大小
#        - data - max data size (KB)  ---------------最大数据大小
#        - fsize - maximum filesize (KB)-------------最大文件大小
#        - memlock - max locked-in-memory address space (KB)--最大锁定内存地址空间
#        - nofile - max number of open files-----------打开文件的最大数目
#        - rss - max resident set size (KB)------------最大持久设置大小
#        - stack - max stack size (KB)-----------------最大栈大小
#        - cpu - max CPU time (MIN)--------------------最多CPU时间
#        - nproc - max number of processes-------------进程的最大数目
#        - as - address space limit---------------------地址空间限制
#        - maxlogins - max number of logins for this user----此用户允许登录的最大数目
#        - maxsyslogins - max number of logins on the system--系统允许登录的最多用户数
#        - priority - the priority to run user process with--用户进程的优先级运行
#        - locks - max number of file locks the user can hold--用户可以持有的文件锁最大数量
#        - sigpending - max number of pending signals---未处理信号的最大数量
#        - msgqueue - max memory used by POSIX message queues (bytes)--内存使用最大POSIX消息队列
#        - nice - max nice priority allowed to raise to--允许的最大优先级
#        - rtprio - max realtime priority----最大实时优先
#
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4
jacky           hard    maxlogins       3
# End of file

本文出自 “相信未来” 博客,请务必保留此出处http://liuleideshitou.blog.51cto.com/2062845/719179

为了配置 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` 为实际使用的用户名。 - 确保所有节点(尤其是集群部署时)都进行了相同的配置,以保持一致性。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值