Grafana+Prometheus系統監控之MySql

來源:互聯網
上載者:User

標籤:oar   src   man   安裝配置   span   文檔   oca   es2017   mysqld   

架構

grafana和prometheus之前安裝配置過,見:Grafana+Prometheus打造全方位立體監控系統

MySql安裝

MySql的地位和重要性就不言而喻了,作為開源產品深受廣大中小企業以及互連網企業喜愛,所以這裡我們也有必要對其進行相應的監控。

由於最近更換了CentOS7,這裡對MySql重新安裝一遍,順便做個記錄,CentOS7的yum源中預設好像是沒有mysql的。為瞭解決這個問題,我們要先下載mysql的repo源。

列出所有版本資訊:

lsb_release -a

下載mysql的repo源:

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

安裝mysql-community-release-el7-5.noarch.rpm包:

rpm -ivh mysql-community-release-el7-5.noarch.rpm

安裝mysql:

 yum install mysql-server -y

修改許可權,否則會報錯:

chown -R root:root /var/lib/mysql

重啟mysql服務:

service mysqld restart

登入並重設密碼:

## 直接斷行符號進入mysql控制台mysql -u rootmysql > use mysql;mysql > update user set password=password(‘123456‘) where user=‘root‘;mysql > exit;
mysqld_exporter安裝

下載並解壓:

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需要串連Mysql,首先為它建立使用者並賦予所需的許可權:

 GRANT REPLICATION CLIENT, PROCESS ON *.* TO ‘exporter‘@‘localhost‘ identified by ‘123456‘; GRANT SELECT ON performance_schema.* TO ‘exporter‘@‘localhost‘; flush privileges;

建立.my.cnf檔案 vi .my.cnf:

[client]user=exporterpassword=123456

運行mysqld_exporter:

./mysqld_exporter -config.my-cnf=".my.cnf" &
Prometheus配置

修改prometheus.yml加入MySql節點:

global:  scrape_interval:     15s  evaluation_interval: 15sscrape_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

儲存以後重啟Prometheus,查看targets:

最後登入grafana查看MySql監控資訊:

參考文檔:
https://github.com/prometheus/mysqld_exporter

Grafana+Prometheus系統監控之MySql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.