【云原生 Prometheus篇】Prometheus的動態服務發現機制與認證配置

目錄

  • 一、Prometheus服務發現的方式
    • 1.1 基于文件的服務發現
    • 1.2 基于consul的服務發現
    • 1.3 基于 Kubernetes API 的服務發現
      • 1.3.1 簡介
      • 1.3.2 基于Kurbernetes發現機制的部分配置參數
  • 二、實例一:部署基于文件的服務發現
    • 2.1 創建用于服務發現的文件
    • 2.2 修改Prometheus的配置文件
    • 2.3 瀏覽器訪問測試
  • 三、實例二:部署基于consul的服務發現
    • 3.1 部署Consul服務
    • 3.2 在Consul 上注冊 Services
    • 3.3 修改 prometheus 配置文件

一、Prometheus服務發現的方式

1.1 基于文件的服務發現

基于文件的服務發現是僅僅略優于靜態配置的服務發現方式,它不依賴于任何平臺或第三方服務,因而也是最為簡單和通用的實現方式。

Prometheus Server 會定期從文件中加載 Target 信息,文件可使用 YAML 和 JSON 格式,它含有定義的 Target 列表,以及可選的標簽信息。

1.2 基于consul的服務發現

下載地址:https://www.consul.io/downloads/

Consul 是一款基于 golang 開發的開源工具,主要面向分布式,服務化的系統提供服務注冊、服務發現和配置管理的功能。
提供服務注冊/發現、健康檢查、Key/Value存儲、多數據中心和分布式一致性保證等功能。

1.3 基于 Kubernetes API 的服務發現

1.3.1 簡介


//基于 Kubernetes API 的服務發現
基于 Kubernetes API 的服務發現機制,支持將API Server 中 Node、Service、Endpoint、Pod 和 Ingress 等資源類型下相應的各資源對象視作 target, 并持續監視相關資源的變動●Node、Service、Endpoint、Pod 和 Ingress 資源分別由各自的發現機制進行定義●負責發現每種類型資源對象的組件,在 Prometheus 中稱為一個 role●支持在集群上基于 DaemonSet 控制器部署 node-exporter 后發現各 Node 節點,也可以通過 kubelet 來作為 Prometheus 發現各 Node 節點的入口#基于 Kubernetes 發現機制的部分配置參數
# The API server addresses. If left empty, Prometheus is assumed to run inside of the cluster and will discover API servers automatically
and use the pod's
# CA certificate and bearer token file at /var/run/secrets/kubernetes.io/serviceaccount/.
[ api_server: <host> ]# The Kubernetes role of entities that should be discovered. One of endpoints, service, pod, node, or ingress.
role: <string># Optional authentication information used to authenticate to the API server.
# Note that 'basic_auth', 'bearer_token'和'bearer_token_file' 等認證方式互斥;
[ bearer_token: <secret> ]
[ bearer_token_file: <filename> ]# TLS configuration.
tls_config:
# CA certificate to validate API server certificate with.
[ ca_file: <filename> ]# Certificate and key files for client cert authentication to the server.
[ cert_file: <filename> ]
[ key_file: <filename> ]# ServerName extension to indicate the name of the server.
[ server_name: <string> ]# Optional namespace discovery. If omitted, all namespaces are used.
namespaces:
names:
[ - <string> ]

1.3.2 基于Kurbernetes發現機制的部分配置參數

# The API server addresses. If left empty, Prometheus is assumed to run inside of the cluster and will discover API servers automatically
and use the pod's
# CA certificate and bearer token file at /var/run/secrets/kubernetes.io/serviceaccount/.
[ api_server: <host> ]# The Kubernetes role of entities that should be discovered. One of endpoints, service, pod, node, or ingress.
role: <string># Optional authentication information used to authenticate to the API server.
# Note that 'basic_auth', 'bearer_token'和'bearer_token_file' 等認證方式互斥;
[ bearer_token: <secret> ]
[ bearer_token_file: <filename> ]# TLS configuration.
tls_config:
# CA certificate to validate API server certificate with.
[ ca_file: <filename> ]# Certificate and key files for client cert authentication to the server.
[ cert_file: <filename> ]
[ key_file: <filename> ]# ServerName extension to indicate the name of the server.
[ server_name: <string> ]# Optional namespace discovery. If omitted, all namespaces are used.
namespaces:
names:
[ - <string> ]

