ulimit:ulimit用于shell启动进程所占用的资源.是shell的内建命令。
修改ulimit的方法:
①:ulimit的默认值:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@BYRD tmp]# 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) 3884 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) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 3884 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited |
②:临时修改测试
0 1 |
[root@BYRD tmp]# ulimit -n 3096 |
③:永久修改
0 1 2 3 |
[root@BYRD ~]# vi /etc/security/limits.conf #编辑,增加如下内容: * - nofile 50000 #最大打开文件数 或者使用echo直接追加 [root@BYRD ~]# echo '* - nofile 50000' >>/etc/security/limits.conf |
0 1 |
[root@BYRD ~]# ulimit -n #操作前,退出重新登录 50000 |
按照网络上的说法如果写入rc.local这个是启动项,经过试验结果存在异议。我的测试结果是不可行,看步骤!
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
[root@BYRD ~]# vim /etc/rc.local #!/bin/sh # This script will be executed *after* all the other init scripts. touch /var/lock/subsys/local ulimit -HSn 3096 #H硬限制,S软限制,n表示设定单个进程最大的打开文件句柄数量 [root@BYRD ~]# reboot [root@BYRD ~]# ulimit -n #依然是1024,而不是设置好的3096,这个不修改/etc/security/limits.conf 1024 [root@BYRD ~]# ls -l /etc/rc.local lrwxrwxrwx. 1 root root 13 Apr 1 14:35 /etc/rc.local -> rc.d/rc.local [root@BYRD ~]# ls -l /etc/rc.d/rc3.d/S99local lrwxrwxrwx. 1 root root 11 Apr 1 14:35 /etc/rc.d/rc3.d/S99local -> ../rc.local [root@BYRD ~]# vim /etc/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local ulimit -HSn 30961 && echo 'right' >>/tmp/right.txt || echo 'wrong' >>/tmp/wrong.txt #如果ulimit -HSn 3096 执行成功,就向/tmp/right中返回一个值right,如果ulimit -HSn 3096执行不成功,所有导致echo 'right' >>/tmp/right.txt 也就不成功,因此返回值wrong到/tmp/wrong.txt printf $(ulimit -n) >>/tmp/ulimit1.txt 2>&1 #打印ulimit -n的值到ulimit1.txt中 ulimit -HSn 3096 #同上 printf $(ulimit -n) >>/tmp/ulimit.txt 2>&1 #打印ulimit -n 的值到/tmp/ulimit.txt中 [root@BYRD ~]# >/tmp/ulimit.txt [root@BYRD ~]# >/tmp/ulimit1.txt [root@BYRD ~]# >/tmp/right.txt [root@BYRD ~]# >/tmp/wrong.txt [root@BYRD ~]# reboot [root@BYRD ~]# cat /tmp/right.txt right [root@BYRD ~]# cat /tmp/wrong.txt [root@BYRD ~]# cat /tmp/ulimit1.txt 30961 [root@BYRD ~]# cat /tmp/ulimit.txt 3096 [root@BYRD ~]# ulimit -n 1024 |
申明:本文由BYRD原创(基于Centos6.4 X64),未经许可禁止转载!
参考:http://blog.csdn.net/guowake/article/details/6615728
参考:http://www.ibm.com/developerworks/cn/linux/l-cn-ulimit/SourceByrd's Weblog-https://note.t4x.org/system/change-ulimit-nofile/ SourceByrd's Weblog-https://note.t4x.org/system/change-ulimit-nofile/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!