Chinaunix首页 | 论坛 | 博客
  • 博客访问: 56043
  • 博文数量: 11
  • 博客积分: 47
  • 博客等级: 民兵
  • 技术积分: 87
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-10 10:24
个人简介

不学无术

文章分类

全部博文(11)

文章存档

2015年(8)

2013年(1)

2012年(2)

我的朋友

分类: LINUX

2012-05-10 10:32:41

limits.conf 配置

===============================================

/etc/security/limits.conf(Centos 5)

[root@localhost pam.d]# cat /etc/security/limits.conf

# /etc/security/limits.conf

#

#each line describes a limit for a user in the form:

#

#           

#

#where:

# 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

#

# can have the two values:

#        - "soft" for enforcing the soft limits

#        - "hard" for enforcing hard limits

#

# 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)

#        - 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)

#        - nice - max nice priority allowed to raise to

#        - rtprio - max realtime priority

#

#                

#

 

#*               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

 

limits.conf 文件实际是 linux pam(插入式认证模块,pluggable authentication modules)中 pam_limits.so 的配置文件,而且只针对于单个会话。

limits.conf的格式如下:

username|@groupname type resource limit

username|@groupname:设置需要被限制的用户名,组名前面加@和用户名区别。也可以用通配符*来做所有用户的限制。

type:有 softhard -soft 指的是当前系统生效的设置值。hard 表明系统中所能设定的最大值。soft 的限制不能比hard 限制高。用 - 就表明同时设置了 soft hard 的值。

resource

core - 限制内核文件的大小

date - 最大数据大小

fsize - 最大文件大小

memlock - 最大锁定内存地址空间

nofile - 打开文件的最大数目

rss - 最大持久设置大小

stack - 最大栈大小

cpu - 以分钟为单位的最多 cpu 时间

noproc - 进程的最大数目

as - 地址空间限制

maxlogins - 此用户允许登录的最大数目

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

session required /lib/security/pam_limits.so

login里的信息(Centos 5):

[root@localhost pam.d]# cat login

#%PAM-1.0

auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so

auth       include      system-auth

account    required     pam_nologin.so

account    include      system-auth

password   include      system-auth

# pam_selinux.so close should be the first session rule

session    required     pam_selinux.so close

session    optional     pam_keyinit.so force revoke

session    required     pam_loginuid.so

session    include      system-auth

session    optional     pam_console.so

# pam_selinux.so open should only be followed by sessions to be executed in the user context

session    required     pam_selinux.so open

 

例:

oracle soft nproc 2047

oracle hard nproc 16384

oracle soft nofile 1024

oracle hard nofile 65536

======================================================

 

 

limits.conf的工作原理

======================================================

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

    例:限制admin用户登录到sshd的服务不能超过2

    /etc/pam.d/sshd 中添加 session required pam_limits.so

    /etc/security/limits.conf中添加 admin - maxlogins 2

    查看应用程序能否被pam支持,用ldd

======================================================

ulimit 命令用法

========================================================

bash

bash内建了一个限制器"ulimit"。注意任何硬限制都不能设置得太高,因此如果你在/etc/profile或用户的 .bash_profile (用户不能编辑或删除这些文件)中定义了限制规则,你就能对用户的bash shell实施限制。这对于缺少pam支持的linux旧发行版本是很有用的。你还必须确保

 

用户不能改变他们的登录shell。限制的设置与pam相似。例如:

 

ulimit –sc 0

ulimit –su 100

ulimit –hu 150

 

 

ulimit命令

设置限制     可以把命令加到profile文件里,也可以在/etc/security/limits.conf文件中定义

限制。

命令参数

-a      显示所有限制

-c      core文件大小的上限

-d      进程数据段大小的上限

-f      shell所能创建的文件大小的上限

-m     驻留内存大小的上限

-s      堆栈大小的上限

-t      每秒可占用的cpu时间上限

-p     管道大小

-n     打开文件数的上限

-u     进程数的上限

-v     虚拟内存的上限

 

阅读(1721) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:pstree乱码解决

给主人留下些什么吧!~~