Prometheus 安裝部署
- 安裝版本:prometheus-2.6.1
- 百度雲下載:https://pan.baidu.com/s/1w16lQZKw8PCHqlRuSK2i7A
- 提取碼:lw1q
二進制安裝部署
1、下載二進制包:prometheus-2.6.1.linux-amd64.tar.gz
2、解壓包:tar xvzf prometheus-2.6.1.linux-amd64.tar.gz
3、移動到安裝目錄:mv prometheus-2.6.1.linux-amd64 /usr/local/prometheus
4、進入目錄:cd /usr/local/prometheus
5、修改配置文件底部監控本機:vim prometheus.yml
scrape_configs: - job_name: 'prometheus' static_configs: # 監控本地及端口 - targets: ['xiangsikai:9090']
注:Prometheus從目標機上通過http方式拉取采樣點數據, 它也可以拉取自身服務數據並監控自身的健康狀況。
注:當然Prometheus服務拉取自身服務采樣數據,並沒有多大的用處,但是它是一個好的DEMO。

global: # 默認情況下,每15s拉取一次目標采樣點數據。 scrape_interval: 15s # 我們可以附加一些指定標簽到采樣點度量標簽列表中, 用於和第三方系統進行通信, 包括:federation, remote storage, Alertmanager external_labels: # 下面就是拉取自身服務采樣點數據配置 monitor: 'codelab-monitor' scrape_configs: # job名稱會增加到拉取到的所有采樣點上,同時還有一個instance目標服務的host:port標簽也會增加到采樣點上 - job_name: 'prometheus' # 覆蓋global的采樣點,拉取時間間隔5s scrape_interval: 5s static_configs: - targets: ['localhost:9090']
6、啟動服務
./prometheus --config.file=prometheus.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
7、測試訪問:http://localhost:9090
8、查看暴露指標:http://localhost.com:9090/metrics
9、將Prometheus配置為系統服務
1、進入systemd目錄下:cd /usr/lib/systemd/system
2、創建文件: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
4、生效系統system文件
systemctl daemon-reload
5、啟動服務
systemctl stop prometheus.service
systemctl start prometheus.service
Docker 容器安裝部署
- 官方地址:https://prometheus.io/docs/prometheus/latest/installation/
一、prometheus.yml通過運行以下命令將您從主機綁定:
docker run -p 9090:9090 -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml \
prom/prometheus
二、或者為配置使用額外的卷:
docker run -p 9090:9090 -v /prometheus-data \
prom/prometheus --config.file=/prometheus-data/prometheus.yml
注:普羅米修斯的配置文件的需要指定對。