zabbix监控MySQL

zabbix监控MySQLmysql

zabbix有自带mysql的监控模板sql

受权一个监控用户数据库

[root@wangzb01 ~]# mysql -uroot -pmysql
MariaDB [(none)]> grant usage, process, replication client on *.* to 'mon'@'localhost' identified by 'mon';
MariaDB [(none)]> Bye

编辑配置文件socket

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

测试链接数据库ide

[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

测试3d

[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/rest

[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

添加主机和模板code

Configuration -> Hosts -> Create hostblog

Agent interfaces -> 127.0.0.1 10050

Templates -> Select -> Template DB MySQL -> select -> Add Add

monitoring -> latest data 中筛选查看mysql监控状况