Ubuntu 12 ulimit 系统最大打开文件个数 设置

11 篇文章 0 订阅

网上能搜索到不少,不过好象都不管用。。

基本命令了解:

root@ubuntu:~# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 31498
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 31498
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

红字部分就是打开文件数1024个,一般这个太小了。也可以用ulimit -n查看


如何设置呢,官方是这样的:

第一步:配置/etc/security/limits.conf

sudo vim /etc/security/limits.conf
文件尾追加 
* hard nofile 40960
* soft nofile 40960
4096可以自己设置,四列参数的设置见英文,简单讲一下:

第一列,可以是用户,也可以是组,要用@group这样的语法,也可以是通配符如*%

第二列,两个值:hard,硬限制,soft,软件限制,一般来说soft要比hard小,hard是底线,决对不能超过,超过soft报警,直到hard数

第三列,见列表,打开文件数是nofile

第四列,数量,这个也不能设置太大


#
#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
#        - NOTE: group and wildcard limits are not applied to root.
#          To apply a limit to the root user, <domain> must be
#          the literal username root.
#
#<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)
#        - 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
#        - chroot - change root to directory (Debian-specific)
#
#<domain>      <type>  <item>         <value>
#


#*               soft    core            0
#root            hard    core            100000


第二步:/etc/pam.d/su(官方)或/etc/pam.d/common-session(网络)

sudo vim /etc/pam.d/su
将 pam_limits.so 这一行注释去掉 
重起系统
sudo vim /etc/pam.d/common-session
加上以下一行
session required pam_limits.so

打开/etc/pam.d/su,发现是包含/etc/pam.d/common-session这个文件的,所以修改哪个文件都应该是可以的

这个觉得修改su这个文件比较好,取消注释就OK了,不容易出错,vim打开,定位,x一下即可



官方只到第二步,就重启系统了,没有第三步,好象不行,感觉是不是全是第三步的作用?!

第三步:配置/etc/profile

最后一行加上

ulimit -SHn 40960

重启,ulimit -n 验证,显示40960就没问题了



更新:2012/9/29:

CentOS 6.3上,只要修改/etc/security/limits.conf,重新登录就OK了。

Ubuntu Server 12.04.1上,修改/etc/security/limits.conf,重登录重启不管用,改/etc/pam.d/common-session, su,重登录重启不管用,非要改/etc/profile?

看来两者是有差异的?还是我测试不到位?

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值