Linux资源使用配置文件 /etc/security/limits.conf

http://www.linuxidc.com/Linux/2012-05/59489.htm

Linux就这个范儿P561

Linux处于稳定性的考虑,默认情况下对系统资源都做了限制,有一些Linux发行版会保守一些,如果不是很极端的话,尽量不要修改

还有一个限制最大打开文件描述符的地方,通过procfs文件系统来调整 cat /proc/sys/fs/file-max

这个文件主要是用来限制用户对系统资源的使用,具体的使用方法 man 5 limits.conf,里面便给出了详细的用法

  1. user@db-2:~$ cat /etc/security/limits.conf
  2. # /etc/security/limits.conf
  3. #
  4. #Each line describes a limit for a user in the form:
  5. #
  6. #<domain>        <type>  <item>  <value>
  7. #
  8. #Where:
  9. #<domain> can be:
  10. #        - an user name
  11. #        - a group name, with @group syntax
  12. #        - the wildcard *, for default entry
  13. #        - the wildcard %, can be also used with %group syntax,
  14. #                 for maxlogin limit
  15. #
  16. #<type> can have the two values:
  17. #        - "soft" for enforcing the soft limits # 软限制,必须比硬限制的值要小
  18. #        - "hard" for enforcing hard limits     # 硬限制
  19. #
  20. #<item> can be one of the following:
  21. #        - core - limits the core file size (KB)
  22. #        - data - max data size (KB)
  23. #        - fsize - maximum filesize (KB)
  24. #        - memlock - max locked-in-memory address space (KB)
  25. #        - nofile - max number of open files    # 最大打开的文件数(以文件描叙符,file descriptor计数)
  26. #        - rss - max resident set size (KB)
  27. #        - stack - max stack size (KB)
  28. #        - cpu - max CPU time (MIN)
  29. #        - nproc - max number of processes
  30. #        - as - address space limit
  31. #        - maxlogins - max number of logins for this user
  32. #        - maxsyslogins - max number of logins on the system
  33. #        - priority - the priority to run user process with
  34. #        - locks - max number of file locks the user can hold
  35. #        - sigpending - max number of pending signals
  36. #        - msgqueue - max memory used by POSIX message queues (bytes)
  37. #        - nice - max nice priority allowed to raise to
  38. #        - rtprio - max realtime priority
  39. #
  40. #<domain>      <type>  <item>         <value>
  41. #
  42. root            soft    nofile          200000
  43. root            hard    nofile          200000
  44. admin           hard    nofile          65536
  45. admin           soft    nofile          65536
  46. # End of file

每行的格式:
用户名/用户组    类型(硬限制、软限制)   选项     值

比如很多朋友可能在使用mysql的时候遇到too many open files的错误,此时便可以通过将运行mysqld的用户的 nofile(最大打开文件数)这个值增大一点,例如
db_running_user      -      nofile    设定一个合理的值  
注意上面的第二列 ‘-’表示hard和soft,可以显示的为soft和hard写两行

我这只是举一个例子,这个文件还可以配置很多资源的使用,但是一般的情况下用默认的就行,当你有特殊需求或者自己对这些参数的来龙去脉又相当了解,你可以去改这些默认的参数,查看当前用户的这些资源使用限制情况可以使用 ulimit -a(查看ulimit的使用方法,用man ulimit无效,可以用help ulimit)

那么对它的修改什么时候生效呢?每次重新login的时候生效,至于原因则是我参考的那篇文章里面说了。

自己的疑问:

1. 为什么要同时有soft和hard这两个限制?这个soft和hard应该是代表两种类型的阀值吧,一定不能超过hard限制,但是可以超过soft限制,有一个hard不就够了么?

知道设置两个参数的意义在于:hard是一个上限在运行期间不可以调大但���以调小,而soft只能比hard小,在运行期间可以调大。 我也用mysqld测试过,它读取的是soft值,但是我又不解的是,既然修改/etc/security/limits.conf要重新login才生效,那么这些修改的意义不就没有了吗?因为要重新登录,意味着服务要重启

应该是这个解释比较合理,soft是一个警告值,而hard则是一个真正意义的阀值,超过就会报错

http://www.linuxidc.com/Linux/2012-05/59489.htm
改最大连接数
vi  /etc/security/limits.conf
 
*   hard   nproc    h1
*   hard   nofile     h1

vi /etc/security/limits.d/90-nproc.conf

*   hard    nproc    h2

echo  '*   hard   nproc    65535'  >>/etc/security/limits.conf  //centos5
echo '* hard nofile 65535' >>/etc/security/limits.conf
echo '* hard nproc 65535' >>/etc/limits.d/-nproc.conf //centos6

注意:  hard    nproc    h2,root用户不受nproc    限制

lnmp第二部分

http://www.cnblogs.com/MYSQLZOUQI/p/4996262.html

nginx配置文件

nginx.conf
user nobody nobody; //使用哪个用户和组来启动子进程 主进程必须是root 1024以下的端口必须是root用户监听
worker_processes ; //开启多少个子进程
error_log /usr/local/nginx/logs/nginx_error.log crit; //日志级别crit
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile ; //打开文件描述符的个数
events
{
use epoll; //事件模型
worker_connections ; 每个worker支持多少连接 曾经设置过10240 nginx做反向代理 导致502错误 最好不要设置那么大
}

Linux资源使用配置文件 /etc/security/limits.conf的更多相关文章

  1. linux资源使用配置文件 /etc/security/limits.conf和ulimit

    limits.conf文件实际上是linux PAM中pam_limits.so的配置文件,而且只针对于单个会话. limits.conf的格式如下: <domain> <type& ...

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

    目录 一. /etc/security/limits.conf 详解 /etc/security/limits.conf 配置解析 /etc/security/limits.d/ 目录 二. ulim ...

  3. CentOS6.x 下 /etc/security/limits.conf 被改错的故障经历

    Intro 我司本小厂,每个员工都是身兼数职,所以开发人员直接登录线上服务器改东西是常态.有些开发人员,自持水平较高(的确水平也是较高,但缺乏对系统的敬畏),所以总是越俎代庖,改一些本身应该是线上运维 ...

  4. 理解RHEL上安装oracle的配置参数 :/etc/security/limits.conf, /etc/profile, /etc/pam.d/login

    无论安装什么版本的Oracle,在安装之前,都需要配置 /etc/pam.d/login   /etc/profile   /etc/security/limits.conf这三个文件 那这三个文件究 ...

  5. linux /proc/sys/fs/file-nr /proc/sys/fs/file-max /etc/security/limits.conf 三者的关联

    ulimit -n 对应 /etc/security/limits.conf 文件设置 问题: Can’t open so many files 对于linux运维的同学们,相信都遇到过这个问题. 在 ...

  6. [转帖]linux文件描述符文件/etc/security/limits.conf

    linux文件描述符文件/etc/security/limits.conf https://blog.csdn.net/fanren224/article/details/79971359 需要多学习 ...

  7. /etc/security/limits.conf配置文件详解

    这个文件主要是用来限制用户对系统资源的使用.是/lib64/security/pam_limits.so模块对应的/etc/serurity/pam_limits的配置文件. # /etc/secur ...

  8. /etc/security/limits.conf 文件说明

    /etc/security/limits.conf 是 Linux 资源使用配置文件,用来限制用户对系统资源的使用 语法:<domain>  <type>  <item& ...

  9. [转帖]/etc/security/limits.conf的含义

    https://www.cnblogs.com/pzk7788/p/7250723.html /etc/security/limits.conf 是 Linux 资源使用配置文件,用来限制用户对系统资 ...

随机推荐

  1. Linux配置防火墙,开启80port、3306port 可能会遇到的小问题

     vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(同意80端口通 ...

  2. c++ __int64

    C++的64位整数[原]by 赤兔 在做ACM题时,经常都会遇到一些比较大的整数.而常用的内置整数类型常常显得太小了:其中long 和 int 范围是[-2^31,2^31),即-2147483648 ...

  3. 适配器模式(Adapter Pattern)----------结构型模式

    对象适配器模式的缺点是:与类适配器模式相比,要在适配器中置换适配着类的某些方法比较麻烦.如果一定要置换掉适配者类的一个或多个方法,可以先做一个适配者类的子类,在子类中将适配者类的方法置换掉,然后再把适 ...

  4. MathType编辑物理单位的方法

    在用MathType编辑物理公式时,由于物理单位很多都是复合单位,所以在编辑时如果能够有这种复合单位直接使用的话,编辑效率就会大大提高.实际上这种想法在MathType中是可行的,MathType中也 ...

  5. SQLServer------聚集索引和非聚集索引的区别

    转载: http://www.cnblogs.com/flashicp/archive/2007/05/08/739245.html 建立非聚集索引(vid不是主键) create index idx ...

  6. HTML&CSS精选笔记_布局与兼容性

    布局与兼容性 CSS布局 版心和布局流程 为什么要应用布局? 阅读报纸时容易发现,虽然报纸中的内容很多,但是经过合理地排版,版面依然清晰.易读.同样,在制作网页时,要想使页面结构清晰.有条理,也需要对 ...

  7. python2.0_day18_django_ORM

    Django_ORMday15\16我们学到的ORM都是最基本的增删改查.下面我们稍作升级,学习下高级点的增删改查.先创建一个新的APP项目 python3. manage.py startapp b ...

  8. pow()

    pow() 如果接收两个参数,如 pow(x, y),则结果相当于 x**y,也就是 x 的 y 次方pow() 如果接收三个参数,如 pow(x, y, z),则结果相当于 (x**y) % z,也 ...

  9. ios 图片处理( 1.按比例缩放 2.指定宽度按比例缩放

    本文转载至 http://blog.sina.com.cn/s/blog_6f29e81f0101tat6.html //按比例缩放,size 是你要把图显示到 多大区域 CGSizeMake(300 ...

  10. ubuntu下Eclipse创建Django项目

    (注:部分过程可能需要FQ) Eclipse版本:Mars.x 点击help->Eclipse Marketplace,搜索“PyDev”并下载安装. 然后选择window->prefer ...