主頁 >  其他 > Centos8搭建服務監控prometheus+node_export+grafana

Centos8搭建服務監控prometheus+node_export+grafana

2020-12-10 13:20:05 其他

Centos8搭建服務監控prometheus+node_export+grafana

  • 簡單介紹
    • prometheus
      • 什么是prometheus?
      • prometheus的特點
      • 基本原理
      • 服務程序
      • 三大套件
    • Grafana
      • 什么是Grafana
      • Grafana的特點
    • node_export
      • node_export是什么
  • 搭建程序
    • prometheus的安裝使用
      • 用戶和組
      • 創建目錄
      • 下載
      • 解壓
      • 為prometheus創建組態檔目錄和存放資料目錄并賦權限
      • 將prometheus組態檔拷貝到/etc/prometheus目錄下
      • 將prometheus下二進制檔案拷貝到/usr/local/bin目錄下
      • 修改組態檔
      • 啟動prometheus
      • 防火墻配置
      • 將prometheus加入systemctl管理
        • 創建prometheus.service服務檔案
        • 重新加載服務串列
        • 啟動服務
      • 將prometheus設定為開機自啟動
    • node_exporter的安裝和使用
      • 用戶和組
      • 創建目錄
      • 下載
      • 解壓
      • 將node_exporter下二進制檔案拷貝到/usr/local/bin目錄下并設定權限
      • 啟動
      • 將node_exporter加入systemctl管理
        • 創建node_exporter.service服務檔案
        • 重新加載服務串列
        • 啟動服務
      • 將node_exporter設定為開機自啟動
      • 加入prometheus監控
    • Grafana的安裝使用
      • 用戶和組
      • 創建目錄
      • 下載
      • 解壓
      • 將grafana下二進制檔案拷貝到/usr/local/bin目錄下并設定權限
      • 配置grafana
        • 拷貝ini組態檔檔案至/etc/grafana組態檔目錄下
        • 創建grafana組態檔所需目錄
        • /etc/grafana組態檔目錄下創建custom.ini的組態檔并覆寫conf/defaults.ini中定義的任何設定
      • 啟動
      • 配置資料源
        • 匯入dashboard
      • 將grafana加入systemctl管理
        • 創建grafana-server.service服務檔案
        • 重新加載服務串列
        • 啟動服務
      • 將grafana設定為開機自啟動

簡單介紹

prometheus

什么是prometheus?

Prometheus是由SoundCloud開發的開源監控報警系統和時序列資料庫(TSDB),Prometheus使用Go語言開發,是Google BorgMon監控系統的開源版本, 2016年由Google發起Linux基金會旗下的原生云基金會(Cloud Native Computing Foundation), 將Prometheus納入其下第二大開源專案, Prometheus目前在開源社區相當活躍, Prometheus和Heapster(Heapster是K8S的一個子專案,用于獲取集群的性能資料,)相比功能更完善、更全面,Prometheus性能也足夠支撐上萬臺規模的集群,簡單來說prometheus就是用來資料收集和存盤的,使用的pull模式,

prometheus的特點

  • 多維度資料模型
  • 靈活的查詢語言
  • 不依賴分布式存盤,單個服務器節點是自主的
  • 通過基于HTTP的pull方式采集時序資料
  • 可以通過中間網關進行時序列資料推送
  • 通過服務發現或者靜態配置來發現目標服務物件
  • 支持多種多樣的圖表和界面展示,比如Grafana等

基本原理

通過HTTP協議周期性抓取被監控組件的狀態,任意組件只要提供對應的HTTP介面就可以接入監控,不需要任何SDK或者其他的集成程序,這樣做非常適合做虛擬化環境監控系統,比如VM、Docker、Kubernetes等,輸出被監控組件資訊的HTTP介面被叫做exporter ,目前互聯網公司常用的組件大部分都有exporter可以直接使用,比如Varnish、Haproxy、Nginx、MySQL、Linux系統資訊(包括磁盤、記憶體、CPU、網路等等),

服務程序

  • Prometheus Daemon負責定時去目標上抓取metrics(指標)資料,每個抓取目標需要暴露一個http服務的介面給它定時抓取,Prometheus支持通過組態檔、文本檔案、Zookeeper、Consul、DNS SRV Lookup等方式指定抓取目標,Prometheus采用PULL的方式進行監控,即服務器可以直接通過目標PULL資料或者間接地通過中間網關來Push資料
  • Prometheus在本地存盤抓取的所有資料,并通過一定規則進行清理和整理資料,并把得到的結果存盤到新的時間序列中
  • Prometheus通過PromQL和其他API可視化地展示收集的資料,Prometheus支持很多方式的圖表可視化,例如Grafana、自帶的Promdash以及自身提供的模版引擎等等,Prometheus還提供HTTP API的查詢方式,自定義所需要的輸出
  • PushGateway支持Client主動推送metrics到PushGateway,而Prometheus只是定時去Gateway上抓取資料
  • Alertmanager是獨立于Prometheus的一個組件,可以支持Prometheus的查詢陳述句,提供十分靈活的報警方式

三大套件

  • Server 主要負責資料采集和存盤,提供PromQL查詢語言的支持
  • Alertmanager 警告管理器,用來進行報警
  • Push Gateway 支持臨時性Job主動推送指標的中間網關

Grafana

什么是Grafana

Grafana是一個跨平臺的開源的度量分析和可視化工具,可以通過將采集的資料查詢然后可視化的展示,并及時通知,說白了,grafana就是prometheus的資料展示工具,

