MENU

Prometheus 的安装与简单使用

January 19, 2020 • 运维

创建 prometheus 用户:

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

下载并解压安装包:

wget https://github.com/prometheus/prometheus/releases/download/v2.15.2/prometheus-2.15.2.linux-amd64.tar.gz
tar -zxvf prometheus-2.15.2.linux-amd64.tar.gz
sudo mv prometheus-2.15.2.linux-amd64 /usr/prometheus

创建 data 目录:

cd /usr/local/prometheus
sudo mkdir data
sudo chown prometheus:prometheus -R .

创建管理脚本:

sudo vim /lib/systemd/system/prometheus.service

填入以下内容:

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

[Service]
User=prometheus
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus \
  --config.file=/usr/local/prometheus/prometheus.yml \
  --storage.tsdb.path=/usr/local/prometheus/data
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target

启动服务:

sudo systemctl start prometheus.service