Prometheus 容器化部署,配合Grafan画图工具监控节点

本文介绍了如何将Prometheus进行容器化部署,并配合Grafana进行节点监控。首先,通过Docker拉取并运行Prometheus官方镜像,配置监控间隔和Alertmanager。接着,添加node_exporter到Prometheus配置中,监控目标节点。然后,部署Grafana并导入仪表板模板,展示监控数据。最后,配置Alertmanager进行邮件报警,确保监控系统的完整性和实用性。
摘要由CSDN通过智能技术生成

f2af7323bed8: Pull complete

c16675a6a294: Pull complete

827843f6afe6: Pull complete

3d272942eeaf: Pull complete

7e785cfa34da: Pull complete

05e324559e3b: Pull complete

170620261a59: Pull complete

ec35f5996032: Pull complete

5509173eb708: Pull complete

Digest: sha256:cb9817249c346d6cfadebe383ed3b3cd4c540f623db40c4ca00da2ada45259bb

Status: Downloaded newer image for prom/prometheus:latest

docker.io/prom/prometheus:latest

创建存放prometheus配置文件的目录,并提供默认配置文件

[root@prometheus ~]# mkdir -p /prometheus/config/

[root@prometheus ~]# vi /prometheus/config/prometheus.yml

[root@prometheus ~]# cat /prometheus/config/prometheus.yml

my global config

global:

scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.

evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.

scrape_timeout is set to the global default (10s).

Alertmanager configuration

alerting:

alertmanagers:

  • static_configs:

  • targets:

- alertmanager:9093

Load rules once and periodically evaluate them according to the global ‘evaluation_interval’.

rule_files:

- “first_rules.yml”

- “second_rules.yml”

A scrape configuration containing exactly one endpoint to scrape:

Here it’s Prometheus itself.

scrape_configs:

The job name is added as a label job=<job_name> to any timeseries scraped from this config.

  • job_name: “prometheus”

metrics_path defaults to ‘/metrics’

scheme defaults to ‘http’.

static_configs:

  • targets: [“localhost:9090”]

使用官方promethrus镜像创建容器

[root@prometheus ~]# docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

prom/prometheus latest a3d385fc29f9 11 days ago 201MB

[root@prometheus ~]# docker run --name prometheus -d --restart always -p 9090:9090 -v /prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml:ro prom/prometheus:latest

268b771e2b8ad9680cd33ab48d7789de1e0da8f28b37f59acfe1bb32ea0235f2

[root@prometheus ~]# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

268b771e2b8a prom/prometheus:latest “/bin/prometheus --c…” 7 seconds ago Up 5 seconds 0.0.0.0:9090->9090/tcp, :::9090->9090/tcp prometheus

//查看端口号

[root@prometheus ~]# ss -antl

State Recv-Q Send-Q Local Address:Port Peer Address:Port Process

LISTEN 0 128 0.0.0.0:9090 0.0.0.0:*

LISTEN 0 128 0.0.0.0:22 0.0.0.0:*

LISTEN 0 128 [::]:9090 [::]😗

LISTEN 0 128 [::]:22 [::]😗

使用本机IP地址192.168.129.205 + 端口号9090/targets在浏览器中访问

在这里插入图片描述

部署 node_exporter


准备工作

node_exporter-1.3.0.linux-amd64.tar.gz

//修改主机名

[root@localhost ~]# hostnamectl set-hostname node-exporter

[root@localhost ~]# bash

//关闭防火墙

[root@node-exporter ~]# systemctl disable --now firewalld.service

Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.

Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@node-exporter ~]# sed -i s/SELINUX=enforing/SELINUX=disabled/g /etc/selinux/config

[root@node-exporter ~]# setenforce 0

[root@node-exporter ~]# reboot

//下载安装包

[root@node-exporter ~]# cd /usr/src/

[root@node-exporter src]# wget https://github.com/prometheus/node_exporter/releases/download/v1.3.0/node_exporter-1.3.0.linux-amd64.tar.gz

[root@node-exporter src]# ls

debug kernels node_exporter-1.3.0.linux-amd64.tar.gz

//解压并重命名

[root@node-exporter src]# tar -xf node_exporter-1.3.0.linux-amd64.tar.gz -C /usr/local/

[root@node-exporter src]# mv /usr/local/node_exporter-1.3.0.linux-amd64/ /usr/local/node_exporter

[root@node-exporter src]# ls /usr/local/

bin etc games include lib lib64 libexec node_exporter sbin share src

//编写.service文件

[root@node-exporter ~]# cat > /usr/lib/systemd/system/node_exporter.service <<EOF

[unit]

Description=The node_exporter Server

After=network.target

[Service]

ExecStart=/usr/local/node_exporter/node_exporter

Restart=on-failure

RestartSec=15s

SyslogI

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值