二、實例一:部署基于文件的服務發現

2.1 創建用于服務發現的文件

新建工作目錄

cd /usr/local/prometheusmkdir targets

在文件中配置所需的 target

vim targets/node-exporter.yaml
- targets:- 192.168.2.108:9100- 192.168.2.106:9100labels:app: node-exporterjob: nodevim targets/mysqld-exporter.yaml
- targets:- 192.168.2.108:9104- 192.168.2.106:9104labels:app: mysqld-exporterjob: mysqld

2.2 修改Prometheus的配置文件

修改 prometheus 配置文件,發現 target 的配置,定義在配置文件的 job 之中。

vim /usr/local/prometheus/prometheus.yml
......
scrape_configs:- job_name: nodesfile_sd_configs:                  #指定使用文件服務發現- files:                          #指定要加載的文件列表- targets/node*.yaml            #文件加載支持通配符refresh_interval: 2m            #每隔 2 分鐘重新加載一次文件中定義的 Targets,默認為 5m- job_name: mysqldfile_sd_configs:- files:- targets/mysqld*.yamlrefresh_interval: 2m

在這里插入圖片描述

2.3 瀏覽器訪問測試

#先重啟服務
systemctl reload prometheus
#然后
瀏覽器查看 Prometheus 頁面的 Status -> Targets

在這里插入圖片描述

三、實例二:部署基于consul的服務發現

3.1 部署Consul服務

cd /opt/
unzip consul_1.9.2_linux_amd64.zip
mv consul /usr/local/bin/
#創建 Consul 服務的數據目錄和配置目錄
mkdir /var/lib/consul-data
mkdir /etc/consul/
#使用 server 模式啟動 Consul 服務
consul agent \
-server \
-bootstrap \
-ui \
-data-dir=/var/lib/consul-data \
-config-dir=/etc/consul/ \
-bind=192.168.2.108 \
-client=0.0.0.0 \
-node=consul-server01 &> /var/log/consul.log &
#查看 consul 集群成員
consul members

在這里插入圖片描述

3.2 在Consul 上注冊 Services

#在配置目錄中添加文件
vim /etc/consul/nodes.json
{"services": [{"id": "node_exporter-node01","name": "node01","address": "192.168.2.108","port": 9100,"tags": ["nodes"],"checks": [{"http": "http://192.168.2.108:9100/metrics","interval": "5s"}]},{"id": "node_exporter-node02","name": "node02","address": "192.168.2.106","port": 9100,"tags": ["nodes"],"checks": [{"http": "http://192.168.2.106:9100/metrics","interval": "5s"}]}]
}
#讓 consul 重新加載配置信息
consul reload		瀏覽器訪問:http://192.168.2.108:8500

在這里插入圖片描述

3.3 修改 prometheus 配置文件

vim /usr/local/prometheus/prometheus.yml
......- job_name: nodesconsul_sd_configs:                  #指定使用 consul 服務發現- server: 192.168.2.108:8500        #指定 consul 服務的端點列表tags:                             #指定 consul 服務發現的 services 中哪些 service 能夠加入到 prometheus 監控的標簽- nodesrefresh_interval: 2m

在這里插入圖片描述

systemctl reload prometheus
瀏覽器查看 Prometheus 頁面的 Status -> Targets

在這里插入圖片描述

#讓 consul 注銷 Service
consul services deregister -id="node_exporter-node02"#重新注冊
consul services register /etc/consul/nodes.json

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/167645.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/167645.shtml
英文地址,請注明出處:http://en.pswp.cn/news/167645.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

yo!這里是c++11重點新增特性介紹

