如何在 Linux 上安装和配置 Prometheus? (Ubuntu 和 CentOS)

已发表: 2019-08-26

如何在 Linux 主机上设置和配置 Prometheus - Crunchify 技巧

什么是普罗米修斯?

Prometheus 是世界一流的监控系统,默认带有时间序列数据库。 它是最初于 2012 年构建的开源系统。

世界 500 强公司一直在使用 Prometheus 来收集其基础设施和应用程序的指标。 Prometheus 支持多维数据模型,时间序列数据主要标识为 Metrics。

没有特殊的数据存储要求,因为 Prometheus 在其自己的安装中使用了时序Time Series DB (TSDB) 部分。

在本教程中,我们将通过超级简单的步骤在 Linux Ubuntu 和 CentOS 上安装 Prometheus。

让我们开始吧:

Step-1 验证 Linux 操作系统版本

命令: cat /etc/os-release

以下步骤适用于Ubuntu Linux OS

Step-2 创建 Prometheus 数据和配置文件夹

命令

让我们验证两个文件夹:

Step-3 更改数据文件夹的所有权

这是避免后续步骤中的权限问题所必需的。

Step-4 创建 prometheus.yml 文件

转到文件夹/crunchify/prometheus/conf并创建文件prometheus.yml

prometheus.yml 文件内容:

Note:在上述文件中 - 将 IP 替换为您的主机/虚拟机 IP。

这是本教程的Directory structure

Linux 上的 Prometheus 设置 - 目录树结构

步骤 5 确保您已在 VM 上安装 Docker。

如何检查 Docker 是否安装?

这意味着 docker 未安装在您的主机/VM 上。 请完全按照 Docker 安装教程在您的主机/VM 上安装 Docker。

Step-6 安装 Docker Compose

Pre-requisite是在执行以下步骤之前先安装 Docker。 (第 5 步)

执行以下三个命令:

Step-7 验证 Docker Compose 版本

恭喜 - docker compose 已成功安装在您的 VM 上。

Step-8 创建 docker-compose.yml 文件

转到文件夹 /crunchify/prometheus。

docker-compose.yml 文件内容:

Step-9 安装 Prometheus Start/Stop 作为系统控制的一部分。

创建文件vi /etc/systemd/system/prometheus.service

prometheus.service 文件内容:

Step-10 启动 Prometheus 服务

Prometheus 服务器在 Linux 上启动:

Prometheus 服务器在 Linux Ubuntu 上启动

恭喜!! 您已在主机上成功启动 Prometheus。

让我们玩一下 Prometheus Dashboard 和 UI


如何验证 Prometheus 是否正常运行?

Prometheus 指标端点 - Crunchify 提示


如何使用 Prometheus 验证主机或虚拟机的 UP 状态?

如何使用 Prometheus 验证主机或虚拟机的 UP 状态?


如何在浏览器上查看 Prometheus 配置?

如何在浏览器上查看 Prometheus 配置


Prometheus 运行时信息

正常运行时间2019-08-26 03:07:24.244852166 +0000 UTC
工作目录/普罗米修斯
配置重新加载成功的
上次成功的配置重新加载2019-08-26 03:07:24 +0000 UTC
头块533
头部时间序列533
WAL 腐败0
协程36
GOMAXPROCS 1
GOGC
神虫
存储保留15天

普罗米修斯构建信息

版本2.12.0
修订43acd0e2e93f9f70c49b2267efa0124f1e759e86
分支
构建用户根@7a9dbdbe0cc7
建造日期20190818-13:53:16
版本去1.12.8

Prometheus 命令行标志:

alertmanager.notification-queue-容量10000
alertmanager.timeout 10s
配置文件/etc/prometheus/prometheus.yml
日志格式日志文件
日志级别信息
query.lookback-delta 5m
query.max-并发20
query.max-samples 50000000
查询超时2m
rules.alert.for-grace-period 10m
rules.alert.for-outage-tolerance 1小时
rules.alert.resend-delay 1m
storage.remote.flush-deadline 1m
storage.remote.read-concurrent-limit 10
storage.remote.read-sample-limit 50000000
storage.tsdb.allow-overlapping-blocks 错误的
storage.tsdb.max-block-duration 36小时
storage.tsdb.min-block-duration 2小时
storage.tsdb.no-lockfile 错误的
storage.tsdb.path /普罗米修斯
storage.tsdb.retention 0s
storage.tsdb.retention.size 0B
storage.tsdb.retention.time 0s
storage.tsdb.wal-压缩错误的
storage.tsdb.wal 段大小0B
web.console.libraries 控制台库
web.console.templates 控制台
web.cors.origin .*
web.enable-admin-api 错误的
web.enable-生命周期错误的
web.external-url
web.listen-address 0.0.0.0:9090
web.max-连接512
web.page-title Prometheus 时序采集和处理服务器
web.read-timeout 5m
web.route-前缀/

你都准备好了。 您已successfully installed Prometheus并验证了它的所有功能。