如何在 AlmaLinux 8 上安装 Prometheus

Prometheus 是一个开源监控,具有维度数据模型、灵活的查询语言、高效的时序数据库和现代警报方法。prometheus-logo

在 AlmaLinux 8 上安装 Prometheus

第 1 步。首先,让我们首先确保您的系统是最新的。

sudo dnf clean all
sudo dnf update

步骤 2. 为 Prometheus 创建系统用户和组。

让我们创建一个专用的 Prometheus 用户。运行以下命令以创建 prometheus系统用户和组:

sudo adduser -M -r -s /sbin/nologin prometheus

接下来,创建一个新的配置目录’ ‘和数据目录’ ‘:/etc/prometheus/var/lib/prometheus

sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus

步骤 3. 在 AlmaLinux 8 上安装 Prometheus。

默认情况下,Prometheus 在 AlmaLinux 8 基础存储库中可用。现在我们运行以下命令在您的系统上下载最新版本的 Prometheus:

cd /usr/src
wget https://github.com/prometheus/prometheus/releases/download/v2.31.1/prometheus-2.31.1.linux-amd64.tar.gz

接下来,解压下载的文件:

tar -xf prometheus-2.31.1.linux-amd64.tar.gz

现在将环境变量“ PROM_SRC”设置到目录 ”:/usr/src/prometheus-*

export PROM_SRC=/usr/src/prometheus-*
sudo cp $PROM_SRC/prometheus.yml /etc/prometheus/

之后,将解压后的 Prometheus 归档目录下 的两个 Prometheus 二进制文件prometheus和 , 复制到该目录下:promtool/usr/local/bin

sudo cp $PROM_SRC/prometheus /usr/local/bin/
sudo cp $PROM_SRC/promtool /usr/local/bin/

步骤 4. 配置 Prometheus。

所有 Prometheus 配置都应该存在于文件中。使用 nano 编辑器打开文件:/etc/prometheus/prometheus.yml

nano /etc/prometheus/prometheus.yml

将目标从“ ”更改为服务器 IP 地址“ ”,如下所示:localhost:9090192.168.77.20:9090

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["192.168.77.20:9090"]

保存并关闭文件,然后在配置文件和目录上设置正确的所有权:

sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus

步骤 5. 创建 Prometheus Systemd 服务文件。

现在我们创建一个 Prometheussystemd服务文件。我们将使用此服务来管理服务的启动和停止:

sudo nano /etc/systemd/system/prometheus.service

添加以下文件:

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
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

保存并关闭文件,然后重新加载systemd服务以注册 Prometheus 服务并启动 Prometheus 服务:

sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
sudo systemctl status prometheus

步骤 6. 配置防火墙。

AlmaLinux 默认启用 Firewalld,它会阻止来自试图访问我们 Fastpanel 服务的其他计算机的其他连接。我们必须打开相应的端口,以便其他机器可以访问 Prometheus 资源:

sudo firewall-cmd --add-port=9090/tcp --permanent
sudo firewall-cmd --reload

步骤 7. 访问 Prometheus Web 界面。

成功安装后,打开 Web 浏览器并使用 URL 访问 Prometheus 。您将被重定向到以下页面:http://192.168.77.20:9090/

prometheus-web-interface

感谢您使用本教程在您的 AlmaLinux 8 系统上安装 Prometheus 监控系统工具。如需更多帮助或有用信息,我们建议您查看Prometheus 官方网站

未经允许不得转载:统信UOS之家 » 如何在 AlmaLinux 8 上安装 Prometheus

相关文章