记一下这个坑
最近将一个 php 环境迁移到了 CentOS 7,一开始一切都好,但是网站正式上线后一段时间却老是出现 php-fpm 进程繁忙的情况了。
刚开始以为是 php-fpm 哪里配错了,后来才发现是 MariaDB 的问题,日志里面一直在报达到了最大打开文件数。看了下,发现最大可以打开文件数是 1024,确实小了。
limits.conf 里面是早就把限制调高了的,所以在 /etc/my.cnf 里面加了一行
open-file-limits = 10240
结果重启后却还是 1024。
最终是在 /usr/lib/systemd/system/mariadb.service 里面找到了线索
# It's not recommended to modify this file in-place, because it will be # overwritten during package upgrades. If you want to customize, the # best way is to create a file "/etc/systemd/system/mariadb.service", # containing # .include /lib/systemd/system/mariadb.service # ...make your changes here... # or create a file "/etc/systemd/system/mariadb.service.d/foo.conf", # which doesn't need to include ".include" call and which will be parsed # after the file mariadb.service itself is parsed. # # For more info about custom unit files, see systemd.unit(5) or # http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F # For example, if you want to increase mariadb's open-files-limit to 10000, # you need to increase systemd's LimitNOFILE setting, so create a file named # "/etc/systemd/system/mariadb.service.d/limits.conf" containing: # [Service] # LimitNOFILE=10000
需要由 systemd 来提高最大可以打开文件数。
于是按照提示创建了 /etc/systemd/system/mariadb.d/limits.conf 加入了
[Service] LimitNOFILE=65535
结果发现还是老样子
…
最终,再把 /etc/my.cnf 里面的 open-file-limits = 10240 删除掉才行。。。