二进制部署 Prometheus
下载 Prometheus https://prometheus.io/download/
安装 Prometheus
tar xvfz prometheus-3.8.1.linux-amd64.tar.gz
cd prometheus-3.8.1.linux-amd64
Prometheus 采集自身健康状态 prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "rules.yml"
# - "first_rules.yml"
# - "second_rules.yml"
# 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: "certs/ca.crt"
cert_file: "certs/client.crt"
key_file: "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 用户密码
apt install apache2-utils -y
htpasswd -nbBC 10 gin <password>
tls_server_config:
cert_file: certs/prom.crt
key_file: certs/key/prom.key
client_ca_file: <filename>
basic_auth_users:
gin: $2y$05$DrCuVd1F6oj69SxIXf3bk.ISRyGvu9wZbP.KtpjY659Nw8dkAZR9G
添加 node_exporter job prometheus.yml
- job_name: "node"
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:8081']
labels:
group: 'production'
添加 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 --web.listen-address="localhost:9090"
[Install]
WantedBy=multi-user.target
启动 Prometheus
systemctl daemon-reload
systemctl enable prometheus.service --now