如何在Linux中修改打开文件描述符的数量

  • 原创
  • Madman
  • /
  • /
  • 0
  • 9660 次阅读

如何在Linux中增加打开文件数限制-min.png

Synopsis: 在Linux中,如果您拥有对系统的root访问权限,那么可以更改可以打开文件描述符的最大数量。Linux系统资源限制又分为整个系统层面的总限制,此时要修改内核参数,比如/proc/sys/fs/file-max。还可以对进程和用户分别做资源限制,将ulimit命令写入应用程序的启动脚本中,此时要注意子进程允许打开的最大文件数不能超过父进程的阈值限制。还可以在当前shell会话中直接执行ulimit命令,此时限制的是当前 shell 进程以及其派生的子进程

1. 全局级的文件描述符限制

查看当前的Linux系统上可打开的文件描述符的最大数量:

# cat /proc/sys/fs/file-max
184256

此数值表示每个登录会话中用户可以打开的文件数量,结果可能会因各系统而异。

如果Linux系统用作Apache/MySQL之类的服务器,可能需要打开更多的文件描述符,可以使用sysctl命令增大内核参数fs.file-max的数值:

1. 增加到500000
# sysctl -w fs.file-max=500000

2. 查看效果
# cat /proc/sys/fs/file-max

上述设置只在当前会话有效,如果需要新建会话或重启系统也生效,那么要修改/etc/sysctl.conf配置文件,在末尾添加fs.file-max=500000,然后你想立即看到效果的话,请运行sysctl -p命令

2. 用户级的文件描述符限制

除了可以通过修改内核参数,来设置Linux系统全局的文件描述符限制外,还可以精细化到每个用户或用户组。

2.1 内置命令ulimit

使用ulimit内置命令可以设置shell的资源限制,包括最大可打开的文件数:

1. 查看当前用户所有的资源限制信息
# 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) 31204
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     
                                
                            
  • July
  • Gain Entry to Secret Price Cuts and Payouts cd091393.tw1.ru Sh
  • Start with a Deposit and Get a Cash Incentive cd091393.tw1.ru ta
  • End of event cash distribution cx953449.tw1.ru gE
  • Receive an Enrollment Incentive oiawqjgmai.temp.swtest.ru Yt
  • This cash bonus is shaped just for you cx953449.tw1.ru Xh
  • You're eligible for a substantial cash amount cd091393.tw1.ru WX
  • Act now to secure your USD50 bonus cx953449.tw1.ru lz
  • Be Awarded Immediate Money oiawqjgmai.temp.swtest.ru dv
  • Reserve cash from a jackpot is available cx953449.tw1.ru cA
  • Play for a chance at quick cash cx953449.tw1.ru if
  • Get Rewarded for Diverse Unplanned Work cd091393.tw1.ru US
  • Get a Bonus Just for Starting to Invest cd091393.tw1.ru po
  • Cash incentive for sharing oiawqjgmai.temp.swtest.ru dZ
  • Win Perks Through Consistent Activity cd091393.tw1.ru fF
  • Earn from Informal Jobs cd091393.tw1.ru Ze
  • Time Spent  Money Earned cd091393.tw1.ru vd
  • Exclusive funds await our members cx953449.tw1.ru 8s
  • Rush Your cash bonus awaits oiawqjgmai.temp.swtest.ru 3a
  • Access Monetary Rewards for Education cd091393.tw1.ru Fj
  • Your Time is Worth Money oiawqjgmai.temp.swtest.ru lf
  • Last cash payout happening now cd091393.tw1.ru oQ
  • The spinner could land you real dollars cd091393.tw1.ru Tx
  • Obtain Your Financial Payout Now cx953449.tw1.ru G7
未经允许不得转载: LIFE & SHARE - 王颜公子 » 如何在Linux中修改打开文件描述符的数量

分享

作者

作者头像

Madman

如需 Linux / Python 相关问题付费解答,请按如下方式联系我

0 条评论

暂时还没有评论.

专题系列