zabbix监控MySQL
zabbix有自带mysql的监控模板
授权一个监控用户
[root@wangzb01 ~]# mysql -uroot -pmysql
MariaDB [(none)]> grant usage, process, replication client on *.* to 'mon'@'localhost' identified by 'mon';
MariaDB [(none)]> Bye
编辑配置文件
vi /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
[root@wangzb01 ~]# mkdir /var/lib/zabbix
[root@wangzb01 ~]# vi /var/lib/zabbix/.my.cnf //如下内容
[mysql]
host=localhost
user=mon
password='mon'
socket=/tmp/mysql.sock
测试连接数据库
[root@wangzb01 ~]# mysql -umon -pmon
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 835
Server version: 10.3.11-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> Bye
重启zabbix-agent服务
[root@wangzb01 ~]# systemctl restart zabbix-agent
测试
[root@wangzb01 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k mysql.ping
若提示:sh: mysqladmin: 未找到命令 需要: ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/
[root@wangzb01 ~]# which mysqladmin
/usr/local/mysql/bin/mysqladmin
[root@wangzb01 ~]# ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/
[root@wangzb01 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k mysql.ping
1
[root@wangzb01 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k mysql.version
sh: mysql: 未找到命令
[root@wangzb01 ~]# which mysql
/usr/local/mysql/bin/mysql
[root@wangzb01 ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[root@wangzb01 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k mysql.version
mysql Ver 15.1 Distrib 10.3.11-MariaDB, for Linux (x86_64) using readline 5.1
[root@wangzb01 ~]# zabbix_get -s 127.0.0.1 -p 10050 -k mysql.size
180224
添加主机和模板
Configuration -> Hosts -> Create host
Agent interfaces -> 127.0.0.1 10050
Templates -> Select -> Template DB MySQL -> select -> Add Add
monitoring -> latest data 中筛选查看mysql监控情况