下载prometheus安装包
wget https://mirror.ghproxy.com/https://github.com/pr
ometheus/prometheus/releases/download/v2.49.1/prometheus-2.49.1.linux-amd6
4.tar.gz
解压prometheus到指定目录
tar xf prometheus-2.49.1.linux-amd64.tar.gz -C /usr/local/
ln -svf /usr/local/prometheus-2.49.1.linux-amd64/ /usr/local/prometheus
配置prometheus
cp /usr/local/prometheus/prometheus.yml /usr/local/prometheus/prometheus.yml_bak
vim /usr/local/prometheus/prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: "prometheus"
metrics_path: "/metrics"
static_configs:
- targets: ["10.0.0.100:9090"]
启动prometheus
/usr/local//prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml
配置system管理Prometheus启动和停止
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus server
Documentation=https://prometheus.io/
[Service]
User=root
Restart=always
ExecStart=/usr/local/prometheus/prometheus \
--config.file=/usr/local/prometheus/prometheus.yml \
--storage.tsdb.path=/usr/local/prometheus/data \
--storage.tsdb.retention.time=60d \
--web.enable-lifecycle
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=20
TimeoutStopSec=20
SendSIGKILL=no
LimitNOFILE=8192
[Install]
WantedBy=multi-user.target
--config.file=/usr/local/prometheus/prometheus.yml # 指定 Prometheus 的配置?件
路径。
--storage.tsdb.path=/usr/local/prometheus/data # 设置 Prometheus 存储时间序
列数据库(TSDB)的路径。 ?于存放Prometheus抓取到的指标数据。
--storage.tsdb.retention.time=60d # 配置 Prometheus 的数据保留
期限。超过这个时间范围的旧数据将被删除。这个可以根据存储资源和监控需求进?调整。
--web.enable-lifecycle # 允许通过 HTTP 请求的?式来更
新Prometheus的配置。
启动Prometheus服务
systemctl daemon-reload
systemctl start prometheus
验证