二进制部署 Prometheus
安装 Prometheus
tar xvfz prometheus-*.tar.gz
cd prometheus-*
Prometheus 采集自身健康状态 prometheus.yml
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# 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=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
scheme: "https"
tls_config:
ca_file: "/data/prometheus-2.53.1.linux-amd64/certs/ca.crt"
cert_file: "/data/prometheus-2.53.1.linux-amd64/certs/client.crt"
key_file: "/data/prometheus-2.53.1.linux-amd64/certs/key/client.key"
insecure_skip_verify: true
basic_auth:
username: 'gin'
password: 'QWE123qwe'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
编辑 web-config.yml 文件启用 https 和 登录认证
Bcrypt 加密 gin 用户密码
htpasswd -nB gin
tls_server_config:
cert_file: /data/prometheus-2.53.1.linux-amd64/certs/prom.crt
key_file: /data/prometheus-2.53.1.linux-amd64/certs/key/prom.key
basic_auth_users:
gin: $2y$05$DrCuVd1F6oj69SxIXf3bk.ISRyGvu9wZbP.KtpjY659Nw8dkAZR9G
启动 Prometheus
./prometheus --config.file=prometheus.yml --web.config.file=web-config.yml
安装 node-exporter
tar xvfz node_exporter-1.8.2.linux-amd64.tar.gz
cd node_exporter-1.8.2.linux-amd64
./node_exporter
启动 node-exporter
./node_exporter --web.listen-address 127.0.0.1:8081
./node_exporter --web.listen-address 127.0.0.1:8082
./node_exporter --web.listen-address 127.0.0.1:8083
添加 node_exporter job prometheus.yml
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'node'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:8080', 'localhost:8081']
labels:
group: 'production'
- targets: ['localhost:8082']
labels:
group: 'canary'
添加 Grafana job prometheus.yml
- job_name: 'grafana_metrics'
scrape_interval: 15s
scrape_timeout: 5s
scheme: "https"
tls_config:
ca_file: "certs/ca.crt"
cert_file: "certs/client.crt"
key_file: "certs/key/client.key"
insecure_skip_verify: true
static_configs:
- targets: ['localhost:3000']
basic_auth:
username: 'admin'
password: 'password'
配置 frp job 修改prometheus.yml 文件
- job_name: "frp"
scheme: "https"
tls_config:
ca_file: "certs/ca.crt"
cert_file: "certs/client.crt"
key_file: "certs/key/client.key"
insecure_skip_verify: true
static_configs:
- targets: ['localhost:8088']
basic_auth:
username: 'admin'
password: 'password'
编辑 prometheus.service 服务文件
[Unit]
[Service]
WorkingDirectory=/usr/local/prometheus
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.config.file=/usr/local/prometheus/web-config.yml
[Install]
WantedBy=multi-user.target