1

修改Linux文件句柄数

 1 year ago
source link: https://blog.51cto.com/u_13874232/5590788
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

linux系统里,最大打开的文件句柄数(也即是打开文件数最大限制值),按约定的单个进程能够打开的最大文件句柄数量,默认大小为:1024。

句柄限制类型

系统级最大限制(内核级别)

[root@VM-16-10-centos ~]# cat /proc/sys/fs/file-max
182376

用户级最大限制

[root@VM-16-10-centos ~]# ulimit -n
100001

修改最大限制值

临时修改方法

用户级的临时修改方法:ulimit -SHn 65535
注意:系统重启后失效!

[mysql@VM-16-10-centos ~]$ ulimit -SHn 65535
[mysql@VM-16-10-centos ~]$ ulimit -n
65535

用户级的永久修改方法

vim /etc/security/limits.conf
修改配置文件/etc/security/limits.conf,加入:

soft nofile 65535
hard nofile 65535

echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf

提示:* 表示所用的用户,但有的系统不认, 需要具体的用户名, 比如:
root soft nofile 65535
root hard nofile 65535
重新登录验证,或reboot后验证。

系统级的修改方式

除了以上对一个进程打开的文件句柄数量的限制,此外还需要设置系统的总限制才合理。

例如:我们把进程打开的文件句柄数据设置为:1024,但是系统的总限制为:600,此时所有进程最多能打开文件句柄数量为:600。此外,我们还需要对系统的总限制值进行修改。

系统级的临时修改方式

echo 655350 > /proc/sys/fs/file-max

系统级的永久修改方式

vi /etc/sysctl.conf
添加: fs.file-max=655350
重启服务器后生效。

查看系统级文件句柄值

sysctl

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK