Prometheus安裝
在centos、ubuntu等系統上安裝步驟如下:
下載prometheus最新安裝包
# wget https://github.com/prometheus/prometheus/releases/download/v2.12.0/prometheus-2.12.0.linux-amd64.tar.gz
將下載好的安裝進行解壓
# tar xf prometheus-2.5.0.linux-amd64.tar.gz
將安裝文件中的執行文件放到/usr/local/bin/目錄下,方便命令可以直接執行(可選)
# cp prometheus-2.5.0.linux-amd64/{prometheus,promtool} /usr/local/bin/
指定prometheus配置文件路徑
# prometheus --config.file="/etc/prometheus/prometheus.yml"
使用promtool命令可以查看prometheus配置文件語法格式是否正確
# promtool check config /opt/prometheus-2.12.0.linux-amd64/prometheus.yml
通過docker安裝
# docker run -d -p 9090:9090 -v /tmp/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
Node exporter安裝
安裝Node exporter最新安裝包
# wget https://github.com/prometheus/node_exporter/releases/download/v0.18.1/node_exporter-0.18.1.linux-amd64.tar.gz
將下載的安裝包進行解壓
# tar -xf node_exporter-0.18.1.linux-amd64.tar.gz
進入到解壓后的安裝包,將執行命令cp到/usr/local/bin目錄下
# cp node_exporter /usr/local/bin/
Prometheus提供了幾個參數來修改本地存儲的配置,主要有:
| 啟動參數 | 默認值 | 含義 |
| --storage.tsdb.path | /data | 數據存儲路徑 |
| --storage.tsdb.retention.time | 15d | 樣本數據在存儲中保存的時間。超過該時間限制的數據就會被刪除。 |
| --storage.tsdb.retention.size | 0 | 每個塊的最大字節數(不包括 wal 文件)。如果超過限制,最早的樣本數據會被優先刪除。支持的單位有 KB, MB, GB, PB,例如:“512MB”。該參數只是試驗性的,可能會在未來的版本中被移除。 |
啟動服務方法
方法一:使用screen命令進行啟動
# screen 進入到prometheus或是node_exporter安裝目錄,將服務啟動起來
root@Prometheus:/opt/node_exporter-0.18.1.linux-amd64# screen -ls
There are screens on:
13286.pts-0.Prometheus (09/10/2019 09:52:46 AM) (Detached)
13129.pts-0.Prometheus (09/10/2019 09:50:09 AM) (Detached)
2 Sockets in /run/screen/S-root.
#在此進入程序后台,可以通過screen -r 13286,退出后台,ctrl+ad,退出后台並結束進程ctrl+d
方法二:使用daemonize方式
