下载各组件,(选择安装)

wget https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz
wget https://github.com/prometheus/alertmanager/releases/download/v0.21.0/alertmanager-0.21.0.linux-amd64.tar.gz
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.17.0/blackbox_exporter-0.17.0.linux-amd64.tar.gz
wget https://github.com/prometheus/consul_exporter/releases/download/v0.7.1/consul_exporter-0.7.1.linux-amd64.tar.gz
wget https://github.com/prometheus/graphite_exporter/releases/download/v0.9.0/graphite_exporter-0.9.0.linux-amd64.tar.gz
wget https://github.com/prometheus/haproxy_exporter/releases/download/v0.11.0/haproxy_exporter-0.11.0.linux-amd64.tar.gz
wget https://github.com/prometheus/memcached_exporter/releases/download/v0.7.0/memcached_exporter-0.7.0.linux-amd64.tar.gz
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
wget https://github.com/prometheus/pushgateway/releases/download/v1.2.0/pushgateway-1.2.0.linux-amd64.tar.gz
wget https://github.com/prometheus/statsd_exporter/releases/download/v0.17.0/statsd_exporter-0.17.0.linux-amd64.tar.gz

安装prometheus组件

tar xf prometheus-2.20.1.linux-amd64.tar.gz

prometheus配置文件prometheus.yml

global:
  scrape_interval:     15s # 应用程序或服务抓取数据的周期,默认15s
  evaluation_interval: 15s # 估算规则的周期,默认1m

alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093

rule_files:
  # - "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'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

启动prometheus

cd prometheus-2.20.1.linux-amd64
# ./prometheus --config.file=prometheus.yml &

添加到systemd(注意替换相应目录)

[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target

[Service]
Type=simple
User=root
Restart=on-failure
ExecStart=/usr/local/prometheus-2.7.1.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.7.1.linux-amd64/prometheus.yml --storage.tsdb.path=/var/lib/prometheus
Restart=on-failure
[Install]
WantedBy=multi-user.target

查看metrics

http://192.168.112.58:9090/metrics

表达式浏览器

http://192.168.112.58:9090/graph

安装grafana

安装node_exporter

./node_exporter &  
# 默认监听端口9100,在路径`/metrics`暴露指标,也可以通过下面的参数来修改
    --web.listen-address=":9100"
    --web.telemetry-path="/node_metrics"

使用systemd管理

[Unit]
Description=node_exporter
Documentation=https://prometheus.io/docs/guides/node-exporter/
After=network.target
[Service]
Type=simple
User=root
ExecStart=/data/prometheus_exporter/node_exporter/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

--collector.textfile.directory=
--collector.systemd
--collector.systemd.unit-whitelist=