目錄
一、目標:
二、環境說明:
三、安裝步驟:
1. 配置ClickHouse集群對接Prometheus,
2. 安裝Prometheus,Prometheus 功能是負責收集各類系統的運行指標,
3. 安裝Grafana,Grafana 功能是負責指標資料可視化,
4. Grafana 集成 Prometheus,
一、目標:
1. Grafana 集成 Prometheus并實作對ClickHouse監控,
二、環境說明:
- 一臺CentOS7系統的虛擬機,主機名為 hadoop3,
- 已經安裝好的clickhouse集群,ClickHouse版本 21.6.6.51(說明:20.1.2.4以上版本的clickhouse已經集成了Prometheus),
- ClickHouse集群安裝方式可以參考文章基于CentOS7/Linux搭建ClickHouse集群
- Grafana版本:8.1.0 下載鏈接
- Prometheus版本:2.29.0 下載鏈接
- 安裝程序使用普通用戶權限,本文使用的用戶是 sspu ,
三、安裝步驟:
1. 配置ClickHouse集群對接Prometheus,
1.1. 將ClickHouse組態檔中 prometheus 標簽的注釋打開 (注意: ClickHouse 集群的各個節點的組態檔都要打開這個標簽),

1.2. 測驗ClickHouse 集群 prometheus 是否打開,
1.2.1. ClickHouse 集群服務重啟,如果修改組態檔前已經啟動 ClickHouse 集群,這里需要重啟服務,
1.2.2. 瀏覽器打開: http://hadoop3:9363/metrics ,看見如下內容說明服務正常,
2. 安裝Prometheus,Prometheus 功能是負責收集各類系統的運行指標,
2.1.官網下載Prometheus安裝包 prometheus-2.29.0-rc.2.linux-amd64.tar.gz

2.2.上傳 prometheus-2.29.0-rc.2.linux-amd64.tar.gz檔案到hadoop3機器的 /opt/module目錄,解壓并重命名
[sspu@hadoop3 ~]$ cd /opt/module
[sspu@hadoop3 module]$ tar -zxvf prometheus-2.29.0-rc.2.linux-amd64.tar.gz
[sspu@hadoop3 module]$ mv prometheus-2.29.0-rc.2.linux-amd64 ./prometheus-2.29.0

2.3. 編輯Prometheus組態檔prometheus.yml 檔案,
2.3.1. 添加 job_name等配置,這里要注意yml檔案格式,縮進和空格等,
[sspu@hadoop3 module]$ cd prometheus-2.29.0/
[sspu@hadoop3 prometheus-2.29.0]$ vim prometheus.yml

2.3.2. 完整的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).
# 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"]
#配置監控clickhouse
- job_name: 'clickhouse'
static_configs:
- targets: ['hadoop3:9363']
2.4.啟動 Prometheus Server
[sspu@hadoop3 prometheus-2.29.0]$ nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &
2.5.訪問 Prometheus 服務
2.5.1.瀏覽器輸入 http://hadoop3:9090/ ,點擊 Status 下拉框中的 Targets 選項,
2.5.2.點擊 Targets 選項后的界面如下圖,
2.5.3.目前 Prometheus 已經安裝配置完成,
3. 安裝Grafana,Grafana 功能是負責指標資料可視化,
3.1 官網 下載 Grafana 安裝包 grafana-8.1.0.linux-amd64.tar.gz
3.2. 上傳 grafana-8.1.0.linux-amd64.tar.gz 檔案到hadoop3機器的 /opt/module目錄,解壓并重命名,
[sspu@hadoop3 ~]$ cd /opt/module
[sspu@hadoop3 module]$ tar -zxvf grafana-8.1.0.linux-amd64.tar.gz
[sspu@hadoop3 module]$ mv grafana-8.1.0.linux-amd64 ./grafana-8.1.0
3.3. 啟動 Grafana 服務,
[sspu@hadoop3 module]$ cd grafana-8.1.0
[sspu@hadoop3 grafana-8.1.0]$ nohup ./bin/grafana-server web > ./grafana.log 2>&1 &
3.4. 打開 web: http://hadoop3:3000,默認用戶名和密碼都是: admin (注意:使用admin登錄會讓你修改密碼,如果不想修改可以skip掉)
![]() | ![]() |
3.5. 登錄后的界面大約如下圖:
4. Grafana 集成 Prometheus,
4.1. 添加資料源 Prometheus,
4.1.1. 最左側選單欄,依次點擊設定->Data Sources,
4.1.2. 點擊 Add Data Sources 按鈕,
4.1.3. 找到 Prometheus,點擊右邊 Select 按鈕 (注意:滑鼠懸停的位置,不然看不見 select 按鈕),
4.1.4. 配置 Prometheus Server 地址:http://hadoop3:9090 ,
4.1.5. 點擊下方(滾動條拉到最下面)的 Save&Test 按鈕,出現綠色的提示框,表示與 Prometheus 正常聯通,
![]() | ![]() |
4.1.6. 點擊 Back 回傳即可,可以看到 Data Sources 頁面,出現了添加的 Prometheus:
![]() | ![]() |
4.2. 配置Grafana監控ClickHouse的模板,
4.2.1. 在網站 https://grafana.com/dashboards 搜索 clickhouse,可以看到大量模板,
4.2.2. 選擇合適的模板,
4.2.2.1. 選擇有 internal exporter metrics 字樣的模板,這些模板是使用 clickhouse 內置的 Prometheus,
4.2.2.2. 同時要選擇最近時間維護的模板,有的模板長期沒有更新維護了,不要只看 start 數和 Downloades 數,
4.2.2.3. 我這里使用的模板是 'ClickHouse by weastur ' url:https://grafana.com/grafana/dashboards/14192
4.2.3. 下載模板檔案,點擊 Downloade JSON 按鈕,模板檔案是一個 .json 檔案,
4.2.4. 上傳模板檔案,
4.2.4.1. Grafana最左側選單欄,一次點擊 ‘+’ --> import --> Upload JSON File,
![]() | ![]() |
4.2.4.2. 選擇剛才下載的 JOSN 檔案,選擇資料源,點擊 Import ,
4.2.4.3. 出現如下界面,表示成功匯入模板,

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/294422.html
標籤:其他








