Architecture
Grafana and Prometheus prior to installation configuration, see: Grafana+prometheus to create a comprehensive three-dimensional monitoring system
MySQL Installation
MySQL's status and importance is self-evident, as open-source products by the vast number of small and medium-sized enterprises and internet companies love, so here we also need to monitor it accordingly.
Due to the recent replacement of CentOS7, MySQL is installed here again, by the way to make a record, the CentOS7 yum source default seems to be no MySQL. To solve this problem, we need to download the MySQL repo source first.
List all version information:
lsb_release -a
Download the repo source for MySQL:
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
To install the MYSQL-COMMUNITY-RELEASE-EL7-5.NOARCH.RPM package:
rpm -ivh mysql-community-release-el7-5.noarch.rpm
Install MySQL:
yum install mysql-server -y
Modify permissions, or you will get an error:
chown -R root:root /var/lib/mysql
To restart the MySQL service:
service mysqld restart
Sign in and reset your password:
## 直接回车进入mysql控制台mysql -u rootmysql > use mysql;mysql > update user set password=password(‘123456‘) where user=‘root‘;mysql > exit;
Mysqld_exporter Installation
Download and unzip:
https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gztar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz
Mysqld_exporter need to connect to MySQL, first create a user for it and give the required permissions:
GRANTONTO‘exporter‘@‘localhost‘identifiedby‘123456‘GRANTSELECTONTO‘exporter‘@‘localhost‘flushprivileges;
Create a. my.cnf file VI. MY.CNF:
[client]user=exporterpassword=123456
Run Mysqld_exporter:
./mysqld_exporter -config.my-cnf=".my.cnf" &
Prometheus Configuration
Modify PROMETHEUS.YML to join the MySQL node:
Global: Scrape_interval:15sEvaluation_interval:15sScrape_configs: - job_name:PrometheusStatic_configs: - Targets: [' localhost:9090 '] Labels: instance:Prometheus- job_name:Linux1Static_configs: - Targets: [' 192.168.1.120:9100 '] Labels: instance:Sys1- job_name:Linux2Static_configs: - Targets: [' 192.168.1.130:9100 '] Labels: instance:Sys2- job_name:Redis1Static_configs: - Targets: [' 192.168.1.120:9121 '] Labels: instance:Redis1- job_name:MysqlStatic_configs: - Targets: [' 192.168.1.120:9104 '] Labels: instance:Db1
To restart Prometheus after saving, view targets:
Last login Grafana view MySQL monitoring information:
Reference Documentation:
Https://github.com/prometheus/mysqld_exporter
Grafana+prometheus system monitoring MySQL