四、prometheus联邦配置
一、基础环境
1 2 3 4 5 | 192.168.88.200 prometheus # prometheus主节点 192.168.88.201 prometheus-federate1 # 联邦节点1 192.168.88.202 prometheus-federate2 # 联邦节点2 192.168.88.203 node1 192.168.88.204 node2 |
二、配置prometheus联邦
2.1、部署prometheus
prometheus主节点和两个联邦节点都部署prometheus
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | # 解压二进制包 root@prometheus:~ # tar xf /usr/local/src/prometheus-2.30.3.linux-amd64.tar.gz -C /usr/local/ root@prometheus:~ # cd /usr/local/ root@prometheus: /usr/local # ln -sv prometheus-2.30.3.linux-amd64/ prometheus 'prometheus' -> 'prometheus-2.30.3.linux-amd64/' root@prometheus: /usr/local # cd prometheus root@prometheus: /usr/local/prometheus # ls LICENSE NOTICE console_libraries consoles prometheus prometheus.yml promtool root@prometheus: /usr/local/prometheus # # prometheus.service 文件 root@prometheus:~ # cat > /etc/systemd/system/prometheus.service << EOF > [Unit] > Description=Prometheus Server > Documentation=https: //prometheus .io /docs/introduction/overview > After=network.target > > [Service] > Restart=on-failure > WorkingDirectory= /usr/local/prometheus > ExecStart= /usr/local/prometheus/prometheus --config. file = /usr/local/prometheus/prometheus .yml > > [Install] > WantedBy=multi-user.target > EOF root@prometheus:~ # # 启动 root@prometheus: /usr/local # systemctl daemon-reload root@prometheus: /usr/local # systemctl start prometheus root@prometheus: /usr/local # netstat -tnpl | grep 9090 tcp6 0 0 :::9090 :::* LISTEN 2787 /prometheus root@prometheus: /usr/local # |
2.2、部署node_exporter
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | # 在node1和node2上执行以下步骤 # 二进制解包 root@node1:~ # cd /usr/local/src/ root@node1: /usr/local/src # tar xf node_exporter-1.2.2.linux-amd64.tar.gz root@node1: /usr/local/src # cd node_exporter-1.2.2.linux-amd64/ root@node1: /usr/local/src/node_exporter-1 .2.2.linux-amd64 # ls LICENSE NOTICE node_exporter root@node1: /usr/local/src/node_exporter-1 .2.2.linux-amd64 # mv node_exporter /usr/local/bin/ root@node1: /usr/local/src/node_exporter-1 .2.2.linux-amd64 # # 创建service文件 root@node1:~ # cat > /etc/systemd/system/node-exporter.service << EOF > [Unit] > Description=Prometheus Node Exporter > After=network.target > > [Service] > ExecStart= /usr/local/bin/node_exporter > > [Install] > WantedBy=multi-user.target > EOF root@node1:~ # # 启动 root@node1:~ # systemctl daemon-reload root@node1:~ # systemctl start node-exporter root@node1:~ # netstat -tnlp | grep 9100 tcp6 0 0 :::9100 :::* LISTEN 2648 /node_exporter root@node1:~ # |
2.3、配置prometheus联邦节点监控node
分别在联邦节点1上监控node1,联邦节点2上监控node2
1 2 3 4 5 6 7 | # 监控node1 root@prometheus-federate1: /usr/local/prometheus # vim prometheus.yml ................ - job_name: "node1" static_configs: - targets: [ "192.168.88.203:9100" ] root@prometheus-federate1: /usr/local/prometheus # systemctl restart prometheus.service |
1 2 3 4 5 6 7 | # 监控node2 root@prometheus-federate2: /usr/local/prometheus # vim prometheus.yml ................ - job_name: "node2" static_configs: - targets: [ "192.168.88.204:9100" ] root@prometheus-federate2: /usr/local/prometheus # systemctl restart prometheus.service |
2.4、配置prometheus主server采集联邦节点数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | root@prometheus: /usr/local/prometheus # vim prometheus.yml .......... - job_name: "prometheus-federate-1" scrape_interval: 10s honor_labels: true metrics_path: '/federate' params: 'match[]' : - '{job="prometheus"}' - '{__name__=~"job.*"}' - '{__name__=~"node.*"}' static_configs: - targets: - '192.168.88.201:9090' - job_name: "prometheus-federate-2" scrape_interval: 10s honor_labels: true metrics_path: '/federate' params: 'match[]' : - '{job="prometheus"}' - '{__name__=~"job.*"}' - '{__name__=~"node.*"}' static_configs: - targets: - '192.168.88.202:9090' root@prometheus: /usr/local/prometheus # systemctl restart prometheus.service |
2.5、验证prometheus server数据
验证指标数据
prometheus server已经可以收集两个node的指标数据了
分类:
prometheus
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)