Grafana的特點

  • 展示方式:快速靈活的客戶端圖表,面板插件有許多不同方式的可視化指標和日志,官方庫中具有豐富的儀表盤插件,比如熱圖、折線圖、圖表等多種展示方式
  • 資料源:Graphite,InfluxDB,OpenTSDB,Prometheus,Elasticsearch,CloudWatch和KairosDB等
  • 通知提醒:以可視方式定義最重要指標的警報規則,Grafana將不斷計算并發送通知,在資料達到閾值時通過Slack、PagerDuty等獲得通知
  • 混合展示:在同一圖表中混合使用不同的資料源,可以基于每個查詢指定資料源,甚至自定義資料源
  • 注釋:使用來自不同資料源的豐富事件注釋圖表,將滑鼠懸停在事件上會顯示完整的事件元資料和標記
  • 過濾器:Ad-hoc過濾器允許動態創建新的鍵/值過濾器,這些過濾器會自動應用于使用該資料源的所有查詢

node_export

node_export是什么

node-export 主要主要是監控kubernetes 集群node 物理主機:cpu、memory、network、disk 等基礎監控資源, node_export是一個監控服務會暴露一個介面,prometheus通過這個介面獲取資料,

搭建程序

prometheus的安裝使用

用戶和組

#先檢查用戶prometheus和組prometheus是否存在

#檢查組是否存在
cat /etc/group | grep prometheus

#如果不存在,創建組
groupadd prometheus

#檢查用戶prometheus是否存在
cat /etc/passwd | grep prometheus    
或者  
id prometheus

#如果不存在,創建用戶
useradd -g prometheus prometheus

創建目錄

# 創建目錄并切換
[root@dxm22 ~]# mkdir -p /data/prometheus
[root@dxm22 ~]# cd /data/prometheus/

下載

[root@dxm22 prometheus]# wget https://github.com/prometheus/prometheus/releases/download/v2.23.0/prometheus-2.23.0.linux-amd64.tar.gz

# 下載完查看
[root@dxm22 prometheus]# ll -h
總用量 62M
-rw-r--r-- 1 root root 62M 11月 26 20:52 prometheus-2.23.0.linux-amd64.tar.gz

解壓

[root@dxm22 prometheus]# tar -zxvf prometheus-2.23.0.linux-amd64.tar.gz
prometheus-2.23.0.linux-amd64/
prometheus-2.23.0.linux-amd64/LICENSE
prometheus-2.23.0.linux-amd64/consoles/
prometheus-2.23.0.linux-amd64/consoles/node-cpu.html
prometheus-2.23.0.linux-amd64/consoles/prometheus-overview.html
prometheus-2.23.0.linux-amd64/consoles/node-overview.html
prometheus-2.23.0.linux-amd64/consoles/node.html
prometheus-2.23.0.linux-amd64/consoles/node-disk.html
prometheus-2.23.0.linux-amd64/consoles/index.html.example
prometheus-2.23.0.linux-amd64/consoles/prometheus.html
prometheus-2.23.0.linux-amd64/prometheus
prometheus-2.23.0.linux-amd64/console_libraries/
prometheus-2.23.0.linux-amd64/console_libraries/prom.lib
prometheus-2.23.0.linux-amd64/console_libraries/menu.lib
prometheus-2.23.0.linux-amd64/prometheus.yml
prometheus-2.23.0.linux-amd64/promtool
prometheus-2.23.0.linux-amd64/NOTICE
[root@dxm22 prometheus]# ll -h
總用量 62M
drwxr-xr-x 4 3434 3434 132 11月 26 20:49 prometheus-2.23.0.linux-amd64
-rw-r--r-- 1 root root 62M 11月 26 20:52 prometheus-2.23.0.linux-amd64.tar.gz

為prometheus創建組態檔目錄和存放資料目錄并賦權限

# 為prometheus創建存放組態檔的目錄
[root@dxm22 data]# mkdir /etc/prometheus

# 為prometheus創建存放資料的目錄
[root@dxm22 data]# mkdir /var/lib/prometheus

# 為/var/lib/prometheus目錄設定權限
[root@dxm22 data]# chown prometheus.prometheus /var/lib/prometheus
[root@dxm22 data]# ll /var/lib | grep prometheus
drwxr-xr-x   2 prometheus     prometheus        6 12月  8 22:20 prometheus

將prometheus組態檔拷貝到/etc/prometheus目錄下

[root@dxm22 prometheus-2.23.0.linux-amd64]# cp prometheus.yml /etc/prometheus/

將prometheus下二進制檔案拷貝到/usr/local/bin目錄下

[root@dxm22 prometheus-2.23.0.linux-amd64]# cp prometheus /usr/local/bin/
[root@dxm22 prometheus-2.23.0.linux-amd64]# cp promtool /usr/local/bin/
[root@dxm22 prometheus-2.23.0.linux-amd64]# ll /usr/local/bin/ | grep prom
-rwxr-xr-x 1 root root 88153522 12月  8 22:25 prometheus
-rwxr-xr-x 1 root root 78172790 12月  8 22:26 promtool

修改組態檔

[root@dxm22 prometheus]# cat /etc/prometheus/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']

因為默認的組態檔中已經有prometheus自身的配置資訊了,所以這里我們無需修改,

啟動prometheus

# 可直接啟動(非后臺啟動),進入prometheus安裝目錄
./prometheus

# 后臺啟動,在安裝目錄下:
nohup ./prometheus --config.file=prometheus.yml --web.enable-admin-api --web.listen-address=:9090 >/dev/null 2>&1 &

