官方參考文檔:https://prometheus.io/docs/prometheus/latest/getting_started/linux
firewall-cmd --zone=public --add-port=9090/tcp --permanent firewall-cmd --reload
mkdir /ssd/prometheus/ mkdir /sas/prometheus/ cd /sas/prometheus/ wget https://github.com/prometheus/prometheus/releases/download/v2.22.2/prometheus-2.22.2.linux-amd64.tar.gz tar -xvfz prometheus-2.22.2.linux-amd64.tar.gz mv prometheus-2.22.2.linux-amd64 prometheus cd prometheus
vi /sas/prometheus/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). # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels: monitor: 'devops-monitor01' # Alertmanager configuration alerting: alertmanagers: - static_configs: - targets: # - alertmanager:9093 # Load rules once and periodically evaluate them according to the global 'evaluation_interval'. 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'. # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s static_configs: - targets: ['10.255.200.1:9090','10.255.200.2:9090','10.255.200.3:9090']
vi /usr/lib/systemd/system/prometheus.service [Unit] Description=Prometheus Services After=network.target remote-fs.target [Service] Type=simple ExecStart=/sas/prometheus/prometheus/prometheus --config.file=/sas/prometheus/prometheus/prometheus.yml --storage.tsdb.path=/ssd/prometheus/ Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.target
systemctl daemon-reload systemctl start prometheus systemctl status prometheus systemctl enable prometheus
瀏覽器訪問:http://10.255.200.1:9090/targets 。可看到3個節點都正常上線,狀態爲:UP。git
瀏覽器訪問:http://10.255.200.1:9090/metrics 。可看到相應的監控數據。
github
使用瀏覽器打開:https://10.255.200.5:3000 , 在 「Configuration」 -> "Data Sources" 中添加prometheus數據源。時序數據庫類型(Time series databases)選 「Prometheus」,選中後填寫相應的名稱及URL,點測試並保存便可。數據庫