wiki
  • Introduction
  • Ansible
    • 1 初识Ansible
    • 2 Ansible Inventory 配置详解
    • 3 Ansible Ad-hoc 命令集
    • 3 Ansible lineinfile 模块详解
    • 4 Ansible Playbook
      • 4.1 Playbook的结构及handler用法
      • 4.2 Playbook循环语句
      • 4.3 Playbook条件语句
      • 4.4 Playbook高级用法
      • 4.5 Playbook之tags
      • 4.6 巧用Roles
      • 4.7 文件管理模块及Jinja2过滤器
      • 4.8 yaml 语法
    • 5 Ansible变量
      • 5.1 自定义变量
      • 5.2 Fact变量
      • 5.3 魔法变量
      • 5.4 使用lookup生成变量
      • 5.5 使用vault配置加密
    • 6 Ansible使用优化
  • Linux
    • linux简介
    • 文件管理
      • 查看文件类型
      • 查看文件详细属性
      • 创建、复制、移动、删除
      • 查看文件内容
      • 打包、压缩
    • 文件权限
      • 基本权限UGO
    • 计划任务
    • 用户管理
    • 进程管理
    • 管道及I/O重定向
    • 软件包管理
    • 网络管理
    • 日志logrotate
    • /etc/security/limits.conf 详解与配置
    • 常用知识
  • Shell
    • 第一部分 初见shell
      • 1. 为什么使用shell编程
      • 2. 和Sha-Bang(#!)一起出发
        • 2.1 调用一个脚本
        • 2.2 牛刀小试
    • 第二部分 shell基础
      • 3. 特殊字符
      • 4. 变量与参数
        • 4.1 变量替换
        • 4.2 变量赋值
        • 4.3 Bash弱类型变量
        • 4.4 特殊变量类型
      • 5. 引用
        • 5.1 引用变量
        • 5.2 转义
      • 6. 退出与退出状态
      • 7. 测试
        • 7.1 测试结构
        • 7.2 文件测试操作
        • 7.3 其他比较操作
        • 7.4 嵌套 if/then 条件测试
        • 7.5 牛刀小试
      • 8. 运算符相关话题
        • 8.1 运算符
        • 8.2 数字常量
        • 8.3 双圆括号结构
        • 8.4 运算符优先级
    • 第三部分 shell进阶
      • 9. 换个角度看变量
        • 9.1 内部变量
        • 9.2 变量类型标注:declare 与 typeset
          • 9.2.1 declare 的另类用法
        • 9.3 $RANDOM:生成随机数
      • 10. 变量处理
        • 10.1 字符串处理
          • 10.1.1 使用 awk 处理字符串
          • 10.1.2 参考资料
        • 10.2 参数替换
      • 11. 循环与分支
        • 11.1 循环
        • 11.2 嵌套循环
        • 11.3 循环控制
        • 11.4 测试与分支
      • 12. 命令替换
      • 13. 算术扩展
    • 第四部分 命令
    • 第五部分 高级话题
      • 18.正则表达式
        • 18.1正则表达式简介
        • 18.2文件名替换
        • 18.3 正则表达式对照表
      • 19. 嵌入文档
      • 20. I/O 重定向
        • 20.1 使用 exec
        • 20.2 重定向代码块
        • 20.3 应用程序
      • 21. 子shell
      • 22. 限制模式的Shell
      • 23. 进程替换
      • 24. 函数
        • 24.1 复杂函数和函数复杂性
        • 24.2 局部变量
        • 24.3 不适用局部变量的递归
      • 25. 别名
      • 26. 列表结构
      • 27. 数组
      • 30. 网络编程
      • 33. 选项
      • 34. 陷阱
      • 36. 其他
        • 36.5 有颜色的脚本
        • 36.11 ssh远程操作
    • 第六部分 Google Shell 风格指南
    • 第七部分 实例
  • 3 Python
    • 3.1 简介
    • 3.2 数据类型
    • python subprocess模块的使用
    • python解析nginx配置文件
    • python调用jenkinsAPI批量拷贝视图job
    • python调用zabbixAPI批量添加web监控
    • python监控activemq集群
  • 4 Golang
    • 4.1 程序结构
    • 4.2 数据类型
      • 4.2.1 基础数据类型
      • 4.2.2 复合数据类型
    • 4.3 函数
  • Docker
    • Docker文章推荐
    • Docker Harbor
    • Docker Harbor HA
    • 快速搭建rabbitmq高可用集群
  • Nginx
    • 1.初识Nginx
    • 2.nginx架构基础
    • 3.nginx配置文件详解
      • 3.1 nginx全局块和events块配置
      • 3.2 nginxHTTP块配置
      • 3.3 nginxSERVER块配置
      • 3.4 nginxLOCATION块配置
      • 3.5 nginx常用模块
    • 4.内核参数优化
    • 5.状态码
    • 6.nginx的常见问题
      • Nginx出现403 forbidden的三种原因
  • 8 Tomcat
    • 8.1 tomcat简介
    • 生产环境中的tomcat配置
    • tomcat假死现象
    • Tomcat 错误代号及状态码
    • tomcat注意事项
  • 9 Elasticsearch
    • 9.1 概述
      • 9.1.1 Elasticsearch 简介及其发展历史
      • 9.1.2 Elastic Stack 家族成员及其应用场景
    • 9.2 安装上手
      • 9.2.1 Elasticsearch的安装和简单配置
      • 9.2.2 Kibana的安装和界面快速浏览
      • 9.2.3 在Docker容器中运行Elasticsearch,Kibana和Cerebro
    • 9.3 Elasticsearch入门
      • 9.3.1 基本概念
      • 9.3.2 文档的基本操作CRUP与批量操作
      • 9.3.3 倒排索引入门
      • 9.3.4 通过分析器进行分词
      • 9.3.5 Search API概览
      • 9.3.6 URI Search详解
      • 9.3.7 Request Body和Query DSL简介
  • 10 Zabbix
    • 10.1 zabbix4.4新功能
    • 10.2 zabbix借助ansible安装
    • 10.3 zabbix添加报警媒介
    • 10.4 MySQL监控模块
    • 10.5 Redis监控模块
    • 10.6 常见问题
    • 10.7 用zabbix api批量添加web监控
    • 10.8 activemq监控
    • 10.9 zookeeper集群监控
    • 10.10 Todolist
  • 11 消息中间件
    • 11.1 activemq集群
    • 11.2 rabbitmq
  • 12 常见集群的搭建
    • 12.1 keepalived和heartbeat对比
    • 12.2 zookeeper集群
    • 12.3 fastdfs
    • 12.4 rocketmq集群的搭建
  • 13 常见服务的搭建
    • none
    • 13.2 jdk
    • 13.3 python3.6
    • 13.4 新建博客方法
    • 13.5 confluence
  • 14 Markdown
    • 14.1 让Markdown写作更简单Typora完全使用指南
  • 16 Mysql
    • 16.1 MySQL基本操作
    • 16.2 列表类型和数据完整性
    • 16.3 数据库设计与查询语句
    • 16.4 视图、事务、索引、函数
    • 16.5 MySQL存储引擎
    • 16.6 用户权限和访问控制
    • 16.7 备份恢复
    • 16.8 AB复制
    • 16.9 主主和keepalived
    • 16.10 读写分离和Amoeba
    • 16.11 MySQL逻辑架构
    • 16.12 MySQL锁等待
    • 16.13 MySQL常见问题
    • 16.14 MySQL bin-log日志清理
  • 17 Redis
    • 17.1 安装
    • 17.2 配置
    • 17.3 服务器端和客户端命令
    • 17.4 数据库操作
      • 17.4.1 string类型
      • 17.4.2 键命令
      • 17.4.3 hash类型
      • 17.4.4 list类型
      • 17.4.5 set类型
      • 17.4.6 zset类型
    • 17.5 centos7安装redis-5.0.0主从
    • 17.6 redis5.0.4集群搭建步骤
    • 17.7 centos7安装升级ruby
    • 17.8 redis-dump方式导入导出数据
    • redis面试题
  • 18 HTML
    • 18.1 html入门
  • 19 CSS
    • 19.1 列表、div、span
    • 19.2 整体感知、常见属性、选择器
    • 19.3 css性质、盒模型、标准文档流、浮动
    • 19.4 行高和字号、超链接美化、background
    • 19.5 相对定位、绝对定位、固定定位、z-index
  • 20 jenkins
    • 20.1 jenkins的安装配置
    • 20.2 Jenkins Job迁移
    • Jenkins常见问题
    • Jenkins关闭和重启的实现方式
    • 使用Jenkins Pipeline自动化构建发布
  • 21 vim
    • vim设置参数以方便YAML语句录入
    • vim常用命令
  • 22 网络
    • TCP协议三次握手四次挥手
    • ip地址
  • 23 未分类
    • DEV SIT UAT PET SIM PRD PROD常见环境英文缩写含义
    • 调优
    • 编程语言的分类
    • curl方式执行shell脚本时如何传参
    • 中文技术文档写作规范
    • PrometheusAlert
  • 24 常见问题
    • centos时区
    • curl https报错
    • du-df磁盘使用不一致
    • linux下增加交换分区
    • mysql最大连接数
  • 25 openldap
    • Centos7 搭建openldap
    • phpldapadmin操作指导
  • 26 gitlab
    • gitlab备份迁移升级&集成openldap
  • 27 监控体系
    • 聊头监控体系
    • grafana问题
  • git
    • git的基本使用
    • Commit message 和 Change log 编写指南
Powered by GitBook
On this page
  • 一、 /etc/security/limits.conf 详解
  • /etc/security/limits.conf 配置解析
  • /etc/security/limits.d/目录
  • 二、 ulimit 如何配置
  • 配置注意事项
  • 基础配置
  • 注意覆盖点的问题。
  • 三、ulimit 配置后生效
  • 临时配置
  • 永久配置
  • 配置不生效的问题
  • 四、ulimit 常用命令
  • 查看配置

Was this helpful?

  1. Linux

/etc/security/limits.conf 详解与配置

一、 /etc/security/limits.conf 详解

/etc/security/limits.conf 文件实际是 Linux PAM(插入式认证模块,Pluggable Authentication Modules)中 pam_limits.so 的配置文件,而且只针对于单个会话。 该设置不会影响系统服务的资源限制。还要注意 /etc/security/limits.d/ 的这个目录,

/etc/security/limits.conf 配置解析

# /etc/security/limits.conf
#
#This file sets the resource limits for the users logged in via PAM.
该文件为通过PAM登录的用户设置资源限制。
#It does not affect resource limits of the system services.
#它不影响系统服务的资源限制。
#Also note that configuration files in /etc/security/limits.d directory,
#which are read in alphabetical order, override the settings in this
#file in case the domain is the same or more specific.
请注意/etc/security/limits.d下按照字母顺序排列的配置文件会覆盖 /etc/security/limits.conf中的
domain相同的的配置
#That means for example that setting a limit for wildcard domain here
#can be overriden with a wildcard setting in a config file in the
#subdirectory, but a user specific setting here can be overriden only
#with a user specific setting in the subdirectory.
这意味着,例如使用通配符的domain会被子目录中相同的通配符配置所覆盖,但是某一用户的特定配置
只能被字母路中用户的配置所覆盖。其实就是某一用户A如果在/etc/security/limits.conf有配置,当
/etc/security/limits.d子目录下配置文件也有用户A的配置时,那么A中某些配置会被覆盖。最终取的值是 /etc/security/limits.d 下的配置文件的配置。

#
#Each line describes a limit for a user in the form:
#每一行描述一个用户配置
#<domain> <type> <item> <value>

#Where:
#<domain> can be:
# - a user name    一个用户名
# - a group name, with @group syntax    用户组格式为@GROUP_NAME
# - 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
有soft,hard和-,soft指的是当前系统生效的设置值,软限制也可以理解为警告值。
hard表名系统中所能设定的最大值。soft的限制不能比hard限制高,用-表名同时设置了soft和hard的值。
#<item> can be one of the following:    <item>可以使以下选项中的一个
# - 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 file descriptors 最大打开的文件数(以文件描叙符,file descripter计数) 
# - rss - max resident set size (KB) 最大持久设置大小
# - stack - max stack size (KB) 最大栈大小
# - cpu - max CPU time (MIN)    最多CPU占用时间,单位为MIN分钟
# - nproc - max number of processes 进程的最大数目
# - as - address space limit (KB) 地址空间限制 
# - 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)
# - nice - max nice priority allowed to raise to values: [-20, 19] max nice优先级允许提升到值
# - rtprio - max realtime pr iority
#
#<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
#@st

/etc/security/limits.d/目录

  • /etc/security/limits.d/目录

    该目录下默认有*-nproc.conf文件,该文件是用于限制用户的线程限制。我们也可以在该目录创建配置文件

    在/etc/security/limits.d/下,以 .conf 结尾。

    • centos 7

      在CentOS 7版本中为/etc/security/limits.d/20-nproc.conf,

      # Default limit for number of user's processes to prevent
      # accidental fork bombs.
      # See rhbz #432903 for reasoning.
      
      *          soft    nproc     4096 # 所有的用户默认可以打开最大的进程数为 4096
      root       soft    nproc     unlimited # root 用户默认可以打开最大的进程数 无限制的。
    • CentOS 6

      在CentOS 6版本中为/etc/security/limits.d/90-nproc.conf

二、 ulimit 如何配置

配置注意事项

注意不能设置 nofile不能设置 unlimited,noproc可以. 当我们设置了 nofile不能设置 unlimited 后,我们进行 ssh 登录,是登录不了的,并且报错下面的内容。

Dec  1 14:57:57 localhost sshd[1543]: pam_limits(sshd:session): Could not set limit for 'nofile': Operation not permitted

当我们设置的 nofile 的值可以设置的最大值为 1048576(2**20),设置的值大于该数,就会进行登录不了。也会显示上面的登录错误。(亲测)

基础配置

我们不将所有的配置配置在/etc/security/limits.conf 而是将配置放在 /etc/security/limits.d/ 下。 比如我们将 nofile的配置放在 /etc/security/limits.d/20-nofile.conf ,nproc 的配置放在 /etc/security/limits.d/20-nproc.conf.

一般我们需要配置的 /etc/security/limits.d/20-nofile.conf 为。

root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535

/etc/security/limits.d/20-nproc.conf 设置为

*    -     nproc   65535
root soft  nproc  unlimited
root hard  nproc  unlimited

注意覆盖点的问题。

示例一: 当 /etc/security/limits.conf 配置了:

root soft nofile 65538
root hard nofile 65538
* soft nofile 65539
* hard nofile 65539

这个root 用户的 默认取值是 65538 ,* 统配符虽然在 root 配置后面,但是 root 的配置只能被 root 进行覆盖。

我们看下这个配置,当这样配置的时候

root soft nofile 65538
root hard nofile 65538
* soft nofile 65539
* hard nofile 65539
root soft nofile 65539

这个的 root 用户的取值还是 65538 ,因为虽然 root soft nofile 65539 会覆盖我们之前的配置,但是这个配置是不生效的。因为 root soft nofile 65539 配置的值大于root hard nofile 65538 , soft 配置的值不能大于 hard.

示例二: 当我们在 /etc/security/limits.conf 配置了:

root soft nofile 65538
root hard nofile 65538
* soft nofile 65539
* hard nofile 65539

然后我们在 /etc/security/limits.d/20-nofile.conf 配置了:

root soft nofile 65536
root hard nofile 65536
* soft nofile 65540
* hard nofile 65540

最后的取值是会取 /etc/security/limits.d/20-nofile.conf 里面的值。

  1. 配置,只能被特定覆盖。

  2. /etc/security/limits.d/ 下文件的相同配置可以覆盖 /etc/security/limits.conf

  3. soft和hard需要都进行设置,才能生效。

  4. nofile不能设置 unlimited

  5. nofile可以设置的最大值为 1048576(2**20),设置的值大于该数,就会进行登录不了。

  6. soft 设置的值 一定要小于或等于 hard 的值。

具体详细配置根据应用情况进行配置。

三、ulimit 配置后生效

临时配置

设置可以打开文件的最大数为 65536

ulimit  -SHn  65536

重启后失效。

永久配置

配置到配置文件/etc/security/limits.conf或者 /etc/security/limits.d/ 中。 然后退出当前会话,重新登录。 即可生效,重启配置也会保留。

配置不生效的问题

按照上面的配置好了之后,我们进行设置登录到服务器,我发现是配置没有生效的,但是我使用 su - root 之后,发现配置是生效的。 很怪异。 设备环境: Centos6.

问题原因

主要是 Centos6 的原因,我们排查到 sshd 服务的 PAM 模块是没有开启的,而/etc/security/limits.conf 文件实际是 Linux PAM(插入式认证模块,Pluggable Authentication Modules)中 pam_limits.so 的配置文件,我们没有开启 PAM 模块,最终也就没有读取到 /etc/security/limits.conf 的内容。 而 su 进行切换的时候使用的是 终端tty登陆(默认使用PAM模块),

解决办法

在 /etc/ssh/sshd_config 将 UsePAM no 更改为 UsePAM yes, 然后重启 sshd 服务。

四、ulimit 常用命令

      -S    use the `soft' resource limit # 设置软限制
      -H    use the `hard' resource limit # 设置硬限制
      -a    all current limits are reported# 显示所有的配置。
      -b    the socket buffer size # 设置socket buffer 的最大值。
      -c    the maximum size of core files created # 设置core文件的最大值.
      -d    the maximum size of a process's data segment  # 设置线程数据段的最大值
      -e    the maximum scheduling priority (`nice') # 设置最大调度优先级
      -f    the maximum size of files written by the shell and its children # 创建文件的最大值。
      -i    the maximum number of pending signals # 设置最大的等待信号
      -l    the maximum size a process may lock into memory #设置在内存中锁定进程的最大值
      -m    the maximum resident set size 
      -n    the maximum number of open file descriptors # 设置最大可以的打开文件描述符。
      -p    the pipe buffer size
      -q    the maximum number of bytes in POSIX message queues
      -r    the maximum real-time scheduling priority
      -s    the maximum stack size
      -t    the maximum amount of cpu time in seconds
      -u    the maximum number of user processes  # 设置用户可以创建的最大进程数。
      -v    the size of virtual memory  # 设置虚拟内存的最大值
      -x    the maximum number of file locks

查看配置

查看所有的配置

ulimit  -a

查看配置的最大打开文件数

ulimit  -n

更改配置

ulimit  -SHn  65536
Previous日志logrotateNext常用知识

Last updated 5 years ago

Was this helpful?

转载链接:

https://www.cnblogs.com/operationhome/p/11966041.html