二进制部署 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'
scrape_configs:
- 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'
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: <filename>
key_file: <filename>
client_auth_type: RequireAndVerifyClientCert
client_ca_file: <filename>
client_allowed_sans:
- "example.com"
- "192.168.1.1"
- "[email protected]"
- "https://example.com/uri"
min_versio: TLS12
max_version: TLS13
http_server_config:
headers:
basic_auth_users:
gin: <secret>
启动 Prometheus
./prometheus --config.file=prometheus.yml --web.config.file=web-config.yml --web.external-url=https://example.com/listen-address="localhost:9090"
添加 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 --web.external-url=https://example.com/listen-address="localhost:9090"
[Install]
WantedBy=multi-user.target