Prometheus監控教程:安裝部署

一、安裝Prometheus Server

Prometheus基於Golang編寫,編譯後的軟件包,不依賴於任何的第三方依賴。用戶只需要下載對應平臺的二進制包,解壓並且添加基本的配置即可正常啓動Prometheus Server。

從二進制包安裝

對於非Docker用戶,可以從https://prometheus.io/download/找到最新版本的Prometheus Sevrer軟件包:

export VERSION=2.6.1
curl -LO https://github.com/prometheus/prometheus/releases/download/v$VERSION/prometheus-$VERSION.darwin-amd64.
tar.gz
將壓縮包進行解壓

tar -xzf prometheus-${VERSION}.darwin-amd64.tar.gz
mv prometheus-2.6.1.linux-amd64 prometheus-2.6.1
cd prometheus-2.6.1
解壓後當前目錄會包含默認的Prometheus配置文件promethes.yaml:


# 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).

# 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'.

static_configs:
- targets: ['localhost:9090']
Promtheus作爲一個時間序列數據庫,其採集的數據會以文件的形似存儲在本地中,默認的存儲路徑爲 data/ ,因此我們需要先手動創建該目錄:

mkdir -p data
用戶也可以通過參數--storage.tsdb.path="data/"修改本地數據存儲的路徑。

啓動prometheus服務,其會默認加載當前路徑下的prometheus.yaml文件:

./prometheus --config.file=prometheus.yaml
正常的情況下,你可以看到以下輸出內容:

level=info ts=2023-03-15T13:44:41.97916738Z caller=main.go:243 msg="Starting Prometheus" version="(version=2.6.1, branch=HEAD, revision=b639fe140c1f71b2cbad3fc322b17efe60839e7e)"
level=info ts=2023-03-15T13:44:41.979234185Z caller=main.go:244 build_context="(go=go1.11.4, user=root@4c0e286fe2b3, date=20190115-19:12:04)"
level=info ts=2023-03-15T13:44:41.979249082Z caller=main.go:245 host_details="(Linux 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 192.168.14.131 (none))"
level=info ts=2023-03-15T13:44:41.979264211Z caller=main.go:246 fd_limits="(soft=65536, hard=131072)"
level=info ts=2023-03-15T13:44:41.979275887Z caller=main.go:247 vm_limits="(soft=unlimited, hard=unlimited)"
level=info ts=2023-03-15T13:44:41.988649378Z caller=main.go:561 msg="Starting TSDB ..."
level=info ts=2023-03-15T13:44:41.999683641Z caller=main.go:571 msg="TSDB started"
level=info ts=2023-03-15T13:44:42.000153492Z caller=main.go:631 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2023-03-15T13:44:42.001185315Z caller=main.go:657 msg="Completed loading of configuration file" filename=prometheus.yml
level=info ts=2023-03-15T13:44:42.00120151Z caller=main.go:530 msg="Server is ready to receive web requests."
level=info ts=2023-03-15T13:44:42.001808404Z caller=web.go:429 component=web msg="Start listening for connections" address=0.0.0.0:9090
使用容器安裝

對於Docker用戶,直接使用Prometheus的鏡像即可啓動Prometheus Server:

docker run -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
啓動完成後,可以通過http://localhost:9090訪問Prometheus的UI界面:

使用容器安裝

對於Docker用戶,直接使用Prometheus的鏡像即可啓動Prometheus Server:

docker run -p 9090:9090 -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
啓動完成後,可以通過http://localhost:9090訪問Prometheus的UI界面:

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章