目錄 前言 列表初始化 { }初始化 initializer_list類 類型推導 auto decltype 范圍for 右值引用與移動語義 左值引用和右值引用 移動語義 1.移動構造 2.移動賦值 3.stl容器相關更新 右值引用和萬能引用 完美轉發 關鍵字 default delete final和override …

西米支付:簡單介紹一下支付公司的分賬功能體系

隨著互聯網的普及和電子商務的快速發展&#xff0c;支付已經成為人們日常生活的重要組成部分。支付公司作為第三方支付平臺&#xff0c;為消費者和商家提供了便捷、安全的支付方式。而在支付領域中&#xff0c;分賬功能是一個非常重要的功能&#xff0c;它可以幫助企業實現資金…

SpringBoot——攔截器

優質博文&#xff1a;IT-BLOG-CN 一、登錄時可能會出現重復提交問題。我們可以通過重定向解決此問題。例如&#xff1a;用戶提交的請求為&#xff1a;/user/login&#xff0c;通過redirect&#xff1a;重定向至 main.html請求。 PostMapping("/user/login") public …

C語言——從終端(鍵盤)將 5 個整數輸入到數組 a 中,然后將 a 逆序復制到數組 b 中,并輸出 b 中 各元素的值。

#define _CRT_SECURE_NO_WARNINGS 1#include<stdio.h> int main() {int i;int a[5];int b[5];printf("輸入5個整數&#xff1a;\n");for(i0;i<5;i){scanf("%d",&a[i]);}printf("數組b的元素值為&#xff1a;\n");for(i4;i>0;i--…

Windows任務管理器內存性能界面各個參數含義

任務管理器的內存性能界面提供了一些關鍵參數&#xff0c;這些參數可以幫助你了解系統中內存的使用情況。以下是一些常見的參數及其含義&#xff1a; 已提交&#xff08;Committed&#xff09;&#xff1a; 表示已分配的物理內存和虛擬內存的總和。已提交的內存包括當前正在使…

Javascript每天一道算法題(十五)——輪轉數組_中等(一行解決輪轉數組)

文章目錄 1、問題2、示例3、解決方法&#xff08;1&#xff09;方法1——while遍歷&#xff08;較為復雜&#xff0c;不推薦&#xff09;&#xff08;2&#xff09;方法2&#xff08;直接截取后插入&#xff0c;推薦&#xff09;&#xff08;3&#xff09;方法3——優化方法2&a…

jQuery_03 dom對象和jQuery對象的互相轉換

dom對象和jQuery對象 dom對象 jQuery對象 在一個文件中同時存在兩種對象 dom對象: 通過js中的document對象獲取的對象 或者創建的對象 jQuery對象: 通過jQuery中的函數獲取的對象。 為什么使用dom或jQuery對象呢&#xff1f; 目的是 要使用dom對象的函數或者屬性 以及呢 要…

python -opencv 輪廓檢測(多邊形,外接矩形,外接圓)

