官方参考文档: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,点测试并保存便可。数据库