背景環境:公司新搭建的zabbix監控系統,使用mariadb數據庫,一直運行正常,然后某天突然發現zabbix打不開了,進入服務器重啟zabbix-server和mariadb直接卡住不動。
配置:centos7.6 zabbix4.0
解決步驟:
1.登錄df -h 查看磁盤空間使用率,發現/var 占用100%,進行無關文件刪除之后重啟服務器;
2.但是登錄zabbix發現提示警告mysql最大連接數有問題,於是登錄mariadb進行排查解決,具體步驟如下
提示如下:
connection to database 'zabbix' failed: [1040] Too many connections
解決:
1.進入數據庫
mysql
show variables like 'max_connections';

2、修改/etc/my.cnf配置文件
在[mysqld]新添加一行:
[root@zabbix-server ]# vi /etc/my.cnf
max_connections=1000
重啟mariadb服務,並驗證最大連接數(沒顯示我們修改的):
[root@zabbix-server ]# systemctl restart mariadb.service
[root@zabbix-server ]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 446
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 214 |
+-----------------+-------+
1 row in set (0.00 sec)
3、配置/usr/lib/systemd/system/mariadb.service來調大打開文件數目
[root@zabbix-server ]# vi /usr/lib/systemd/system/mariadb.service
在[Service]新加這兩行:
LimitNOFILE=10000
LimitNPROC=10000
4、重新加載系統服務,並重啟mariadb服務
systemctl daemon-reload
[root@zabbix-server ]# systemctl --system daemon-reload
[root@zabbix-server ]# systemctl restart mariadb.service
5、重新驗證下,是否為1000
MariaDB [(none)]> show variables like 'max_connections';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 5
Current database: *** NONE ***
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
1 row in set (0.00 sec)
ok 打開zabbix服務運行正常