# 后臺啟動,在任意目錄下:
nohup /usr/local/prometheus/prometheus --config.file=/etc/prometheus/prometheus.yml --web.enable-admin-api --web.listen-address=:9090 >/dev/null 2>&1 &

我們這里使用后臺啟動,
[root@dxm22 prometheus-2.23.0.linux-amd64]# nohup /usr/local/prometheus/prometheus --config.file=/etc/prometheus/prometheus.yml --web.enable-admin-api --web.listen-address=:9090 >/dev/null 2>&1 &
[1] 20203

# 查看是否存在prometheus行程
[root@dxm22 prometheus-2.23.0.linux-amd64]# ps aux | grep prometheus
root       20203  4.5  3.3 769484 61424 pts/0    Sl   22:43   0:00 /usr/local/prometheus/prometheus --config.file=/etc/prometheus/prometheus.yml --web.enable-admin-api --web.listen-address=:9090
root       20213  0.0  0.0  12320  1044 pts/0    S+   22:43   0:00 grep --color=auto prometheus

# 查看9090埠是否被監聽
[root@dxm22 prometheus-2.23.0.linux-amd64]# netstat -tunlp | grep :9090
tcp6       0      0 :::9090                 :::*                    LISTEN      20203/prometheus

啟動成功后,瀏覽器訪問ip:9090,我們這里是http://192.168.0.22:9090/targets
在這里插入圖片描述

防火墻配置

因為我這里是本機測驗,所以防火墻是關閉狀態,正常情況下服務器的防火墻都是開啟的,所以需要做這一步配置,把9090埠加入防火墻,

# 把9090埠加入防火墻
[root@dxm22 prometheus-2.23.0.linux-amd64]# firewall-cmd --add-port=9090/tcp --permanent
success

# 多載防火墻的修改
[root@dxm22 prometheus-2.23.0.linux-amd64]# firewall-cmd --reload
success

將prometheus加入systemctl管理

創建prometheus.service服務檔案

[Unit]

Description=Prometheus Time Series Collection and Processing Server
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
Type=simple
ExecStart=/usr/local/prometheus/prometheus \
    --config.file /etc/prometheus/prometheus.yml \
    --storage.tsdb.path /var/lib/prometheus/ \
    --web.console.templates=/etc/prometheus/consoles \
    --web.console.libraries=/etc/prometheus/console_libraries
LimitNOFILE=65536
PrivateTmp=true
RestartSec=2
StartLimitInterval=0
Restart=always
    
[Install]
WantedBy=multi-user.target

重新加載服務串列

[root@dxm22 prometheus-2.23.0.linux-amd64]# systemctl daemon-reload

啟動服務

# 停止上面手動后臺啟動的prometheus服務
[root@dxm22 prometheus-2.23.0.linux-amd64]# ps aux | grep prometheus
root       20203  0.0  4.0 769484 75316 pts/0    Sl   22:43   0:00 /usr/local/prometheus/prometheus --config.file=/etc/prometheus/prometheus.yml --web.enable-admin-api --web.listen-address=:9090
root       20881  0.0  0.1  12320  2376 pts/0    S+   23:05   0:00 grep --color=auto prometheus
[root@dxm22 prometheus-2.23.0.linux-amd64]# kill -9 20203

# 檢查是否還存在prometheus行程
[root@dxm22 prometheus-2.23.0.linux-amd64]# ps aux | grep prometheus
root       20885  0.0  0.0  12320  1084 pts/0    S+   23:05   0:00 grep --color=auto prometheus

# 查詢所有服務單元是否有prometheus
[root@dxm22 prometheus-2.23.0.linux-amd64]# systemctl list-unit-files | grep prometheus
prometheus.service                         disabled

# 存在,且非開啟自啟動,接著使用systemctl啟動prometheus服務
[root@dxm22 prometheus-2.23.0.linux-amd64]# systemctl start prometheus.service

