增大mysql/mariadb的最大连接数

最近在部署一个大型的zabbix监控,遭遇了mysql连接数不足的情况,在增加mysql的最大连接数的过程中,发现还是有点繁琐的,于是在这里记录下来。

参考:https://pjstrnad.com/mariadb-raise-number-of-connections/

首先,去编辑/etc/my.cnf,或者相应的mysql服务器配置文件。

在[mysqld]一节下方增加以下内容:

open_files_limit=12000
max_connections=10000

对应的两个参数可以根据实际需要修改。此时重启mysql服务器,发现设置并未生效,或者说生效了一半,只增加到了214,原因是systemd本身存在限制导致的。
接下来修改/etc/security/limits.conf,如果没有,就新建一个,插入以下内容。

mysql soft nofile 4096
mysql hard nofile 10240

然后创建systemd启动文件的配置

mkdir -p /etc/systemd/system/mariadb.service.d
vi /etc/systemd/system/mariadb.service.d/limits.conf

然后插入以下内容

[Service]
LimitNOFILE=infinity

完成后就可以重启MySQL服务器了

systemctl daemon-reload
systemctl restart mariadb

发表评论