相關安裝包的下載
鏈接:https://pan.baidu.com/s/1ejM0V0f7H1Ikic_vpYGr_w
提取碼:axeq
安裝步驟
1、將安裝包放到部署機器上
2、解壓包 tar -zxvf prometheus-2.6.1.linux-amd64.tar.gz
3、移動並重命名到安裝目錄下 mv prometheus-2.6.1.linux-amd64.tar.gz /usr/local/prometheus
4、進入目錄下並修改配置文件prometheus.yml 添加監控機器
# my global config
global:
scrape_interval: 15s # 默認沒15s拉取一次數據點數據
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:
# - "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' static_configs: - targets: ['localhost:9090'] #監控本地及端口默認9090 - job_name: 'node_exporter_local' #通過node_exporter收集的數據 下面會有介紹 scrape_interval: 5s static_configs: - targets: ['192.168.2.35:9100']
5、啟動
./prometheus --config.file=prometheus.yml
注:第一次操作可能啟動報錯百分之99是yml文件 修改的問題

# 指定配置文件 --config.file="prometheus.yml" # 指定監聽地址端口 --web.listen-address="0.0.0.0:9090" # 最大連接數 --web.max-connections=512 # tsdb數據存儲的目錄,默認當前data/ --storage.tsdb.path="data/" # premetheus 存儲數據的時間,默認保存15天 --storage.tsdb.retention=15d
6、網頁訪問:http://localhost:9090
查看監控機器 up表示正常
查看數據采集情況
7、為了啟動和重啟方便 將prometheus 配置成服務
cd /usr/lib/systemd/system
vim prometheus.service
[Unit] Description=https://prometheus.io [Service] Restart=on-failure ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml [Install] WantedBy=multi-user.target
systemctl daemon-reload
8、啟動重啟
systemctl stop promethus.service
systemctl restart promethus.service
安裝 node-exporter 或 wmi_exporter-0.9.0-amd64
node-exporter 監控linux相關的系統下使用 默認端口9100
鏈接:https://pan.baidu.com/s/1CL5n05rnwAV8h1ArNJ2ofw
提取碼:410r
將node-exporter 放到/usr/bin 下 執行 nohup /usr/bin/exporter &
wmi_exporter-0.9.0-amd64 監控windows機器的使用 默認端口9082
鏈接:https://pan.baidu.com/s/1-7l6GUQ5-HNrJKR0mchVYA
提取碼:gou6
隨便目錄下 雙機執行即可
測試
http://監控機器ip:端口
參考資料:https://www.cnblogs.com/xiangsikai/p/11288801.html