centos7.8如何安裝prometheus和grafana

小編給大家分享一下centos7.8如何安裝prometheus和grafana,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供南川網(wǎng)站建設、南川做網(wǎng)站、南川網(wǎng)站設計、南川網(wǎng)站制作等企業(yè)網(wǎng)站建設、網(wǎng)頁設計與制作、南川企業(yè)網(wǎng)站模板建站服務,十載南川做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡服務。

安裝準備

  • 虛擬機:centos7.8 2臺

本實踐中以 2臺已安裝centos7.8的虛機作為實踐環(huán)境安裝prometheus2.8.1和grafana,并在prometheus中配置對這2臺主機的監(jiān)控。

具體安裝規(guī)劃如下:

hostname

ip

os

cpu

memory

disk

備注

prometheus-host

172.22.3.148

centos7.8

2c

2g

20g

prometheus
grafana
node_exporter

prometheus-node

172.22.3.149

centos7.8

2c

2g

20g

node_exporter

  • 相關安裝文件

https://github.com/prometheus/prometheus/releases/download/v2.24.0/prometheus-2.24.0.linux-amd64.tar.gz
https://dl.grafana.com/oss/release/grafana-7.3.6-1.x86_64.rpm
https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz

備注:如無說明,以下部署均在prometheus-host部署

安裝prometheus

  • 下載

# cd /opt
# wget https://github.com/prometheus/prometheus/releases/download/v2.8.1/prometheus-2.8.1.linux-amd64.tar.gz
  • 安裝

# cd /opt
# tar -zxf prometheus-2.8.1.linux-amd64.tar.gz
# mv prometheus-2.8.1.linux-amd64 prometheus
  • 啟動

# cd /opt/prometheus
# ./prometheus
  • 創(chuàng)建service并設置自動啟動

## 創(chuàng)建service
# vi /usr/lib/systemd/system/prometheus.service
[Unit]
Description=prometheus
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/opt/prometheus/prometheus --config.file=/opt/prometheus/prometheus.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target

# systemctl daemon-reload
## 設置自啟動
# systemctl enable prometheus
Created symlink from /etc/systemd/system/multi-user.target.wants/prometheus.service to /usr/lib/systemd/system/prometheus.service.
## 啟動服務
# systemctl start prometheus
  • 訪問prometheus

瀏覽器地址欄輸入 http://172.22.3.148:9090

centos7.8如何安裝prometheus和grafana

安裝grafana

  • 下載

# cd /opt
# wget https://dl.grafana.com/oss/release/grafana-7.3.6-1.x86_64.rpm
  • 安裝

# cd /opt
# yum install grafana-7.3.6-1.x86_64.rpm
  • 啟動

## 安裝完成后會自動生成grafana-server的service
systemctl daemon-reload
systemctl start grafana-server
  • 設置自動啟動

## 設置自啟動
# systemctl enable grafana-server
  • 訪問grafana并配置默認數(shù)據(jù)源

瀏覽器地址欄輸入 http://172.22.3.148:3000

centos7.8如何安裝prometheus和grafana

使用默認用戶名密碼 admin/admin登錄

centos7.8如何安裝prometheus和grafana

首次登錄后需要設置新密碼如上。

granfa安裝后需要配置數(shù)據(jù)源

centos7.8如何安裝prometheus和grafana

選擇Prometheus,點擊Select

centos7.8如何安裝prometheus和grafana

只需要設置URL為http://localhost:9090

centos7.8如何安裝prometheus和grafana

其它保持默認,直接點“Save & Test”按鈕即可

centos7.8如何安裝prometheus和grafana

彈出保存成功提示,點“Back”按鈕返回。

centos7.8如何安裝prometheus和grafana

可以看到grafana已經(jīng)保存了一個數(shù)據(jù)源。

安裝node_exporter并用prometheus配置主機監(jiān)控

  • 下載

# cd /usr/local
# wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
  • 安裝

# cd /usr/local
# tar -zxf node_exporter-1.0.1.linux-amd64.tar.gz
# mv node_exporter-1.0.1.linux-amd64/node_exporter ./bin/
  • 創(chuàng)建service并設置自動啟動

## 創(chuàng)建service
# vi /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io/
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

# systemctl daemon-reload
## 設置自啟動
# systemctl enable node_exporter
Created symlink from /etc/systemd/system/multi-user.target.wants/node_exporter.service to /usr/lib/systemd/system/node_exporter.service.
## 啟動服務
# systemctl start node_exporter
  • 在prometheus中配置對主機prometheus-host監(jiān)控

修改prometheus配置文件prometheus.yml,在scrape_configs下增加如下配置

- job_name: 'prometheus-host'
    file_sd_configs:
      - files: ['/opt/prometheus/sd_config/prometheus-host.yml']
        refresh_interval: 5s

新增/opt/prometheus/sd_config/prometheus-host.yml文件,內(nèi)容如下

cat /opt/prometheus/sd_config/prometheus-host.yml
- targets:
  - 172.22.3.149:9100

備注:每次修改配置完成,用promtool檢測配置文件是否正確

# /opt/prometheus/promtool check config /opt/prometheus/prometheus.yml

重啟prometheus

# systemctl restart prometheus

瀏覽器地址欄輸入 http://172.22.3.148:9090/targets

centos7.8如何安裝prometheus和grafana

可以看到targets已經(jīng)增加了對主機prometheus-host的監(jiān)控

  • 在grafana中配置面板顯示對主機prometheus-host監(jiān)控內(nèi)容

centos7.8如何安裝prometheus和grafana

點“+”按鈕,彈出導入面板窗口

centos7.8如何安裝prometheus和grafana

如圖輸入8919,點Load,grafana會直接從官方網(wǎng)站導入編號為8919的面板如下

centos7.8如何安裝prometheus和grafana

選擇數(shù)據(jù)源Prometheus,繼續(xù)“Import”,顯示node監(jiān)控界面顯示如下

centos7.8如何安裝prometheus和grafana

在prometheus-nodes安裝node_exporter并用prometheus配置主機監(jiān)控

  • 安裝步驟參考在prometheus-host安裝node_exporter步驟

  • 在prometheus中配置對主機prometheus-nodes監(jiān)控

修改prometheus配置文件prometheus.yml,在scrape_configs下增加如下配置

  - job_name: 'prometheus-nodes'
    file_sd_configs:
      - files: ['/opt/prometheus/sd_config/prometheus-nodes.yml']
        refresh_interval: 5s

新增/opt/prometheus/sd_config/prometheus-nodes.yml文件,內(nèi)容如下

cat /opt/prometheus/sd_config/prometheus-nodes.yml
- targets:
  - 172.22.3.148:9100

重啟prometheus

# systemctl restart prometheus

瀏覽器地址欄輸入 http://172.22.3.148:9090/targets

centos7.8如何安裝prometheus和grafana

可以看到targets已經(jīng)增加了對主機prometheus-nodes的監(jiān)控

訪問grafana,也可以看到node監(jiān)控界面多了prometheus-nodes的顯示

centos7.8如何安裝prometheus和grafana

以上是“centos7.8如何安裝prometheus和grafana”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

分享題目:centos7.8如何安裝prometheus和grafana
轉載源于:http://bm7419.com/article26/psoijg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供Google、網(wǎng)站建設、動態(tài)網(wǎng)站、虛擬主機、定制開發(fā)、網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站優(yōu)化排名