从官方网站下载
Prometheus 提供了预编译的二进制文件,可以直接下载并安装。
-
访问 Prometheus 官方网站:
- 打开浏览器,访问 Prometheus 官方网站。
-
查找最新版本:
在官网上找到最新的 Prometheus 版本,点击对应的链接下载。
-
下载二进制文件:
根据你的操作系统(Linux、Windows 或 macOS)选择合适的二进制文件进行下载。
-
安装:
- 在目标目录下解压下载的二进制文件:
tar -xzf prometheus-*.tar.gz
- 运行安装脚本(安装路径可以自定义):
./install.sh
- 在目标目录下解压下载的二进制文件:
从 GitHub 克隆源代码
如果你需要自定义 Prometheus 或者开发它,可以从 GitHub 上克隆仓库。
-
访问 GitHub 仓库:
- 打开浏览器,访问 Prometheus GitHub 仓库。
-
克隆仓库:
- 使用 Git 克隆仓库:
git clone https://github.com/prometheus/prometheus.git
- 使用 Git 克隆仓库:
-
编译安装:
- 进入仓库目录:
cd prometheus
- 执行编译命令(需要安装 Go 语言):
make
- 安装命令:
make install
- 进入仓库目录:
使用 Docker 下载
如果你使用 Docker,可以直接拉取 Prometheus 镜像。
-
拉取镜像:
docker pull prom/prometheus:latest
或者特定版本:
docker pull prom/prometheus:{{ .Version }} -
运行 Prometheus:
docker run -d --name prometheus-prometheus prom/prometheus:latest
-d表示后台运行。--name指定容器名称。
使用 Helm 安装(Kubernetes 环境)
如果你使用 Kubernetes,可以使用 Helm 包装器安装 Prometheus。
-
安装 Helm: 如果尚未安装 Helm,可以先安装:
curl -fsSL -o get-helm-3 https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 get-helm-3
-
安装 Prometheus:
helm repo add prom https://kubernetes.github.io/prometheus helm repo update helm install prometheus prom/prometheus
验证安装
-
访问 Prometheus 网页:
- 启动 Prometheus 后,访问其默认端口 909:
curl http://localhost:909
- 应该会显示 Prometheus 的网页界面。
- 启动 Prometheus 后,访问其默认端口 909:
-
检查目标端口:
Prometheus 监控目标(如你的应用)是否可以被正确发现和监控。
配置 Prometheus(可选)
-
创建配置文件:
global: server: listen: '...:909' timezone: 'America/New_York' scrape_configs: - job: 'prometheus' scrape_interval: 15s static_configs: - targets: ['localhost:808'] -
重新启动 Prometheus:
systemctl restart prometheus
测试
-
访问 Prometheus 网页: 打开浏览器,访问
http://localhost:909。 -
检查目标状态: 点击“Targets”(监控目标)查看目标状态,确保所有目标都正常运行。
故障排除
-
依赖问题: 如果在编译源码时遇到依赖问题,确保安装了所有必要的依赖包,特别是 Go 语言和其相关工具。
-
配置错误: 如果配置错误,检查配置文件格式是否正确,确保所有指标和目标配置无误。
-
运行状态: Prometheus 未能正常运行,检查日志文件:
journalctl -u prometheus
通过以上步骤,你应该能够顺利下载并安装 Prometheus,并根据需要进行配置和使用。




