Prometheus监控+node_exporter组件+Grafana可视化界面

准备服务器:

服务器系统ip地址组件
Prometheus服务器CentOS 7.6172.16.200.74Prometheus、infuxdb
Grafana服务器CentOS 7.6172.16.200.79Grafana
Client服务器CentOS 7.6172.16.200.75node_exporter

所有服务器安装 ntpdate 工具,进行时间同步
yum -y install ntpdate
/usr/sbin/ntpdate ntp1.aliyun.com

一、安装Prometheus服务器

1.下载解压

# wget https://github.com/prometheus/prometheus/releases/download/v2.37.8/prometheus-2.37.8.linux-amd64.tar.gz

# tar xf prometheus-2.37.8.linux-amd64.tar.gz

2.配置安装

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

# useradd -s /sbin/nologin prometheus

# chown -R prometheus:prometheus /usr/local/prometheus/

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

[Unit]
Description=prometheus
After=network.target 

[Service]
User=prometheus
Group=prometheus
WorkingDirectory=/usr/local/prometheus
ExecStart=/usr/local/prometheus/prometheus
[Install]
WantedBy=multi-user.target


# systemctl daemon-reload

# systemctl enable --now prometheus

开启防火墙端口:

# firewall-cmd --add-port=9090/tcp --permanent

# firewall-cmd --reload

启动 Prometheus 后,访问 http://ip:9090 访问 Prometheus 自带的界面

3.存储配置

默认情况下 Prometheus 会将数据存储到本机的 /usr/local/prometheus/data 目录,数据大小受限、扩展不便;使用 influxdb 时序数据库作为数据库来存储数据。 

3.1下载安装

# wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.11.x86_64.rpm

# yum -y localinstall influxdb-1.7.11.x86_64.rpm

# cp /etc/influxdb/influxdb.conf /etc/influxdb/influxdb.conf.default

可修改[meta]、[data]存储位置

# vim /etc/influxdb/influxdb.conf

后台执行启动

# nohup influxd --config /etc/influxdb/influxdb.conf &

3.2验证创建数据库

# influx
Connected to http://localhost:8086 version 1.7.11
InfluxDB shell version: 1.7.11
> create database prometheus;
> show databases;
> exit 

 3.3配置 Prometheus 使用 infuxdb

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

在最后面添加:
remote_write:
  - url: "http://localhost:8086/api/v1/prom/write?db=prometheus"
remote_read:
  - url: "http://localhost:8086/api/v1/prom/read?db=prometheus"

重启服务:

# systemctl restart prometheus    

二、监控客户端服务器

1.监控服务器安装 Node_Exporter

# wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz

# tar xf node_exporter-1.5.0.linux-amd64.tar.gz

# mv node_exporter-1.5.0.linux-amd64 /usr/local/exporter/

# useradd -s /sbin/nologin prometheus

# chown -R prometheus:prometheus /usr/local/exporter/

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

[Unit]
Description=node_exporter
After=network.target 

[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/exporter/node_exporter \
          --web.listen-address=:20001 \
          --collector.systemd \
          --collector.systemd.unit-whitelist=(sshd|nginx).service \
          --collector.processes
[Install]
WantedBy=multi-user.target

# systemctl daemon-reload

# systemctl enable --now node_exporter

开放防火墙端口:

# firewall-cmd --add-port=20001/tcp --permanent

# firewall-cmd --reload

启动 node_exporter 服务后,访问 http://ip:20001/metrics,查看 Client 的监控指标。 

 2.修改 Promehtues 配置添加客户端地址

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

  - job_name: "Client"
    static_configs:
      - targets: ["192.168.0.2:20001"]

# systemctl restart prometheus

3.验证界面显示

 

三、Prometheus + Grafana 实现可视化界面
     在 Prometheus 中,我们可以使用 Web 界面进行数据的查询和展示,但是展示效果不是很好;安装 Grafana 来配合 Prometheus 使用。 

1.下载安装 Grafana

# wget https://dl.grafana.com/enterprise/release/grafana-enterprise-7.5.11-1.x86_64.rpm

# yum -y localinstall grafana-enterprise-7.5.11-1.x86_64.rpm

# systemctl enable --now grafana-server

开启防火墙端口:

# firewall-cmd --add-port=3000/tcp --permanent

# firewall-cmd --reload

2.配置 Grafana 的 Web 界面

http://ip:3000

默认账号密码都是 admin

登录后,要求修改密码,可以Skip跳过。

Add data source(添加数据源)

Save&Test

 Import(导入模板)

 

可视化界面展示 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值