其他分享
首页 > 其他分享> > 四、prometheus联邦配置

四、prometheus联邦配置

作者:互联网

一、基础环境

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

# 解压二进制包
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

# 在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

# 监控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

# 监控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采集联邦节点数据

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的指标数据了

 

标签:node,root,配置,node1,prometheus,usr,联邦,local
来源: https://www.cnblogs.com/zhrx/p/16027021.html