VM 虚拟机 构建 Prometheus + Thanos 环境 (1) - 基础架构 && Prometheus 安装


构建 Prometheus + Thanos 环境时,考虑到 Prometheus 原生开源版并未提供高可用性的支持,特别是在面对更大规模和高可用性要求的监控场景时。因此,引入 Thanos 成为一种选择。Prometheus 通常以单实例运行,适用于小到中等规模的监控需求,但在更大规模和高可用性要求下,Thanos 提供了解决方案,通过集中、查询汇聚多个 Prometheus 实例的数据,并支持长期数据存储,从而提高了整体可用性。

1 概述 && 架构

1.1 说明

为了实现整个 Prometheus 监控系统的统一查询入口,并将历史数据进行一致性存储,示例采用 Thanos 构建解决方案。该方案具备以下特点:

  1. 提供 Prometheus 的统一查询入口和历史数据的一致性保存。

  2. Thanos Querier 兼容 Prometheus 接口,使 Grafana 能够直接利用 Prometheus 数据源进行监控。

  3. Thanos 包含以下组件:

  • Sidecar:作为 Prometheus 收集器的代理,负责数据的中转和收集;
  • Querier:通过 Querier 可以聚合各个 Sidecar 的数据,实现统一的查询功能;
  • Store: 将收集回来的数据存储到对象存储或其他备份与归档类存储中;
  • Compactor: 负责对存储在对象存储中的数据进行压缩;
  • Ruler: 统一告警规则与阈值配置;

通过 Thanos + Prometheus 的部署,客户将构建一个分布式的查询和持久性存储功能的 Prometheus 监控系统。

1.2 基础架构图

2 环境部署

2.1 初始化配置

# 修改打开文件数
cat >> /etc/security/limits.conf << EOF
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535 
EOF

# 禁用 selinux && 禁用 firewalld
setenforce 0 && sed -i 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config && getenforce
systemctl disable firewalld && systemctl stop firewalld


# 停止 swap, fstab 关闭 swap 自启动 
swapoff -a
vim /etc/fstab

# 创建 Prometheus 用户
useradd -s /sbin/nologin prometheus

# 创建 Prometheus 存储目录
/data/prometheus

2.2 Prometheus 部署

2.2.1 下载 & 安装 Prometheus

# 下载 Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz

# 解压 Prometheus
tar xf prometheus-2.45.0.linux-amd64.tar.gz

# 移动到工具目录
mv prometheus-2.45.0.linux-amd64 /usr/local/prometheus

# 配置 Prometheus 权限

chown prometheus.prometheus -R /usr/local/prometheus/

chown prometheus.prometheus -R /data/prometheus

2.2.2 Prometheus 服务配置

# vim /etc/systemd/system/prometheus.service

[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus \
  --config.file=/usr/local/prometheus/prometheus.yml \
  --storage.tsdb.path=/data/prometheus \
  --storage.tsdb.min-block-duration=2h \
  --storage.tsdb.max-block-duration=2h \
  --web.enable-admin-api \
  --web.enable-lifecycle \

[Install]
WantedBy=multi-user.target

2.2.3 Prometheus 启动 && 开机启动

systemctl start prometheus.service
systemctl enable prometheus.service

3. 参考资料

Prometheus 安装包

Download | Prometheus

本系列将探讨 Thanos 的常用组件,介绍它们的功能和作用:

通过了解每个组件的应用机制和应用配置,为监控系统的构建和维护提供更有力的保证。

最近更新

  1. TCP协议是安全的吗?

    2024-01-29 08:44:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-29 08:44:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-29 08:44:01       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-29 08:44:01       20 阅读

热门阅读

  1. 关键点标注工具

    2024-01-29 08:44:01       28 阅读
  2. VUE computed和watch例子

    2024-01-29 08:44:01       31 阅读
  3. [EFI]戴尔T5810电脑 Hackintosh 黑苹果efi引导文件

    2024-01-29 08:44:01       36 阅读
  4. 非root运行docker容器

    2024-01-29 08:44:01       41 阅读