如何在 Debian 11 上安装 Prometheus

Linux命令3年前 (2021)发布 AI观察员
172 0 0

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

如何在 Debian 11 上安装 Prometheus

Debian 11 Bullseye 上安装 Prometheus

步骤 1. 在我们安装任何软件之前,通过apt在终端中运行以下命令来确保您的系统是最新的很重要:

sudo apt update
sudo apt upgrade

步骤 2. 创建 Prometheus 用户。

我们将创建一个专用的 Prometheus 系统用户和组:

sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus

步骤 3. 在 Debian 11 上安装 Prometheus。

现在我们从官方页面下载 Prometheus 软件包安装程序:

mkdir -p /tmp/prometheus && cd /tmp/prometheus
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest|grep browser_download_url|grep linux-amd64|cut -d '"' -f 4|wget -qi -

然后,提取 Prometheus 包文件:

tar xvf prometheus*.tar.gz

文件提取后,我们将文件移动到正确的目录:

sudo mv prometheus.yml /etc/prometheus/prometheus.yml
sudo mv consoles/ console_libraries/ /etc/prometheus/

步骤 4. 配置 Prometheus。

默认情况下,Prometheus 配置文件将位于. 默认配置文件如下所示:/etc/prometheus/prometheus.yml

cat /etc/prometheus/prometheus.yml

输出:

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"# 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=` to any timeseries scraped from this config.
  - job_name: "prometheus"

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

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

步骤 5. 创建 Prometheus Systemd 服务

现在我们使用以下命令创建一个 Prometheussystemd服务文件:

nano /etc/systemd/system/prometheus.service

添加以下文件:

[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
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 \
  --web.listen-address=0.0.0.0:9090 \
  --web.external-url=

SyslogIdentifier=prometheus
Restart=always

[Install]
WantedBy=multi-user.target

保存并关闭文件,然后我们将更改其权限:

for i in rules rules.d files_sd; do sudo chown -R prometheus:prometheus /etc/prometheus/${i}; done
for i in rules rules.d files_sd; do sudo chmod -R 775 /etc/prometheus/${i}; done
sudo chown -R prometheus:prometheus /var/lib/prometheus/

接下来,重新加载systemd守护进程并启动服务:

sudo systemctl daemon-reload
sudo systemctl start prometheus
sudo systemctl enable prometheus

步骤 6. 访问 Prometheus Web 界面。

成功安装后,打开您喜欢的浏览器并导航至或并完成所需的步骤以完成安装。http://your-domain.com:9090http://your-ip-address:9090

如何在 Debian 11 上安装 Prometheus

感谢您使用本教程在 Debian 11 Bullseye 上安装最新版本的 Prometheus。如需其他帮助或有用信息,我们建议您查看Prometheus 官方网站

© 版权声明

相关文章

天猫U特购  京东优惠购        京东优惠    天猫优惠