prometheus+Grafana部署

CentOS7 下部署Prometheus+Grafana+node_exporter+blackbox_exporter监控

image.png

一、环境

监控端(192.168.20.13)安装:Prometheus+Grafana

被监控端(39.96.187.128)安装:node_exporter+blackbox_exporter

二、软件包下载

https://prometheus.io/download/

(统一下载到 /soft)

node_exporter下载:

Wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz

prometheus下载:

Wget https://github.com/prometheus/prometheus/releases/download/v2.14.0/prometheus-2.14.0.linux-amd64.tar.gz

blackbox_exporter下载:

Wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/blackbox_exporter-0.16.0.linux-amd64.tar.gz

grafana下载:

 https://dl.grafana.com/oss/release/grafana-6.5.1-1.x86_64.rpm

三、Prometheus安装及配置

1、解压安装包

mkdir -p / software/prometheus

groupadd prometheus

useradd -g prometheus prometheus -d /software/Prometheus

tar -zxvf prometheus-2.14.0.linux-amd64.tar.gz

cd prometheus-2.14.0.linux-amd64/

mv * /software/prometheus/

cd /software/prometheus/

mkdir {data,cfg,logs,bin} -p

mv prometheus promtool bin/

mv prometheus.yml cfg/

chown -R prometheus.prometheus *

2、设置环境变量

vim /etc/profile

PATH=/software/prometheus/bin:$PATH:$HOME/bin

3、使变量生效

source /etc/profile

4、创建prometheus.service 的 systemd unit 文件

vim /etc/systemd/system/prometheus.service

内容:

[Unit]

Description=Prometheus

Documentation=https://prometheus.io/

After=network.target

[Service]

Type=simple

User=prometheus

ExecStart=/software/prometheus/bin/prometheus --config.file=/software/prometheus/cfg/prometheus.yml --storage.tsdb.path=/software/prometheus/data

Restart=on-failure

[Install]

WantedBy=multi-user.target

5、prometheus.yml配置文件

image.png

image.png

6、启动服务

systemctl daemon-reload
systemctl enable prometheus.service
systemctl start prometheus.service

7、运行状态

image.png

Prometheus自带有简单的UI, http://192.168.20.13:9090/targets

四、node_exporter安装及配置

1、解压安装包
mkdir -p /software
mkdir -p /software/prometheus
cd /soft
tar -zxvf node_exporter-0.18.1.linux-amd64.tar.gz -C /software/prometheus/
cd /software/prometheus/
mv node_exporter-0.18.1.linux-amd64 node_exporter
2、创建用户
groupadd prometheus
useradd -g prometheus prometheus -d /software/prometheus
chown -R prometheus.prometheus node_exporter
3、创建node_exporter.service的 systemd unit 文件
vim /usr/lib/systemd/system/node_exporter.service
内容:
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=prometheus
ExecStart=/software/prometheus/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target
4、启动服务
systemctl daemon-reload
systemctl enable node_exporter.service
systemctl start node_exporter.service

5、运行状态


image.png

image.png

6、客户监控端数据汇报
访问: http://192.168.20.13:9100/metrics,查看从exporter具体能抓到的数据.如下 :

image.png

访问: http://192.168.20.196:9100/metrics,查看从exporter具体能抓到的数据.如下 :
image.png

五、blackbox_exporter安装及配置

1、安装
cd /software
tar -zxvf blackbox_exporter-0.16.0.linux-amd64.tar.gz -C /software/prometheus/
cd /software/prometheus/
mv blackbox_exporter-0.16.0.linux-amd64 blackbox_exporter
2、创建用户
chown -R prometheus.prometheus blackbox_exporter
3、验证安装是否成功
cd /software/Prometheus/blackbox_exporter
./blackbox_exporter --version
![image.png](https://upload-images.jianshu.io/upload_images/26078328-e32be51c15b16633.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

4、创建systemd服务

vim /usr/lib/systemd/system/blackbox_exporter.service

内容:

Description=blackbox_exporter

Documentation=https://prometheus.io/

After=network.target

 Type=simple

User=prometheus

ExecStart=/software/prometheus/blackbox_exporter/blackbox_exporter --config.file=/software/prometheus/blackbox_exporter/blackbox.yml

Restart=on-failure

[Install]

WantedBy=multi-user.target

5、启动服务

systemctl daemon-reload

systemctl enable blackbox_exporter.service

systemctl start blackbox_exporter.service

六、Grafana安装及配置

1、安装

yum localinstall grafana-6.5.1-1.x86_64.rpm

2、启动服务

systemctl daemon-reload

systemctl enable grafana-server.service

systemctl start grafana-server.service

3、访问WEB界面

默认账号/密码:admin/admin

http://192.168.20.13:3000

①add data source


image.png

②填写信息,点击“save&test”,如果成功,会有绿色的提示


image.png

③创建dashboard
image.png

③创建dashboard


image.png

④导入json文件
image.png

image.png

实现可视化我们可以直接使用现成的模板
硬件监控:1-node-exporter-for-prometheus-dashboard-update-1102_rev11.json
进程监控:2 Blackbox Exporter 0.14 for Prometheus 监控展示看板-1575517197953.json
七、关于Prometheus的配置文件

1、注意事项
①严格按照格式进行缩进,否则将导致配置文件无效。
②job_name不能重复,否则将导致Prometheus启动不了。
2、node_exporter部分的格式
例子:

  • job_name: 'node_39.96.187.128'
    static_configs:
    • targets: ['39.96.187.128:9100']
      labels:
      instance: '39.96.187.128'

效果:


image.png

3、blackbox_exporter部分的格式
例子:

  • job_name: "blackbox_39.96.187.128"
    scrape_interval: 5s
    metrics_path: /probe
    params:
    module: [tcp_connect]
    static_configs:
    - targets: ['39.96.187.128:9115','39.96.187.128:9100','39.96.187.128:9948','39.96.187.128:9941','39.96.187.128:9951','39.96.187.128:9954','39.96.187.128:9956','39.96.187.128:9936','39.96.187.128:9952','39.96.187.128:9944','39.96.187.128:9942','39.96.187.128:9947','39.96.187.128:9947','39.96.187.128:9966','39.96.187.128:9909','39.96.187.128:8901','39.96.187.128:7777']
    labels:
    group: '进程监控'
    relabel_configs:
    - source_labels: [address]
    target_label: __param_target
    - source_labels: [__param_target]
    target_label: instance
    - target_label: address
    replacement: 39.96.187.128:9115

效果:


image.png

你可能感兴趣的:(prometheus+Grafana部署)