grafana和prometheus以前安裝配置過,見:Grafana+Prometheus打造全方位立體監控系統mysql
MySql的地位和重要性就不言而喻了,做爲開源產品深受廣大中小企業以及互聯網企業喜好,因此這裏咱們也有必要對其進行相應的監控。linux
因爲最近更換了CentOS7,這裏對MySql從新安裝一遍,順便作個記錄,CentOS7的yum源中默認好像是沒有mysql的。爲了解決這個問題,咱們要先下載mysql的repo源。git
列出全部版本信息:github
lsb_release -a
複製代碼
下載mysql的repo源:redis
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
複製代碼
安裝mysql-community-release-el7-5.noarch.rpm包:sql
rpm -ivh mysql-community-release-el7-5.noarch.rpm
複製代碼
安裝mysql:bash
yum install mysql-server -y
複製代碼
chown -R root:root /var/lib/mysql
複製代碼
重啓mysql服務:ide
service mysqld restart
複製代碼
登陸並重置密碼:ui
## 直接回車進入mysql控制檯
mysql -u root
mysql > use mysql;
mysql > update user set password=password('123456') where user='root';
mysql > exit;
複製代碼
https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz
tar -xvf mysqld_exporter-0.10.0.linux-amd64.tar.gz
複製代碼
mysqld_exporter須要鏈接Mysql,首先爲它建立用戶並賦予所需的權限:
GRANT REPLICATION CLIENT, PROCESS ON . TO 'exporter'@'localhost' identified by '123456';
GRANT SELECT ON performance_schema.* TO 'exporter'@'localhost';
flush privileges;
複製代碼
[client]
user=exporter
password=123456
複製代碼
./mysqld_exporter -config.my-cnf=".my.cnf" &
複製代碼
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
labels:
instance: prometheus
- job_name: linux1
static_configs:
- targets: ['192.168.1.120:9100']
labels:
instance: sys1
- job_name: linux2
static_configs:
- targets: ['192.168.1.130:9100']
labels:
instance: sys2
- job_name: redis1
static_configs:
- targets: ['192.168.1.120:9121']
labels:
instance: redis1
- job_name: mysql
static_configs:
- targets: ['192.168.1.120:9104']
labels:
instance: db1
複製代碼