在某台服务器遇到高并发访问时,有时就会出现 当我们登录这台服务器时,直接登录失败,报错如下:
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