1.环境说明

监控主机 被监控主机
192.168.0.66 192.168.0.67
运维主机 MySQL

2.主机安装Prometheus

下载:https://prometheus.io/download/

上传到主机
[root@localhost ~]# yum -y ×××tall vim lrzsz

3.安装go

[root@localhost ~]# yum -y ×××tall epel-release
[root@localhost ~]# yum -y ×××tall go
Prometheus解压即可用
[root@localhost ~]# tar xf prometheus-2.10.0.linux-amd64.tar.gz -C /usr/local/

4.安装编辑Prometheus配置文件

[root@localhost ~]# vim /usr/local/prometheus-2.10.0.linux-amd64/prometheus.yml
追加如下内容(前方空格一定要对齐):
  - job_name: system-status
    static_configs:
    - targets: ['192.168.0.67:9100']
      labels:
        ×××tance: 7-7
  - job_name: mysql-status
    static_configs:
    - targets: ['192.168.0.67:9104']
      labels:
        ×××tance: 7-7-mysql

centos7下部署 Prometheus+Grafana超炫监控_第1张图片

5.启动Prometheus

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# cd /usr/local/prometheus-2.10.0.linux-amd64/
[root@localhost prometheus-2.10.0.linux-amd64]# ./prometheus --config.file=prometheus.yml &    # &意为后台启动

Prometheus页面如下
centos7下部署 Prometheus+Grafana超炫监控_第2张图片

6.配置被监控服务器

(1)、node_exporter 用于监控操作系统的性能和运行状态(官网自行下载)
(2)、mysqld_exporter 用于监控 mysql 服务(官网自行下载)
(3)、snmp_exporter 用于监控网络设备
更多 exporter 可在官网下载:https://prometheus.io/download/#node_exporter

7.mysql安装和授权

[root@localhost ~]# yum -y ×××tall mariadb mariadb-server
[root@localhost ~]# systemctl restart mariadb
[root@localhost ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB 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)]>  GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'mysql_monitor'@'localhost'
    -> identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT SELECT ON *.* TO 'mysql_monitor'@'localhost';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> exit
Bye

8.安装主机监控的node_exporter

[root@localhost ~]# tar xf node_exporter-0.17.0.linux-amd64.tar.gz -C /usr/local/
[root@localhost ~]# /usr/local/node_exporter-0.17.0.linux-amd64/node_exporter &

9.安装主机监控的mysql_exporter

[root@localhost ~]# tar xf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /usr/local/
[root@localhost ~]# vim /usr/local/mysqld_exporter-0.11.0.linux-amd64/.my.cnf
写入如下内容:
[client]
user=mysql_monitor
password= 123456
启动
[root@localhost ~]# cd /usr/local/mysqld_exporter-0.11.0.linux-amd64/
[root@localhost mysqld_exporter-0.11.0.linux-amd64]# ./mysqld_exporter --config.my-cnf=".my.cnf"   &

后台启动的“ & ” 一定要写,不然推出当前操作终端后就会自动关掉
再次刷新Prometheus时,页面被监控都为up
centos7下部署 Prometheus+Grafana超炫监控_第3张图片

10.安装grafana

下载:https://grafana.com/grafana/download
上传到运维主机

[root@localhost ~]# yum -y ×××tall /root/grafana-6.2.2-1.x86_64.rpm
下载饼状图插件,便于美化数据
[root@localhost ~]# grafana-cli plug××× ×××tall grafana-piechart-panel
启动grafana
[root@localhost ~]# systemctl restart grafana-server

11.登录grafana

默认端口3000,初始用户名和密码都为admin
http://192.168.0.66:3000
根据引导,登录后修改自己的密码
centos7下部署 Prometheus+Grafana超炫监控_第4张图片
centos7下部署 Prometheus+Grafana超炫监控_第5张图片
centos7下部署 Prometheus+Grafana超炫监控_第6张图片
centos7下部署 Prometheus+Grafana超炫监控_第7张图片
centos7下部署 Prometheus+Grafana超炫监控_第8张图片
如上图:find dashboards on grafana.com 里可以找到需要监控的模板,查到相应的模板id
import dashboard 可以导入相应的模板id,其中8919为主机模板,9777为MySQL模板
centos7下部署 Prometheus+Grafana超炫监控_第9张图片
点击load导入即可。
刷新到主页,效果如下
centos7下部署 Prometheus+Grafana超炫监控_第10张图片