以下是在 CentOS 上安装 Prometheus 的完整步骤,包括使用 Docker 和 Docker Compose 来简化部署,以及配置 Prometheus 和 Node Exporter 抓取指标。

  1. 安装 Docker 和 Docker Compose

    首先,您需要在 CentOS 上安装 Docker 和 Docker Compose。您可以使用以下命令来安装它们:

    sudo yum install docker docker-compose
    
  2. 创建 Prometheus 目录和配置文件

    创建一个名为 prometheus 的目录,并在其中创建 docker-compose.yml 文件:

    sudo mkdir /opt/prometheus
    sudo nano /opt/prometheus/docker-compose.yml
    
  3. 配置 docker-compose.yml 文件

    在 docker-compose.yml 文件中,添加以下内容:

    version: '3'
    services:
      prometheus:
        image: prom/prometheus
        volumes:
          - ./prometheus.yml:/etc/prometheus/prometheus.yml
        command:
          - '--config.file=/etc/prometheus/prometheus.yml'
          - '--storage.tsdb.path=/prometheus'
        ports:
          - '9090:9090'
    

    此配置文件将使用 Prometheus 的官方 Docker 镜像,并将其绑定到本地 prometheus.yml 文件。

  4. 创建 Prometheus 配置文件

    创建一个名为 prometheus.yml 的文件:

    sudo nano /opt/prometheus/prometheus.yml
    

    在 prometheus.yml 文件中添加以下内容:

    global:
      scrape_interval: 15s
    
    scrape_configs:
      - job_name: 'prometheus'
        static_configs:
          - targets: ['localhost:9090']
      - job_name: 'node_exporter'
        static_configs:
          - targets: ['localhost:9100']
    

    此配置文件定义了两个抓取配置:一个是用于 Prometheus 自身的,另一个是用于监视 Node Exporter 的。

  5. 启动 Prometheus

    使用以下命令启动 Prometheus:

    cd /opt/prometheus
    sudo docker-compose up -d
    

    这将启动 Prometheus 并使其在后台运行。

  6. 访问 Prometheus Web 界面

    现在,您可以使用浏览器访问 http://localhost:9090/ 来访问 Prometheus 的 Web 界面,并开始监视您的系统。

请注意,这只是一个基本的安装指南。您可能需要根据您的具体需求进行调整和配置。例如,您可能需要配置其他抓取目标,或者添加额外的指标。

CentOS 上安装 Prometheus 的完整指南

原文地址: https://www.cveoy.top/t/topic/nrCb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录