環(huán)境和前提:
mysql 5.7.32
CentOS Linux release 7.9.2009 (Core)
open-files-limit = 16384
現(xiàn)象:
連接數(shù)接近了5000
報(bào)錯(cuò) [ERROR] Error in accept: Too many open files
root@(none) 17:24:24> show global variables like '%open%';
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| have_openssl | YES |
| innodb_open_files | 995 |
| open_files_limit | 5000 |
| table_open_cache | 995 |
| table_open_cache_instances | 16 |
+----------------------------+-------+
[root@ooxx logs]# ulimit -a
..........
open files (-n) 61000
分析:
[root@5jdb01 33950]# more limits
Limit Soft Limit Hard Limit Units
..........
Max open files 5000 5000 files
和我配置文件中的open-files-limit值對(duì)不上,沒生效
open_files_limit 這個(gè)數(shù)字少了點(diǎn)剿牺,這里有個(gè)算法:
max_open_files_1 = max_connections + table_cache * 2 = 100 + 1000 * 2 = 2100
max_open_files_2 = max_connections*5 = 100 * 5 = 500
解決方法:
vim /lib/systemd/system/mysqld.service
LimitNOFILE = 61000
重啟MySQL服務(wù)
全局修改方法:
vim /etc/systemd/system.conf
DefaultLimitCORE=infinity
DefaultLimitNOFILE=61000
DefaultLimitNPROC=61000
重啟服務(wù)器使之生效