linux(centos8):安裝prometheus服務端/node_exporter客戶端(prometheus 2.18.1)


一,prometheus的用途

Prometheus是一個開源的系統監控和警報工具包

相比其他監控系統,它更適用於微服務的體系架構

它使用各種專用exporter,用來實現對硬件/存儲/數據庫/web服務等的監控

 

說明:劉宏締的架構森林是一個專注架構的博客,地址:https://www.cnblogs.com/architectforest

         對應的源碼可以訪問這里獲取: https://github.com/liuhongdi/

說明:作者:劉宏締 郵箱: 371125307@qq.com

 

二,下載prometheus

1,官網:

https://prometheus.io/

 

2,prometheus的軟件下載地址

https://prometheus.io/download/

 

3,下載

下載到源代碼目錄下

[root@blog prometheus]# pwd
/usr/local/source/prometheus
[root@blog prometheus]# wget https://github.com/prometheus/prometheus/releases/download/v2.18.1/prometheus-2.18.1.linux-amd64.tar.gz     

 

三,安裝prometheus

1,解壓縮

[root@blog prometheus]# tar -zxvf prometheus-2.18.1.linux-amd64.tar.gz

 

2,移動到軟件的安裝目錄

[root@blog prometheus]# mv prometheus-2.18.1.linux-amd64 /usr/local/soft/

 

四,配置prometheus

查看配置文件

[root@blog prometheus-2.18.1.linux-amd64]# more prometheus.yml

內容

...
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
    - targets: ['localhost:9090']

因為默認的配置文件中已經有prometheus自身的信息配置,

所以無需修改

 

五,用systemd管理prometheus服務

1,創建service文件

[root@blog ~]# vi /usr/lib/systemd/system/prometheus.service

內容:

[Unit]
Description=prometheus
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/soft/prometheus-2.18.1.linux-amd64/prometheus --config.file="/usr/local/soft/prometheus-2.18.1.linux-amd64/prometheus.yml"
LimitNOFILE=65536
PrivateTmp=true
RestartSec=2
StartLimitInterval=0
Restart=always

[Install]
WantedBy=multi-user.target

說明:注意把軟件的路徑替換成自己prometheus安裝的路徑

 

2,重新加載服務列表

[root@blog ~]# systemctl daemon-reload

 

3,啟動服務

[root@blog ~]# systemctl start prometheus.service 

 

六,測試服務端安裝效果

1,查看版本

[root@blog ~]# /usr/local/soft/prometheus-2.18.1.linux-amd64/prometheus --version
prometheus, version 2.18.1 (branch: HEAD, revision: ecee9c8abfd118f139014cb1b174b08db3f342cf)
  build user:       root@2117a9e64a7e
  build date:       20200507-16:51:47
  go version:       go1.14.2 

 

2,查看幫助:

[root@blog ~]# /usr/local/soft/prometheus-2.18.1.linux-amd64/prometheus --help 

 

3,登錄到圖形管理界面:

訪問下面的地址:注意把ip替換成自己服務器的ip

http://121.122.123.47:9090/targets

 

查看截圖:

  

七,安裝客戶端(各步驟在客戶端操作)

1,常用的幾個exporter

            node_exporter: 監控操作系統的性能和運行狀態
            mysqld_exporter:監控 mysql 服務
            snmp_exporter: 監控網絡設備

      這里以安裝node_exporter為例:

2,下載node_exporter

[root@cacheServer prometheus]# pwd
/usr/local/source/prometheus 
[root@cacheServer prometheus]# wget https://github.com/prometheus/node_exporter/releases/download/v1.0.0/node_exporter-1.0.0.linux-amd64.tar.gz

 

3,安裝node_exporter:

解壓縮

[root@cacheServer prometheus]# tar -zxvf node_exporter-1.0.0.linux-amd64.tar.gz

 

移動到安裝目錄

[root@cacheServer prometheus]# mv node_exporter-1.0.0.linux-amd64 /usr/local/soft/

 

查看node_exporter的版本:

[root@cacheServer ~]# /usr/local/soft/node_exporter-1.0.0.linux-amd64/node_exporter --version
node_exporter, version 1.0.0 (branch: HEAD, revision: b9c96706a7425383902b6143d097cf6d7cfd1960)
  build user:       root@3e55cc20ccc0
  build date:       20200526-06:01:48
  go version:       go1.14.3

 

5,啟動:

#nohup:忽略所有掛斷(SIGHUP)信號

#&:把進程扔到后台執行

[root@cacheServer prometheus]# nohup /usr/local/soft/node_exporter-1.0.0.linux-amd64/node_exporter &  

 

因為我用來安裝客戶端的這台機器OS版本是centos6.5,所以我們就不再編寫service文件,

如果大家的客戶端機器是centos7或centos8,可以參考這個內容:

[Unit]
Description=node_exporter
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/soft/node_exporter-1.0.0.linux-amd64/node_exporter
PrivateTmp=true
RestartSec=5
StartLimitInterval=0
Restart=always

[Install]
WantedBy=multi-user.target

 

判斷啟動是否成功?

[root@cacheServer ~]# ss -lntp | grep 9100
LISTEN     0      128                       *:9100                     *:*      users:(("node_exporter",6440,3))

經檢查可以發現node_exporter已經守護在了9100端口了

 

八,在prometheus服務端為新增的客戶端添加配置(在服務端操作)

說明:服務端在獲取客戶端的數據之前,必須能訪問客戶端上的9100端口,

大家應該先用telnet測試能否訪問,如果不能訪問,

請先檢查客戶端防火牆是否放開了從服務端ip到客戶端ip及端口的訪問

例:

[root@blog ~]$ telnet 121.122.123.118 9100
Trying 121.122.123.118...
Connected to 121.122.123.118.
Escape character is '^]'.
^]
telnet> quit
Connection closed.

 

編輯prometheus服務端的配置文件

[root@blog ~]# cd /usr/local/soft/prometheus-2.18.1.linux-amd64/
[root@blog prometheus-2.18.1.linux-amd64]# vi prometheus.yml 


在下增加一段針對118這個node_exporter的job:注意把ip換成自己安裝node_exporter客戶端的ip

- job_name: '118node'
  static_configs:
  - targets: ['121.122.123.118:9100']

說明:添加到配置文件中時要注意縮進

 

編輯完成后重啟服務

[root@blog ~]# systemctl restart prometheus.service 

 

九,測試客戶端安裝效果

登錄頁面查看效果:注意把ip換成自己的服務器ip

http://121.122.123.47:9090/targets

效果如圖:

 

 

十,查看服務器linux版本

[root@blog ~]# cat /etc/redhat-release
CentOS Linux release 8.0.1905 (Core)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM