手把手帶你部署Prometheus+Grafana+Mysql監控系統

環境準備:

Prometheus        192.168.60.100

被控節點客戶端:192.168.60.101

Grafana:            192.168.60.102

【部署Prometheus】

# tar xvf prometheus-2.5.0.linux-amd64.tar.gz -C /usr/local/

# mv /usr/local/prometheus-2.5.0.linux-amd64/ /usr/local/prometheus

#vim /lib/systemd/system/prometheus.service  #註冊prometheus啓動服務

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.enable-lifecycle
ExecStop=/usr/bin/killall -9 prometheus



[Install]
WantedBy=multi-user.target

#systemctl daemon-reload

#systemctl start prometheus

#systemctk enable prometheus

#訪問192.168.60.100:9090即可訪問prometheus頁面

#通過http://192.168.60.100:9090/metrics可以查看到監控的數據

#在Prometheus界面可以通過關鍵詞查詢監控項,點擊Graph圖標,然後點擊Execute即可看到所查詢的監控項所匯成的圖標;

 

【部署prometheus的被控節點】

# tar xvf node_exporter-0.16.0.linux-amd64.tar.gz

## mv /usr/local/node_exporter-0.16.0.linux-amd64/ /usr/local/node_exporter

# vim /usr/lib/systemd/system/node_exporter.service

[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/node_exporter/node_exporter

[Install]
WantedBy=multi-user.target

[Unit]
Description=node_exporter
After=network.target

 # systemctl start  node_exporter

#systemctl enable node_exporter

回到Prometheus服務節點指定被控agent的IP地址信息

# vim /usr/local/prometheus/prometheus.yml

 - job_name: "agent1"
    static_configs:
    - targets: ['192.168.60.101:9100']

#systemctl restart prometheus

訪問http://168.63.136.238:9090即可看到監控狀態信息

 

 

【監控mysql數據庫】

在192.168.60.101被控節點上部署mariadb數據庫,並安裝監控數據庫的prometheus插件,以便後續能正常監控mysql數據庫性能指標

# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz

# tar xvf mysqld_exporter-0.12.1.linux-amd64.tar.gz

# mv /usr/local/mysqld_exporter-0.12.1.linux-amd64/ /usr/local/mysqld_exporter

MariaDB [(none)]> grant select,replication client,process on *.* to 'mysql_monitor'@'localhost' identified by '123.com';

MariaDB [(none)]> flush privileges;

#vim cat /usr/local/mysqld_exporter/.my.cnf

[client]
user=mysql_monitor
password=123.com

#vim /usr/lib/systemd/system/mysqld_exporter.service

[Unit]
Description=mysqld_exporter
After=network.target
[Service]
Type=simple
User=mysql
Environment=DATA_SOURCE_NAME=mysql_montor:123.com(localhost:3306)/
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --web.listen-address=0.0.0.0:9104
 --config.my-cnf /etc/my.cnf \
# --collect.slave_status \
# --collect.slave_hosts \
  --log.level=error \
# --collect.info_schema.processlist \
# --collect.info_schema.innodb_metrics \
# --collect.info_schema.innodb_tablespaces \
# --collect.info_schema.innodb_cmp \
# --collect.info_schema.innodb_cmpmem
Restart=on-failure
[Install]
WantedBy=multi-user.targe

啓動exporter插件

#systemctl daemon-reload

#systemctl enable mysqld_exporter.service

#systemctl start mysqld_exporter.service

 測試:http://192.168.60.101:9104/metrics   #訪問被控節點的9104端口,即可查看監控信息

 回到promethues服務節點,在配置文件中添加被控節點的mariadb配置段

# vim /usr/local/prometheus/prometheus.yml

 - job_name: 'mariadb'
    static_configs:
    - targets: ['192.168.60.101:9104']

 

 【部署Grafana監控】

192.168.60.102節點部署Granfana

使用Grafana連接Promethues監控

# rpm -ivh grafana-5.3.4-1.x86_64.rpm

# systemctl enable grafana-server
# systemctl start grafana-serve

 

 

 

【Grafana展示Mysql的數據】

上述已經將Granfana和Prometheus的數據源關聯起來,現在是要做的就是將Prometheus收集到的數據進行圖形化展示,操作如下:

1、修改grafana配置文件 #添加以下內容

[dashboards.json]
enabled= true
path=/var/lib/grafana/dashboards
[[email protected]-006 ~]#

 

#git clone  https://github.com/percona/grafana-dashboards.git

 #cp -r /var/lib/grafana/grafana-dashboards/dashboards/ /var/lib/grafana/

#systemctl restart grafana-server

 

 

 驗證Grafana數據收集是否正常.

 

END!

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章