ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

prometheus部署安装

prometheus部署安装 一、环境确认同一服务器必备1. 环境准备在开始之前请确保你的服务器满足以下基本要求- 操作系统LinuxUbuntu 20.04/CentOS 7- 开放端口9090Prometheus 默认端口- 权限拥有 root 或 sudo 权限- 无需额外依赖二进制包含完整运行文件Docker 需提前安装二、方式一二进制文件安装 推荐用于生产环境这种方式让你对 Prometheus 的配置和运行有最大的控制权。步骤 1: 创建 Prometheus 用户和组为了安全建议使用一个非 root 用户来运行 Prometheus。sudogroupadd--systemprometheussudouseradd--system--gidprometheus --no-create-home--shell/bin/false prometheussudomkdir-p/etc/prometheus /var/lib/prometheussudochown-Rprometheus:prometheus /etc/prometheus /var/lib/prometheus2. 下载并安装二进制文件# 替换为官网最新版本https://prometheus.io/download/cd/tmpwgethttps://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gztar-xzfprometheus-2.45.0.linux-amd64.tar.gzsudocpprometheus-2.45.0.linux-amd64/{prometheus,promtool}/usr/local/bin/sudocp-rprometheus-2.45.0.linux-amd64/consoles prometheus-2.45.0.linux-amd64/console_libraries /etc/prometheus/3. 配置并启动服务# 写入基础配置监控自身sudotee/etc/prometheus/prometheus.ymlEOF global: scrape_interval: 15s scrape_configs: - job_name: prometheus static_configs: - targets: [localhost:9090] EOF# 创建系统服务sudotee/etc/systemd/system/prometheus.serviceEOF [Unit] DescriptionPrometheus Wantsnetwork-online.target Afternetwork-online.target [Service] Userprometheus Groupprometheus Typesimple ExecStart/usr/local/bin/prometheus --config.file/etc/prometheus/prometheus.yml --storage.tsdb.path/var/lib/prometheus [Install] WantedBymulti-user.target EOF# 启动并设置开机自启sudosystemctl daemon-reloadsudosystemctl start prometheussudosystemctlenableprometheus4. 验证访问 http://服务器IP:9090能看到 Prometheus 界面即部署成功。三、方式二Docker 安装快速部署适合测试 / 轻量场景步骤 1: 安装宝塔面板步骤 2: 在宝塔面板中安装docker模块步骤 3:在docker模块中应用商店中搜索prometheus选择合适版本并进行安装步骤 4: prometheus安装完成后步骤 5: 访问网址路径http://IP地址:9090即可完成prometheus的docker部署。
返回列表