python -opencv 輪廓檢測(多邊形&#xff0c;外接矩形&#xff0c;外接圓) 邊緣檢測步驟: 第一步&#xff1a;讀取圖像為灰度圖 第二步&#xff1a;進行二值化處理 第三步&#xff1a;使用cv2.findContours對二值化圖像提取輪廓 第三步&#xff1a;將輪廓繪制到圖中 代碼如下…

Hibernate的三種狀態

1.瞬時狀態(Transient) 通過new創建對象后&#xff0c;對象并沒有立刻持久化&#xff0c;他并未對數據庫中的數據有任何的關聯&#xff0c;此時java對象的狀態為瞬時狀態&#xff0c;Session對于瞬時狀態的java對象是一無所知的&#xff0c;當對象不再被其他對象引用時&#xf…

【TL431+場效應管組成過壓保護電路】2022-3-22

緣由這個穩壓三極管是構成的電路是起到保護的作用嗎&#xff1f;-硬件開發-CSDN問答

HTML5+ API 爬坑記錄

背景: 有個比較早些使用5開發的項目, 最近兩天反饋了一些問題, 解決過程在此記錄; 坑1: plus.gallery.pick 選擇圖片沒有進入回調 HTML5 API Reference 在 聯想小新 平板電腦上選擇相冊圖片進行上傳時, 打開相冊瞬間 應用會自動重啟, 相冊倒是有打開, 不過應用重啟了, 導…

使用正則表達式來判斷一個字符串只是否包含數字

使用正則表達式來判斷一個字符串只是否包含數字 1、第一種 import java.util.regex.Pattern;public class Main {public static void main(String[] args) {String inputString "12345";if (containsOnlyDigits(inputString)) {System.out.println("字符串只…

文件url 轉File

// param url : http://xxx.xxx.xx.jpg public static File getFile(String url) throws Exception {//對本地?件命名String fileName url.substring(url.lastIndexOf("."),url.length());File file null;URL urlfile;InputStream inStream null;OutputStream os…

[原創](免改BIOS)使用Clover升級舊電腦-(高階玩法)讓固態硬盤內置Win11 PE啟動系統

[簡介] 常用網名: 豬頭三 出生日期: 1981.XX.XXQQ: 643439947 個人網站: 80x86匯編小站 https://www.x86asm.org 編程生涯: 2001年~至今[共22年] 職業生涯: 20年 開發語言: C/C、80x86ASM、PHP、Perl、Objective-C、Object Pascal、C#、Python 開發工具: Visual Studio、Delphi…

【算法專題】滑動窗口—無重復字符的最長子串

力扣題目鏈接&#xff1a;無重復字符的最長子串 一、題目解析 二、算法原理 解法一&#xff1a;暴力解法&#xff08;時間復雜度最壞&#xff1a;O(N)&#xff09; 從每一個位置開始往后枚舉&#xff0c;在往后尋找無重復最長子串時&#xff0c;可以利用哈希表來統計字符出現…

手機APP-MCP走藍牙無線遙控智能安全帽~執法記錄儀~拍照錄像,并可做基礎的配置,例如修改服務器IP以及配置WiFi等

手機APP-MCP走藍牙無線遙控智能安全帽~執法記錄儀~拍照錄像,并可做基礎的配置,例如修改服務器IP以及配置WiFi等 手機APP-MCP走藍牙無線遙控智能安全帽~執法記錄儀~拍照錄像,并可做基礎的配置,例如修改服務器IP以及配置WiFi等&#xff0c; AIoT萬物智聯&#xff0c;智能安全帽…

Java 文件操作

文章目錄 Java 文件操作構造方法文件屬性操作文件內容操作InputStreamReaderOutputStreamWriter 更多案例文件查找普通文件的復制 Java 文件操作 Java 中通過 java.io.File 類來對文件進行描述。 構造方法 構造方法說明File(String pathname)通過路徑名字符串來創建 File 實…

JVM之jvisualvm多合一故障處理工具

jvisualvm多合一故障處理工具 1、visualvm介紹 VisualVM是一款免費的&#xff0c;集成了多個 JDK 命令行工具的可視化工具&#xff0c;它能為您提供強大的分析能力&#xff0c;對 Java 應 用程序做性能分析和調優。這些功能包括生成和分析海量數據、跟蹤內存泄漏、監控垃圾回…

SpringBoot:異步任務基礎與源碼剖析

官網文檔&#xff1a;How To Do Async in Spring | Baeldung。 Async注解 Spring框架基于Async注解提供了對異步執行流程的支持。 最簡單的例子是&#xff1a;使用Async注解修飾一個方法&#xff0c;那么這個方法將在一個單獨的線程中被執行&#xff0c;即&#xff1a;從同步執…

系列六、Spring整合單元測試

一、概述 Spring中獲取bean最常見的方式是通過ClassPathXmlApplicationContext 或者 AnnotationConfigApplicationContext的getBean()方式獲取bean&#xff0c;那么在Spring中如何像在SpringBoot中直接一個類上添加個SpringBootTest注解&#xff0c;即可在類中注入自己想要測試…