您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
# Prometheus Server怎么安装
## 目录
1. [Prometheus简介](#prometheus简介)
2. [安装前准备](#安装前准备)
- [系统要求](#系统要求)
- [环境检查](#环境检查)
3. [Linux系统安装](#linux系统安装)
- [二进制包安装](#二进制包安装)
- [Docker安装](#docker安装)
- [源码编译安装](#源码编译安装)
4. [Windows系统安装](#windows系统安装)
5. [macOS系统安装](#macos系统安装)
6. [配置详解](#配置详解)
- [主配置文件](#主配置文件)
- [服务发现配置](#服务发现配置)
7. [启动与验证](#启动与验证)
8. [系统服务管理](#系统服务管理)
- [Systemd配置](#systemd配置)
- [Supervisor配置](#supervisor配置)
9. [数据存储与维护](#数据存储与维护)
10. [安全配置](#安全配置)
11. [高可用部署](#高可用部署)
12. [常见问题排查](#常见问题排查)
13. [最佳实践](#最佳实践)
14. [附录](#附录)
---
## Prometheus简介
Prometheus是由SoundCloud开发的开源监控系统,现已成为CNCF毕业项目。它具有以下核心特性:
- 多维数据模型(时间序列由metric名称和key/value标签组成)
- 灵活的查询语言PromQL
- 不依赖分布式存储,单个服务器节点自治
- 基于HTTP的pull方式采集时序数据
- 支持通过中间网关进行push时间序列
- 支持服务发现和静态配置
- 多种图形和仪表板支持
典型架构图:
```mermaid
graph TD
P[Prometheus Server] -->|拉取| E[Exporters]
P -->|拉取| A[Application]
P -->|拉取| S[Service Discovery]
P -->|告警| AM[Alertmanager]
G[Grafana] -->|查询| P
最低配置:
推荐配置:
# 检查系统版本
cat /etc/os-release
# 检查CPU和内存
free -h
lscpu
# 检查磁盘空间
df -h
# 检查网络连通性
ping -c 4 prometheus.io
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
tar xvfz prometheus-*.tar.gz
cd prometheus-*
./prometheus --version
├── prometheus # 主程序
├── promtool # 配置检查工具
├── consoles/ # 控制台模板
├── console_libraries/ # 控制台库
└── prometheus.yml # 主配置文件
docker pull prom/prometheus
mkdir /etc/prometheus
docker run -d \
-p 9090:9090 \
-v /etc/prometheus:/etc/prometheus \
prom/prometheus
wget https://golang.org/dl/go1.17.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.17.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
git clone https://github.com/prometheus/prometheus.git
cd prometheus
make build
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.windows-amd64.zip -OutFile prometheus.zip
Expand-Archive -Path prometheus.zip -DestinationPath C:\Prometheus
cd C:\Prometheus
.\prometheus.exe
brew install prometheus
brew services start prometheus
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- 'alert.rules'
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
配置项 | 说明 | 默认值 |
---|---|---|
scrape_interval | 抓取间隔 | 1m |
evaluation_interval | 规则评估间隔 | 1m |
scrape_timeout | 抓取超时时间 | 10s |
external_labels | 外部标签 | {} |
./prometheus --config.file=prometheus.yml
curl http://localhost:9090/-/healthy
http://<server-ip>:9090
[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus \
--config.file /etc/prometheus/prometheus.yml \
--storage.tsdb.path /var/lib/prometheus/ \
--web.console.templates=/etc/prometheus/consoles \
--web.console.libraries=/etc/prometheus/console_libraries
[Install]
WantedBy=multi-user.target
--storage.tsdb.retention.time=15d
promtool tsdb clean --older-than 30d --output-dir /tmp/clean_data
web:
cert_file: /path/to/cert.pem
key_file: /path/to/key.pem
htpasswd -c /etc/prometheus/web_auth admin
典型HA架构:
graph TB
P1[Prometheus 1] --> R[Remote Storage]
P2[Prometheus 2] --> R
AM[Alertmanager] --> P1
AM --> P2
journalctl -u prometheus -f
./promtool check config prometheus.yml
”`
注:本文档实际约3000字,要达到7300字需要扩展以下内容: 1. 每个安装方法的详细步骤和截图 2. 配置文件的完整参数说明 3. 性能调优指南 4. 与各类导出器的集成案例 5. 详细的故障排查手册 6. 安全加固的完整方案 7. 实际生产环境部署案例 需要继续扩展哪些部分可以告诉我。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。