# 查看prometheus服務狀態
[root@dxm22 prometheus-2.23.0.linux-amd64]# systemctl status prometheus.service
● prometheus.service - Prometheus Time Series Collection and Processing Server
   Loaded: loaded (/etc/systemd/system/prometheus.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-12-08 23:07:57 CST; 11s ago
 Main PID: 20927 (prometheus)
    Tasks: 9 (limit: 11154)
   Memory: 24.2M
   CGroup: /system.slice/prometheus.service
           └─20927 /usr/local/prometheus/prometheus --config.file /etc/prometheus/prometheus.yml --storage.tsdb.path /var/lib/pro>

12月 08 23:07:58 dxm22.host prometheus[20927]: level=info ts=2020-12-08T15:07:58.085Z caller=head.go:645 component=tsdb msg="Repl>
12月 08 23:07:58 dxm22.host prometheus[20927]: level=info ts=2020-12-08T15:07:58.085Z caller=head.go:659 component=tsdb msg="On-d>
12月 08 23:07:58 dxm22.host prometheus[20927]: level=info ts=2020-12-08T15:07:58.085Z caller=head.go:665 component=tsdb msg="Repl>
12月 08 23:07:58 dxm22.host prometheus[20927]: level=info ts=2020-12-08T15:07:58.086Z caller=head.go:717 component=tsdb msg="WAL >
12月 08 23:07:58 dxm22.host prometheus[20927]: level=info ts=2020-12-08T15:07:58.086Z caller=head.go:722 component=tsdb msg="WAL >
12月 08 23:07:58 dxm22.host prometheus[20927]: level=info ts=2020-12-08T15:07:58.086Z caller=main.go:742 fs_type=XFS_SUPER_MAGIC
12月 08 23:07:58 dxm22.host prometheus[20927]: level=info ts=2020-12-08T15:07:58.086Z caller=main.go:745 msg="TSDB started"
12月 08 23:07:58 dxm22.host prometheus[20927]: level=info ts=2020-12-08T15:07:58.086Z caller=main.go:871 msg="Loading configurati>
12月 08 23:08:00 dxm22.host prometheus[20927]: level=info ts=2020-12-08T15:08:00.619Z caller=main.go:902 msg="Completed loading o>
12月 08 23:08:00 dxm22.host prometheus[20927]: level=info ts=2020-12-08T15:08:00.619Z caller=main.go:694 msg="Server is ready to >

在這里插入圖片描述

Active: active (running) 可以看到prometheus服務已經啟動成功,
在這里插入圖片描述

將prometheus設定為開機自啟動

[root@dxm22 prometheus-2.23.0.linux-amd64]# systemctl list-unit-files | grep prometheus
prometheus.service                         disabled
# disabled表示非開機自啟動

# 設定為開機自啟動
[root@dxm22 prometheus-2.23.0.linux-amd64]# systemctl enable prometheus.service
Created symlink /etc/systemd/system/multi-user.target.wants/prometheus.service → /etc/systemd/system/prometheus.service.

# 再次查看
[root@dxm22 prometheus-2.23.0.linux-amd64]# systemctl list-unit-files | grep prometheus
prometheus.service                         enabled

# enabled表示是開機自啟動,執行重啟命令
[root@dxm22 prometheus-2.23.0.linux-amd64]# reboot

#重啟后再次查看prometheus服務已啟動完成,

node_exporter的安裝和使用

用戶和組

#先檢查用戶node_exporter和組node_exporter是否存在

#檢查組是否存在
cat /etc/group | grep node_exporter

#如果不存在,創建組
groupadd node_exporter

#檢查用戶node_exporter是否存在
cat /etc/passwd | grep node_exporter    
或者  
id node_exporter

#如果不存在,創建用戶
useradd -g node_exporter node_exporter

創建目錄

# 創建目錄并切換
[root@dxm22 ~]# mkdir -p /data/node_exporter
[root@dxm22 ~]# cd /data/node_exporter

下載

[root@dxm22 node_exporter]# wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz

# 下載完查看
[root@dxm22 node_exporter]# ll -h
總用量 9.1M
-rw-r--r-- 1 root root 9.1M 6月  16 21:19 node_exporter-1.0.1.linux-amd64.tar.gz

解壓

[root@dxm22 node_exporter]# tar -zxvf node_exporter-1.0.1.linux-amd64.tar.gz
node_exporter-1.0.1.linux-amd64/
node_exporter-1.0.1.linux-amd64/NOTICE
node_exporter-1.0.1.linux-amd64/node_exporter
node_exporter-1.0.1.linux-amd64/LICENSE

將node_exporter下二進制檔案拷貝到/usr/local/bin目錄下并設定權限

# 拷貝檔案
[root@dxm22 node_exporter-1.0.1.linux-amd64]# cp node_exporter /usr/local/bin/
[root@dxm22 node_exporter-1.0.1.linux-amd64]# ll /usr/local/bin/ | grep node
-rwxr-xr-x 1 root root 19657731 12月  8 23:27 node_exporter

# 設定權限
[root@dxm22 node_exporter-1.0.1.linux-amd64]# chown node_exporter.node_exporter /usr/local/bin/node_exporter

# 查看權限設定是否成功
[root@dxm22 node_exporter-1.0.1.linux-amd64]# ll /usr/local/bin/node_exporter
-rwxr-xr-x 1 node_exporter node_exporter 19657731 12月  8 23:27 /usr/local/bin/node_exporter

啟動

# 可直接啟動(非后臺啟動),進入node_exporter安裝目錄
./node_exporter

# 后臺啟動,在安裝目錄下:
nohup ./node_exporter &
# 后臺啟動,在任意目錄下:
nohup /usr/local/bin/node_exporter &

我們這里使用后臺啟動,
[root@dxm22 node_exporter-1.0.1.linux-amd64]# nohup /usr/local/bin/node_exporter &
[1] 21296
[root@dxm22 node_exporter-1.0.1.linux-amd64]# nohup: 忽略輸入并把輸出追加到'nohup.out'

# 查看是否存在node_exporter行程
[root@dxm22 node_exporter-1.0.1.linux-amd64]# ps aux | grep node_exporter
root       21296  0.0  0.7 717504 13380 pts/0    Sl   23:35   0:00 /usr/local/bin/node_exporter
root       21315  0.0  0.0  12320  1068 pts/0    S+   23:36   0:00 grep --color=auto node_exporter

# 查看9100埠是否被監聽
[root@dxm22 node_exporter-1.0.1.linux-amd64]# netstat -ntlp | grep :9100
tcp6       0      0 :::9100                 :::*                    LISTEN      21296/node_exporter

說明啟動成功,在瀏覽器上輸入ip + 9100埠可訪問,(如果有防火墻,需要設定)
在這里插入圖片描述

將node_exporter加入systemctl管理

創建node_exporter.service服務檔案

[root@dxm22 node_exporter-1.0.1.linux-amd64]# cat /etc/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target

[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter
PrivateTmp=true
RestartSec=5
StartLimitInterval=0
Restart=always

[Install]
WantedBy=multi-user.target

重新加載服務串列

[root@dxm22 node_exporter-1.0.1.linux-amd64]# systemctl daemon-reload

啟動服務

# 停止上面手動后臺啟動的node_exporter行程
[root@dxm22 node_exporter-1.0.1.linux-amd64]# ps aux | grep node_exporter
root       21464  0.0  0.8 717760 14884 pts/0    Sl   23:44   0:00 /usr/local/bin/node_exporter
root       21513  0.0  0.0  12320  1112 pts/0    S+   23:45   0:00 grep --color=auto node_exporter
[root@dxm22 node_exporter-1.0.1.linux-amd64]# kill -9 21464

# 檢查是否還存在node_exporter行程
[root@dxm22 node_exporter-1.0.1.linux-amd64]# ps aux | grep node_exporter
root       21516  0.0  0.0  12320  1060 pts/0    S+   23:45   0:00 grep --color=auto node_exporter

# 查詢所有服務單元是否有node_exporter
[root@dxm22 node_exporter-1.0.1.linux-amd64]# systemctl list-unit-files | grep node_exporter
node_exporter.service                      disabled

# 存在,且非開啟自啟動,接著使用systemctl啟動node_exporter服務
[root@dxm22 node_exporter-1.0.1.linux-amd64]# systemctl start node_exporter

# 查看node_exporter服務狀態
[root@dxm22 node_exporter-1.0.1.linux-amd64]# systemctl status node_exporter.service

在這里插入圖片描述
Active: active (running) 可以看到node_exporter服務已經啟動成功,在瀏覽器上輸入ip + 9100埠可訪問,

將node_exporter設定為開機自啟動

[root@dxm22 node_exporter-1.0.1.linux-amd64]# systemctl list-unit-files | grep node_exporter
node_exporter.service                      disabled
# disabled表示非開機自啟動

# 設定為開機自啟動
[root@dxm22 node_exporter-1.0.1.linux-amd64]# systemctl enable node_exporter.service
Created symlink /etc/systemd/system/multi-user.target.wants/node_exporter.service → /etc/systemd/system/node_exporter.service.

# 再次查看
[root@dxm22 node_exporter-1.0.1.linux-amd64]# systemctl list-unit-files | grep node_exporter
node_exporter.service                      enabled

# enabled表示是開機自啟動,執行重啟命令
[root@dxm22 node_exporter-1.0.1.linux-amd64]# reboot

#重啟后再次查看node_exporter服務已啟動完成,

加入prometheus監控

[root@dxm22 node_exporter-1.0.1.linux-amd64]# vim /etc/prometheus/prometheus.yml
# 增加如下內容:
# node_exporter監控 -新增node_exporter相關job
  - job_name: 'node_exporter'
    static_configs:
    - targets: ['localhost:9100']

在這里插入圖片描述
重啟prometheus

[root@dxm22 node_exporter-1.0.1.linux-amd64]# systemctl restart prometheus.service

再次訪問http://192.168.0.22:9090/targets,在這里插入圖片描述

Grafana的安裝使用

用戶和組

#先檢查用戶grafana和組grafana是否存在

#檢查組是否存在
cat /etc/group | grep grafana

#如果不存在,創建組
groupadd grafana

#檢查用戶grafana是否存在
cat /etc/passwd | grep grafana    
或者  
id grafana

#如果不存在,創建用戶
useradd -g grafana grafana

創建目錄

# 創建目錄并切換
[root@dxm22 ~]# mkdir -p /data/grafana
[root@dxm22 ~]# cd /data/grafana

下載

# 去官網下載grafana包,官網地址:https://grafana.com/grafana/download
# 或者 wget https://dl.grafana.com/oss/release/grafana-7.3.4-1.x86_64.rpm
# 或者到華為鏡像網站下載wget https://mirrors.huaweicloud.com/grafana/7.3.4/grafana-7.3.4.linux-amd64.tar.gz

# 這里我們去華為鏡像下載
[root@dxm22 grafana]# wget https://mirrors.huaweicloud.com/grafana/7.3.4/grafana-7.3.4.linux-amd64.tar.gz

# 下載完查看
[root@dxm22 grafana]# ll -h
總用量 52M
-rw-r--r-- 1 root root 52M 11月 24 14:35 grafana-7.3.4.linux-amd64.tar.gz

解壓

[root@dxm22 grafana]# tar -zxvf grafana-7.3.4.linux-amd64.tar.gz

將grafana下二進制檔案拷貝到/usr/local/bin目錄下并設定權限

# 拷貝檔案
[root@dxm22 grafana-7.3.4]# cp /data/grafana/grafana-7.3.4/bin/grafana-server /usr/local/bin/
[root@dxm22 grafana-7.3.4]# ll /usr/local/bin/ | grep grafana
-rwxr-xr-x 1 root          root          58938592 12月  9 11:56 grafana-server

# 設定權限
[root@dxm22 grafana-7.3.4]# chown grafana.grafana /usr/local/bin/grafana-server

# 查看權限設定是否成功
[root@dxm22 grafana-7.3.4]# ll /usr/local/bin/grafana-server
-rwxr-xr-x 1 grafana grafana 58938592 12月  9 11:56 /usr/local/bin/grafana-server

配置grafana

拷貝ini組態檔檔案至/etc/grafana組態檔目錄下

# 將解壓檔案下conf檔案夾下ini檔案均拷貝至/etc/grafana目錄下
[root@dxm22 grafana-7.3.4]# cp -r /data/grafana/grafana-7.3.4/conf/ /etc/grafana/
[root@dxm22 grafana-7.3.4]# ll /etc/grafana/
總用量 72
-rw-r--r-- 1 root root 30381 12月  9 12:05 defaults.ini
-rw-r--r-- 1 root root  1045 12月  9 12:05 ldap_multiple.toml
-rw-r--r-- 1 root root  2289 12月  9 12:05 ldap.toml
drwxr-xr-x 6 root root    75 12月  9 12:05 provisioning
-rw-r--r-- 1 root root 31400 12月  9 12:05 sample.ini

創建grafana組態檔所需目錄

# 創建用于存放temp files, sessions, and the sqlite3 db等的資料目錄
[root@dxm22 grafana-7.3.4]# mkdir /var/lib/grafana

# 創建grafana日志檔案目錄
[root@dxm22 grafana-7.3.4]# mkdir /var/lib/grafana/log

# 創建plugins目錄
[root@dxm22 grafana-7.3.4]# mkdir /var/lib/grafana/plugins

/etc/grafana組態檔目錄下創建custom.ini的組態檔并覆寫conf/defaults.ini中定義的任何設定

# 復制defaults.ini檔案并重命名為custom.ini
[root@dxm22 grafana-7.3.4]# cp /etc/grafana/defaults.ini /etc/grafana/custom.ini
[root@dxm22 grafana-7.3.4]# ll /etc/grafana/ | grep ini
-rw-r--r-- 1 root root 30381 12月  9 12:08 custom.ini
-rw-r--r-- 1 root root 30381 12月  9 12:05 defaults.ini
-rw-r--r-- 1 root root 31400 12月  9 12:05 sample.ini

# 修改custom.ini檔案內容,主要有以下幾項,未列出的默認即可,
data = /var/lib/grafana

logs = /var/lib/grafana/log

plugins = /var/lib/grafana/plugins

provisioning = /etc/grafana/provisioning

啟動

# 可直接啟動(非后臺啟動),進入grafana安裝目錄bin下
./grafana-server

# 后臺啟動,在安裝目錄下:
nohup ./grafana-server &
# 后臺啟動,在任意目錄下:
nohup /usr/local/bin/grafana-server &

我們這里使用后臺啟動,
[root@dxm22 grafana-7.3.4]# nohup /usr/local/bin/grafana-server &
[1] 28811
[root@dxm22 grafana-7.3.4]# nohup: 忽略輸入并把輸出追加到'nohup.out'

# 查看是否存在grafana行程
[root@dxm22 grafana-7.3.4]# ps aux | grep grafana
root       28811  4.1  2.9 1427932 54568 pts/0   Sl   12:25   0:00 /usr/local/bin/grafana-server
root       28822  0.0  0.0  12320  1076 pts/0    S+   12:25   0:00 grep --color=auto grafana

# 查看3000埠是否被監聽
[root@dxm22 grafana-7.3.4]# netstat -ntlp | grep :3000
tcp6       0      0 :::3000                 :::*                    LISTEN      28811/grafana-server

說明啟動成功,在瀏覽器上輸入ip + 3000埠可訪問,我們這里是http://192.168.0.22:3000/,(如果有防火墻,需要設定),默認的用戶名/密碼都使用 admin,
在這里插入圖片描述
我們登錄之后再看
在這里插入圖片描述

配置資料源

左側選單->Configuration->Data Sources->點 add data source 按鈕
在這里插入圖片描述
選擇prometheus,如圖:
在這里插入圖片描述
設定url,我們這里是http://192.168.0.22:9090,大家注意要修改為自己的IP+埠:
在這里插入圖片描述
然后點 save & test 按鈕,看到 “Data source is working” 表示資料源可以正常作業,如圖:
在這里插入圖片描述

匯入dashboard

可在官方模板https://grafana.com/grafana/dashboards,查看模板編號,也可以下載后匯入,比如我這里選擇import,輸入模板編號為8919
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述

將grafana加入systemctl管理

創建grafana-server.service服務檔案

[root@dxm22 grafana-7.3.4]# vim /etc/systemd/system/grafana-server.service


[Unit]
Description=Grafana instance
Documentation=http://docs.grafana.org
Wants=network-online.target
After=network-online.target
After=postgresql.service mariadb.service mysqld.service

[Service]
User=grafana
Group=grafana
Type=notify
Restart=on-failure
WorkingDirectory=/usr/share/grafana
RuntimeDirectory=grafana
RuntimeDirectoryMode=0750
ExecStart=/usr/local/bin/grafana-server                                                  \
                            --config=/etc/grafana/custom.ini                             \
                            --homepath=/data/grafana/grafana-7.3.4                       \
                            --pidfile=/var/lib/grafana/pid/grafana-server.pid            \
                            cfg:default.paths.logs=/var/lib/grafana/log                  \
                            cfg:default.paths.data=/var/lib/grafana                      \
                            cfg:default.paths.plugins=/var/lib/grafana/plugins           \
                            cfg:default.paths.provisioning=/etc/grafana/provisioning  &

LimitNOFILE=10000
TimeoutStopSec=20

[Install]
WantedBy=multi-user.target

# 目錄賦權限
chown -R grafana.grafana /usr/share/grafana
chown -R grafana.grafana /etc/grafana/
chown -R grafana.grafana /var/lib/grafana/

重新加載服務串列

[root@dxm22 grafana-7.3.4]# systemctl daemon-reload

啟動服務

# 停止上面手動后臺啟動的grafana行程
[root@dxm22 grafana-7.3.4]# ps aux | grep grafana
root       28811  0.1  1.8 1649640 33700 pts/0   Sl   12:25   0:03 /usr/local/bin/grafana-server
root       29742  0.0  0.0  12320  1088 pts/0    S+   13:11   0:00 grep --color=auto grafana
[root@dxm22 grafana-7.3.4]# kill -9 28811

# 檢查是否還存在grafana行程
[root@dxm22 grafana-7.3.4]# ps aux | grep grafana
root       29748  0.0  0.0  12320   972 pts/0    S+   13:12   0:00 grep --color=auto grafana

# 查詢所有服務單元是否有grafana
[root@dxm22 grafana-7.3.4]# systemctl list-unit-files | grep grafana
grafana-server.service                     disabled

# 存在,且非開啟自啟動,接著使用systemctl啟動grafana服務
[root@dxm22 grafana-7.3.4]# systemctl start grafana-server.service

# 查看grafana服務狀態
[root@dxm22 grafana-7.3.4]# systemctl status grafana-server.service

在這里插入圖片描述

Active: active (running) 可以看到grafana服務已經啟動成功,在瀏覽器上輸入ip + 3000埠可訪問,

將grafana設定為開機自啟動

[[root@dxm22 grafana-7.3.4]# systemctl list-unit-files |  grep grafana
grafana-server.service                     disabled
# disabled表示非開機自啟動

# 設定為開機自啟動
[root@dxm22 grafana-7.3.4]# systemctl enable grafana-server
Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service → /etc/systemd/system/grafana-server.service.
# 再次查看
[root@dxm22 grafana-7.3.4]# systemctl list-unit-files |  grep grafana
grafana-server.service                     enabled

# enabled表示是開機自啟動,執行重啟命令
[root@dxm22 grafana-7.3.4]# reboot

#重啟后再次查看grafana服務已啟動完成,

至此我們就完成了在centos8服務器上安裝prometheus、node_exporter和grafana的監控環境,下一步我們將接入mysqld_exporter加入prometheus來監控,

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/232539.html

標籤:其他

上一篇:JAVA期末實驗:CSP 201809-4 原題

下一篇:Centos7(阿里云)安裝Mysql5.7

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 網閘典型架構簡述

    網閘架構一般分為兩種:三主機的三系統架構網閘和雙主機的2+1架構網閘。 三主機架構分別為內端機、外端機和仲裁機。三機無論從軟體和硬體上均各自獨立。首先從硬體上來看,三機都用各自獨立的主板、記憶體及存盤設備。從軟體上來看,三機有各自獨立的作業系統。這樣能達到完全的三機獨立。對于“2+1”系統,“2”分為 ......

    uj5u.com 2020-09-10 02:00:44 more
  • 如何從xshell上傳檔案到centos linux虛擬機里

    如何從xshell上傳檔案到centos linux虛擬機里及:虛擬機CentOs下執行 yum -y install lrzsz命令,出現錯誤:鏡像無法找到軟體包 前言 一、安裝lrzsz步驟 二、上傳檔案 三、遇到的問題及解決方案 總結 前言 提示:其實很簡單,往虛擬機上安裝一個上傳檔案的工具 ......

    uj5u.com 2020-09-10 02:00:47 more
  • 一、SQLMAP入門

    一、SQLMAP入門 1、判斷是否存在注入 sqlmap.py -u 網址/id=1 id=1不可缺少。當注入點后面的引數大于兩個時。需要加雙引號, sqlmap.py -u "網址/id=1&uid=1" 2、判斷文本中的請求是否存在注入 從文本中加載http請求,SQLMAP可以從一個文本檔案中 ......

    uj5u.com 2020-09-10 02:00:50 more
  • Metasploit 簡單使用教程

    metasploit 簡單使用教程 浩先生, 2020-08-28 16:18:25 分類專欄: kail 網路安全 linux 文章標簽: linux資訊安全 編輯 著作權 metasploit 使用教程 前言 一、Metasploit是什么? 二、準備作業 三、具體步驟 前言 Msfconsole ......

    uj5u.com 2020-09-10 02:00:53 more
  • 游戲逆向之驅動層與用戶層通訊

    驅動層代碼: #pragma once #include <ntifs.h> #define add_code CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFERED,FILE_ANY_ACCESS) /* 更多游戲逆向視頻www.yxfzedu.com ......

    uj5u.com 2020-09-10 02:00:56 more
  • 北斗電力時鐘(北斗授時服務器)讓網路資料更精準

    北斗電力時鐘(北斗授時服務器)讓網路資料更精準 北斗電力時鐘(北斗授時服務器)讓網路資料更精準 京準電子科技官微——ahjzsz 近幾年,資訊技術的得了快速發展,互聯網在逐漸普及,其在人們生活和生產中都得到了廣泛應用,并且取得了不錯的應用效果。計算機網路資訊在電力系統中的應用,一方面使電力系統的運行 ......

    uj5u.com 2020-09-10 02:01:03 more
  • 【CTF】CTFHub 技能樹 彩蛋 writeup

    ?碎碎念 CTFHub:https://www.ctfhub.com/ 筆者入門CTF時時剛開始刷的是bugku的舊平臺,后來才有了CTFHub。 感覺不論是網頁UI設計,還是題目質量,賽事跟蹤,工具軟體都做得很不錯。 而且因為獨到的金幣制度的確讓人有一種想去刷題賺金幣的感覺。 個人還是非常喜歡這個 ......

    uj5u.com 2020-09-10 02:04:05 more
  • 02windows基礎操作

    我學到了一下幾點 Windows系統目錄結構與滲透的作用 常見Windows的服務詳解 Windows埠詳解 常用的Windows注冊表詳解 hacker DOS命令詳解(net user / type /md /rd/ dir /cd /net use copy、批處理 等) 利用dos命令制作 ......

    uj5u.com 2020-09-10 02:04:18 more
  • 03.Linux基礎操作

    我學到了以下幾點 01Linux系統介紹02系統安裝,密碼啊破解03Linux常用命令04LAMP 01LINUX windows: win03 8 12 16 19 配置不繁瑣 Linux:redhat,centos(紅帽社區版),Ubuntu server,suse unix:金融機構,證券,銀 ......

    uj5u.com 2020-09-10 02:04:30 more
  • 05HTML

    01HTML介紹 02頭部標簽講解03基礎標簽講解04表單標簽講解 HTML前段語言 js1.了解代碼2.根據代碼 懂得挖掘漏洞 (POST注入/XSS漏洞上傳)3.黑帽seo 白帽seo 客戶網站被黑帽植入劫持代碼如何處理4.熟悉html表單 <html><head><title>TDK標題,描述 ......

    uj5u.com 2020-09-10 02:04:36 more
最新发布
  • 2023年最新微信小程式抓包教程

    01 開門見山 隔一個月發一篇文章,不過分。 首先回顧一下《微信系結手機號資料庫被脫庫事件》,我也是第一時間得知了這個訊息,然后跟蹤了整件事情的經過。下面是這起事件的相關截圖以及近日流出的一萬條資料樣本: 個人認為這件事也沒什么,還不如關注一下之前45億快遞資料查詢渠道疑似在近日復活的訊息。 訊息是 ......

    uj5u.com 2023-04-20 08:48:24 more
  • web3 產品介紹:metamask 錢包 使用最多的瀏覽器插件錢包

    Metamask錢包是一種基于區塊鏈技術的數字貨幣錢包,它允許用戶在安全、便捷的環境下管理自己的加密資產。Metamask錢包是以太坊生態系統中最流行的錢包之一,它具有易于使用、安全性高和功能強大等優點。 本文將詳細介紹Metamask錢包的功能和使用方法。 一、 Metamask錢包的功能 數字資 ......

    uj5u.com 2023-04-20 08:47:46 more
  • vulnhub_Earth

    前言 靶機地址->>>vulnhub_Earth 攻擊機ip:192.168.20.121 靶機ip:192.168.20.122 參考文章 https://www.cnblogs.com/Jing-X/archive/2022/04/03/16097695.html https://www.cnb ......

    uj5u.com 2023-04-20 07:46:20 more
  • 從4k到42k,軟體測驗工程師的漲薪史,給我看哭了

    清明節一過,盲猜大家已經無心上班,在數著日子準備過五一,但一想到銀行卡里的余額……瞬間心情就不美麗了。最近,2023年高校畢業生就業調查顯示,本科畢業月平均起薪為5825元。調查一出,便有很多同學表示自己又被平均了。看著這一資料,不免讓人想到前不久中國青年報的一項調查:近六成大學生認為畢業10年內會 ......

    uj5u.com 2023-04-20 07:44:00 more
  • 最新版本 Stable Diffusion 開源 AI 繪畫工具之中文自動提詞篇

    🎈 標簽生成器 由于輸入正向提示詞 prompt 和反向提示詞 negative prompt 都是使用英文,所以對學習母語的我們非常不友好 使用網址:https://tinygeeker.github.io/p/ai-prompt-generator 這個網址是為了讓大家在使用 AI 繪畫的時候 ......

    uj5u.com 2023-04-20 07:43:36 more
  • 漫談前端自動化測驗演進之路及測驗工具分析

    隨著前端技術的不斷發展和應用程式的日益復雜,前端自動化測驗也在不斷演進。隨著 Web 應用程式變得越來越復雜,自動化測驗的需求也越來越高。如今,自動化測驗已經成為 Web 應用程式開發程序中不可或缺的一部分,它們可以幫助開發人員更快地發現和修復錯誤,提高應用程式的性能和可靠性。 ......

    uj5u.com 2023-04-20 07:43:16 more
  • CANN開發實踐:4個DVPP記憶體問題的典型案例解讀

    摘要:由于DVPP媒體資料處理功能對存放輸入、輸出資料的記憶體有更高的要求(例如,記憶體首地址128位元組對齊),因此需呼叫專用的記憶體申請介面,那么本期就分享幾個關于DVPP記憶體問題的典型案例,并給出原因分析及解決方法。 本文分享自華為云社區《FAQ_DVPP記憶體問題案例》,作者:昇騰CANN。 DVPP ......

    uj5u.com 2023-04-20 07:43:03 more
  • msf學習

    msf學習 以kali自帶的msf為例 一、msf核心模塊與功能 msf模塊都放在/usr/share/metasploit-framework/modules目錄下 1、auxiliary 輔助模塊,輔助滲透(埠掃描、登錄密碼爆破、漏洞驗證等) 2、encoders 編碼器模塊,主要包含各種編碼 ......

    uj5u.com 2023-04-20 07:42:59 more
  • Halcon軟體安裝與界面簡介

    1. 下載Halcon17版本到到本地 2. 雙擊安裝包后 3. 步驟如下 1.2 Halcon軟體安裝 界面分為四大塊 1. Halcon的五個助手 1) 影像采集助手:與相機連接,設定相機引數,采集影像 2) 標定助手:九點標定或是其它的標定,生成標定檔案及內參外參,可以將像素單位轉換為長度單位 ......

    uj5u.com 2023-04-20 07:42:17 more
  • 在MacOS下使用Unity3D開發游戲

    第一次發博客,先發一下我的游戲開發環境吧。 去年2月份買了一臺MacBookPro2021 M1pro(以下簡稱mbp),這一年來一直在用mbp開發游戲。我大致分享一下我的開發工具以及使用體驗。 1、Unity 官網鏈接: https://unity.cn/releases 我一般使用的Apple ......

    uj5u.com 2023-04-20 07:40:19 more