1. 部署Prometheus
1.1 下载
bash
#下载lts稳定版本
wget https://github.com/prometheus/prometheus/releases/download/v2.53.3/prometheus-2.53.3.linux-amd64.tar.gz
#下载lts稳定版本
wget https://github.com/prometheus/prometheus/releases/download/v2.53.3/prometheus-2.53.3.linux-amd64.tar.gz
1.2 创建用户
bash
#创建用户
useradd -rs /bin/false prometheus
#创建目录
mkdir /data/apps/prometheus
#解压
tar -xf prometheus-2.53.3.linux-amd64.tar.gz --strip-components=1 -C /data/apps/prometheus/
#修改权限
chown -R prometheus. /data/apps/prometheus
#创建用户
useradd -rs /bin/false prometheus
#创建目录
mkdir /data/apps/prometheus
#解压
tar -xf prometheus-2.53.3.linux-amd64.tar.gz --strip-components=1 -C /data/apps/prometheus/
#修改权限
chown -R prometheus. /data/apps/prometheus
1.3 配置systemd
bash
cat > /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus Time Series Collection and Processing Server
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/data/apps/prometheus/prometheus \
--config.file /data/apps/prometheus/prometheus.yml \
--storage.tsdb.path /data/apps/prometheus/ \
--web.console.templates=/data/apps/prometheus/consoles \
--web.console.libraries=/data/apps/prometheus/console_libraries \
--web.enable-lifecycle \
--storage.tsdb.retention.time=10d \
--storage.tsdb.no-lockfile \
--storage.tsdb.min-block-duration=2h \
--storage.tsdb.max-block-duration=2h
[Install]
WantedBy=multi-user.target
EOF
cat > /etc/systemd/system/prometheus.service <<EOF
[Unit]
Description=Prometheus Time Series Collection and Processing Server
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/data/apps/prometheus/prometheus \
--config.file /data/apps/prometheus/prometheus.yml \
--storage.tsdb.path /data/apps/prometheus/ \
--web.console.templates=/data/apps/prometheus/consoles \
--web.console.libraries=/data/apps/prometheus/console_libraries \
--web.enable-lifecycle \
--storage.tsdb.retention.time=10d \
--storage.tsdb.no-lockfile \
--storage.tsdb.min-block-duration=2h \
--storage.tsdb.max-block-duration=2h
[Install]
WantedBy=multi-user.target
EOF
- 启动
bash
systemctl daemon-reload
systemctl enable --now prometheus
systemctl daemon-reload
systemctl enable --now prometheus
- 效果