知乎專欄 | 多維度架構 |
2018-01-08T01:34:44.515973Z 0 [Warning] Changed limits: max_open_files: 5000 (requested 10240) 2018-01-08T01:34:44.516402Z 0 [Warning] Changed limits: table_open_cache: 1471 (requested 2000)
提出出現在 CentOS 7 ulimit 配置沒有問題的情況下mysql日誌提示 Warning
# ulimit -Sa | grep "open files" open files (-n) 40960
[root@netkiller ~]# cat /proc/`pidof mysqld`/limits Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size 0 unlimited bytes Max resident set unlimited unlimited bytes Max processes 63494 63494 processes Max open files 5000 5000 files Max locked memory 65536 65536 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 63494 63494 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us
動態改變
[root@netkiller ~]# egrep '^(Limit|Max open files)' /proc/`pidof mysqld`/limits Limit Soft Limit Hard Limit Units Max open files 5000 5000 files
問題的出現出現原因是systemctl啟動腳本覆蓋了ulimit配置
# cat /usr/lib/systemd/system/mysqld.service | grep -A2 open_files_limit # Sets open_files_limit LimitNOFILE = 5000
解決方法,直接修改上面的數值,不建議修改mysqld.service,這樣會影響你下次升級。請採用下面的方案完美解決:
mkdir /usr/lib/systemd/system/mysqld.service.d cat >> /usr/lib/systemd/system/mysqld.service.d/override.conf <<EOF [Service] LimitNOFILE=40960 EOF
重啟 MySQL
systemctl daemon-reload systemctl restart mysqld
檢查是否生效
mysql> show variables like 'open_files_limit'; +------------------+-------+ | Variable_name | Value | +------------------+-------+ | open_files_limit | 65535 | +------------------+-------+ 1 row in set (0.01 sec)