Ubuntu下修改最大文件打开数

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

sudo vim /etc/security/limits.conf

文件尾追加

* hard nofile 655350
* soft nofile 655350

655350可以自己设置,四列参数的设置见英文,简单讲一下:
第一列,可以是用户,也可以是组,要用@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 655350

 

 

第四步:重启服务器生效

Leave a Reply

Your email address will not be published.