Too many open files in systemOpt 解决方案 及 Kernel 内核及优化 及 linux系统内核参数file-max与ulimit的关系与差别

本文介绍在高并发场景下遇到Toomanyopenfiles错误的排查与解决方法,通过调整Linux系统内核参数fs.file-max,解决因文件句柄数量限制导致的服务不可达问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在某台服务器遇到高并发访问时,有时就会出现 当我们登录这台服务器时,直接登录失败,报错如下:
Too many open files in systemOpt

通过zabbix监控平台同时会发现出现报警:

Zabbix agent on xx.xx.xx.xx is unreachable for 5 minutes

在高并发期间,zabbix server 获取不到该台服务器的任何监控数据,如下图所示

通过 ullimit -n 及 ulimit -u 查看,设置都正常

-bash-4.2$ ulimit -n
102400
-bash-4.2$ ulimit -u
102400

那么出些这种高并发导致的 Too many open files in systemOpt 故障该如何着手解决?

下面讲解排查思路和解决方案:

-bash-4.2$ cat /proc/sys/fs/file-max 
65535

发现文件限制数太少

lscpu 查看 该台服务器 cpu 核数太少,才四核

-bash-4.2$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            15
Model:                 6
Model name:            Intel(R) Xeon(R) Silver 4116 CPU @ 2.10GHz
Stepping:              3
CPU MHz:               2095.078
BogoMIPS:              4190.15
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
L3 cache:              16384K
NUMA node0 CPU(s):     0-3
Flags:                 fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx lm constant_tsc nopl xtopology eagerfpu pni cx16 x2apic hypervisor lahf_lm
-bash-4.2$ 

查看 /etc/sysctl.conf 发现:

-bash-4.2$ cat /etc/sysctl.conf 
fs.file-max = 65535
...
...
...

修改 /etc/sysctl.conf 文件中 内核参数 fs.file-max

-bash-4.2$ vim /etc/sysctl.conf 
fs.file-max = 655350
...
...
...

执行 sysctl -p ,从 /etc/sysctl.conf 中加载系统参数,以使设置立即生效

-bash-4.2$ sudo sysctl -p
fs.file-max = 655350
...
...
...
-bash-4.2$

注意:

sysctl 作用:sysctl 用来配置与显示在 /proc/sys 目录中的内核参数。

 

执行 sysctl -p 后,生效后效果如下:

-bash-4.2$ cat /proc/sys/fs/file-max 
655350
-bash-4.2$

---------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------

linux 系统内核参数file-max 与 ulimit 的关系与差别:

简单的说,max-file 表示系统级别的能够打开的文件句柄的数量,而 ulimit -n 控制进程级别 能够打开的文件句柄的数量。提供大量静态文件访问的web服务器,缓存服务器(如squid), 均要注意这个问题。

 

 

 

参考链接:

sysctl -p 详解:https://www.cnblogs.com/davidshen/p/10442219.html

linux 系统内核参数file-max 与 ulimit 的关系与差别:http://www.21yunwei.com/archives/5736

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wudinaniya

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值