码迷,mamicode.com
首页 > 系统相关 > 详细

Linux系统 /etc/security/limits.conf 配置

时间:2017-08-05 19:42:14      阅读:7966      评论:0      收藏:0      [点我收藏+]

标签:posix   priority   ssi   ber   rac   auth   its   调试   ble   

1. limits.conf 配置文件描述

limits.conf文件实际是Linux PAM(插入式认证模块,Pluggable Authentication Modules)中 pam_limits.so 的配置文件,突破系统的默认限制,对系统访问资源有一定保护作用。 limits.conf 和sysctl.conf区别在于limits.conf是针对用户,而sysctl.conf是针对整个系统参数配置。

2. limits.conf工作原理

limits.conf是 pam_limits.so的 配置文件,然后/etc/pam.d/下的应用程序调用pam_***.so模块。譬如说,当用户访问服务器,服务程序将请求发送到PAM模块,PAM模块根据服务名称在/etc/pam.d目 录下选择一个对应的服务文件,然后根据服务文件的内容选择具体的PAM模块进行处理。

3. limit.conf文件格式

# /etc/security/limits.conf
#
#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
#        - 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 file descriptors
#        - rss - max resident set size (KB)
#        - stack - max stack size (KB)
#        - cpu - max CPU time (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]
#        - 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

# End of file
* soft core 0
* hard core 0
* soft nofile 32768
* hard nofile 65536

username|@groupname   type  resource  limit

resource 表示要限制的资源

core - 限制内核文件的大小
何谓core文件,当一个程序崩溃时,在进程当前工作目录的core文件中复制了该进程的存储图像。core文件仅仅是一个内存映象(同时加上调试信息),主要是用来调试的。 core文件是个二进制文件,需要用相应的工具来分析程序崩溃时的内存映像,系统默认core文件的大小为0,所以没有被创建。可以用ulimit命令查看和修改core文件的大小,例如:
#ulimit –c
0
#ulimit -c 1000
-c 指定修改core文件的大小,1000指定了core文件大小。也可以对core文件的大小不做限制,如: ulimit -c unlimited
注意:如果想让修改永久生效,则需要修改配置文件,如 .bash_profile、/etc/profile或/etc/security/limits.conf

nofile - 打开文件的最大数目

对于需要做许多套接字连接并使它们处于打开状态的应用程序而言,最好通过使用ulimit -n,或者通过设置nofile参数,为用户把文件描述符的数量设置得比默认值高一些

maxlogins - 此用户允许登录的最大数目
注意:要使 limits.conf 文件配置生效,必须要确保 pam_limits.so 文件被加入到启动文件中。查看 /etc/pam.d/login 文件中有:session required /lib/security/pam_limits.so

4. limits.conf 设置使用

示例,若机器上部署了ORACLE数据库,我们需要对oracle用户的资源做下调整,如下:

# oracle limits resource
oracle  soft  nproc   2047
oracle  hard  nproc   16384
oracle  soft  nofile  1024
oracle  hard  nofile  65536
oracle  soft  stack   10240

要使 limits.conf 文件配置生效,必须要确保 pam_limits.so 文件被加入到启动文件中。查看 /etc/pam.d/login 文件中有:

session required /lib/security/pam_limits.so

--查看当前系统配置文件ulimit的全局配置

ulimit -a

如果未进行具体设置的话,会使用默认配置,如下查看:

grep ^* /etc/security/limits.conf

批注:当使用*号让全局用户生效的时候,生效的nproc的值大小是受文件/etc/security/limits.d/90-nproc.conf中nproc值大小制约的,而如果仅仅是针对某个用户,那么就不受该文件nproc值大小的影响。

 

Linux系统 /etc/security/limits.conf 配置

标签:posix   priority   ssi   ber   rac   auth   its   调试   ble   

原文地址:http://www.cnblogs.com/secdata/p/7291033.html

(1)
(2)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!