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監控狀況

相關文章
相關標籤/搜索