1 Prometheus部署
1.1 Prometheus服务要求
- 建议Prometheus版本为2.2.1或更高版本(包括最新版本)。这是由于Prometheus在以前的版本中不稳定,以及缺少标志端点。
- 每个Prometheus实例都必须有一组全局唯一的标识标签。这些标签将被sidecar和Thanos在许多地方使用。
- 启用--web.enable-admin-api参数,以支持sidecar从Prometheus获取元数据,就像外部标签一样。
- 必须将--storage.tsdb.min-block-duration和--storage.tsdb.max-block-duration设置为相等的值,以禁用本地压缩,以便使用Thanos sidecar上传。建议默认为2小时。
1.2 128Prometheus搭建
1、配置文件
vim prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
region: jinan
replica: A
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["192.168.137.128:9090"]
- job_name: "node_exporter"
metrics_path: "/metrics"
static_configs:
- targets: ["192.168.137.128:9100"]
2、启动脚本
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus server
Documentation=https://prometheus.io/
[Service]
User=root
Restart=always
ExecStart=/app/module/prometheus/prometheus \
--config.file=/app/module/prometheus/prometheus.yml \
--storage.tsdb.path=/app/module/prometheus/data \
--storage.tsdb.retention.time=2h \
--storage.tsdb.min-block-duration=2h \
--storage.tsdb.max-block-duration=2h \
--web.listen-address=0.0.0.0:9090 \
--web.enable-admin-api \
--web.enable-lifecycle
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=20
TimeoutStopSec=20
SendSIGKILL=no
LimitNOFILE=8192
[Install]
WantedBy=multi-user.target
3、启动服务
systemctl daemon-reload
systemctl start prometheus.service
systemctl status -l prometheus.service
1.3 131Prometheus搭建
1、配置文件
vim prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
region: jinan
replica: B
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["192.168.137.131:9090"]
- job_name: "node_exporter"
metrics_path: "/metrics"
static_configs:
- targets: ["192.168.137.131:9100"]
2、启动脚本
vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=Prometheus server
Documentation=https://prometheus.io/
[Service]
User=root
Restart=always
ExecStart=/app/module/prometheus/prometheus \
--config.file=/app/module/prometheus/prometheus.yml \
--storage.tsdb.path=/app/module/prometheus/data \
--storage.tsdb.retention.time=2h \
--storage.tsdb.min-block-duration=2h \
--storage.tsdb.max-block-duration=2h \
--web.listen-address=0.0.0.0:9090 \
--web.enable-admin-api \
--web.enable-lifecycle
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=20
TimeoutStopSec=20
SendSIGKILL=no
LimitNOFILE=8192
[Install]
WantedBy=multi-user.target
4、启动服务
systemctl daemon-reload
systemctl start prometheus.service
systemctl status -l prometheus.service