Advertisement

y86.第四章 Prometheus大厂监控体系及实战 -- prometheus存储(十七)

阅读量:

14.2 远端存储之–VictoriaMetrics

https://github.com/VictoriaMetrics/VictoriaMetrics

https://docs.victoriametrics.com/Single-server-VictoriaMetrics.html

在这里插入图片描述

14.2.1 单机

下载:

复制代码
    root@prometheus3:~# wget https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.77.2/victoria-metrics-amd64-v1.77.2.tar.gz
    
    
      
    
    AI助手
14.2.1.1 部署单机版
复制代码
    root@prometheus3:~# tar xf victoria-metrics-amd64-v1.77.2.tar.gz
    
    参数:
    -httpListenAddr=0.0.0.0:8428 #监听地址及端口
    -storageDataPath #VictoriaMetrics将所有数据存储在此目录,默认为执行启动Victoria的当前目录下的victoria-metrics-data目录中。
    -retentionPeriod #存储数据的保留,较旧的数据会自动删除,默认保留为1个月,默认单位为m(月),支持的单位有h(hour)、d(day)、w(week)、y(year)。
    
    root@prometheus3:~# mv victoria-metrics-prod /usr/local/bin/
    
    service启动文件:
    root@prometheus3:~# vim /etc/systemd/system/victoria-metrics-prod.service
    [Unit]
    Description=For Victoria-metrics-prod service
    After=network.target
    
    [Service]
    ExecStart=/usr/local/bin/victoria-metrics-prod -httpListenAddr=0.0.0.0:8428 -storageDataPath=/data/victoria -retentionPeriod=3
    
    [Install]
    WantedBy=multi-user.target
    
    root@prometheus3:~# systemctl enable --now victoria-metrics-prod
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手

验证web页面:

http://172.31.2.103:8428/

在这里插入图片描述
14.2.1.2 prometheus设置
复制代码
    root@prometheus1:/apps/prometheus# vim 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).
    
    remote_write:
      - url: http://172.31.2.103:8428/api/v1/write 
    
    
      
      
      
      
      
      
      
      
      
    
    AI助手
14.2.1.3 验证VictoriaMetrics数据

http://172.31.2.103:8428/vmui/

在这里插入图片描述
14.2.1.4 grafana设置

添加数据源:

类型为prometheus,地址及端口为VictoriaMetrics:

在这里插入图片描述

把prometheus数据源地址和端口改成VictoriaMetrics的

导入指定模板:

8919:

在这里插入图片描述
14.2.1.5 验证数据
在这里插入图片描述

11074:

在这里插入图片描述

14.2.2 官方docker-compose

访问该仓库的容器部署分支:https://github.com/VictoriaMetrics/VictoriaMetrics/tree/cluster/deployment/docker

复制代码
    git clone https://github.com/VictoriaMetrics/VictoriaMetrics.git
    
    root@k8s-harbor1:~# git clone https://gitee.com/raymond9/VictoriaMetrics.git
    
    root@k8s-harbor1:~# cd VictoriaMetrics/deployment/docker/
    
    root@k8s-harbor1:~/VictoriaMetrics/deployment/docker# ll
    total 64
    drwxr-xr-x 5 root root  4096 May 31 22:13 ./
    drwxr-xr-x 4 root root  4096 May 31 22:13 ../
    -rw-r--r-- 1 root root  6312 May 31 22:13 Makefile
    -rw-r--r-- 1 root root  1495 May 31 22:13 README.md
    -rw-r--r-- 1 root root    61 May 31 22:13 alertmanager.yml
    -rw-r--r-- 1 root root 17025 May 31 22:13 alerts.yml
    drwxr-xr-x 2 root root  4096 May 31 22:13 base/
    drwxr-xr-x 2 root root  4096 May 31 22:13 builder/
    -rw-r--r-- 1 root root  2843 May 31 22:13 docker-compose.yml
    -rw-r--r-- 1 root root   298 May 31 22:13 prometheus.yml
    drwxr-xr-x 4 root root  4096 May 31 22:13 provisioning/
    
    root@k8s-harbor1:~/VictoriaMetrics/deployment/docker# docker-compose up -d
    
    root@k8s-harbor1:~/VictoriaMetrics/deployment/docker# grep "image:" docker-compose.yml 
    image: victoriametrics/vmagent
    image: victoriametrics/victoria-metrics
    image: grafana/grafana:8.5.1
    image: victoriametrics/vmalert
    image: prom/alertmanager
    
    root@k8s-harbor1:~/VictoriaMetrics/deployment/docker# docker pull registry.cn-beijing.aliyuncs.com/raymond9/vmagent
    root@k8s-harbor1:~/VictoriaMetrics/deployment/docker# docker pull registry.cn-beijing.aliyuncs.com/raymond9/victoria-metrics
    root@k8s-harbor1:~/VictoriaMetrics/deployment/docker# docker pull registry.cn-beijing.aliyuncs.com/raymond9/grafana:8.5.1
    root@k8s-harbor1:~/VictoriaMetrics/deployment/docker# docker pull registry.cn-beijing.aliyuncs.com/raymond9/vmalert
    root@k8s-harbor1:~/VictoriaMetrics/deployment/docker# docker pull registry.cn-beijing.aliyuncs.com/raymond9/alertmanager
    
    root@k8s-harbor1:~/VictoriaMetrics/deployment/docker# docker-compose up -d
    Creating victoriametrics ... done
    Creating alertmanager    ... done
    Creating grafana         ... done
    Creating vmalert         ... done
    Creating vmagent         ... done
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手

http://172.31.7.104:8428/

在这里插入图片描述

14.2.3 集群版本

在这里插入图片描述
14.2.3.1 组件介绍
复制代码
    vminsert #写入组件(写),vminsert负责接收数据写入并根据对度量名称及其所有标签的一致hash结果将数据分散写入不同的后端vmstorage节点之间vmstorage,vminsert默认端口8480。
    
    vmstorage #存储原始数据并返回给定时间范围内给定标签过滤器的查询数据,默认端口8482。
    vmselect #查询组件(读),连接vmstorage,默认端口8481.
    
    其它可选组件:
    vmagent #是一个很小但功能强大的代理,它可以从node_exporter各种来源收集度量数据,并将它们存储在VictoriaMetrics或任何其它支持远程写入的与prometheus兼容的存储系统中,有替代prometheus server的意向。
    
    
      
      
      
      
      
      
      
    
    AI助手
在这里插入图片描述
复制代码
    vmalert:替换prometheus server,以VictoriaMetrics为数据源,基于兼容prometheus的告警规则,判断数据是否异常,并将产生的通知发送给alertermanager。
    
    Vmgateway:读写VictoriaMetrics数据的代理网关,可实现限速和访问控制等功能,目前为企业版组件。
    vmctl: VictoriaMetrics的命令行工具,目前主要用于将prometheus、opentsdb等数据源迁移到VictoriaMetrics。
    
    
      
      
      
      
    
    AI助手

下载:

复制代码
    root@node1:~# wget https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.77.2/victoria-metrics-amd64-v1.77.2-cluster.tar.gz
    
    
      
    
    AI助手
14.2.3.2 部署集群

分别在各个VictoriaMetrics服务器进行安装配置:

复制代码
    root@node1:~# tar xf victoria-metrics-amd64-v1.77.2-cluster.tar.gz 
    
    root@node1:~# mv vminsert-prod vmstorage-prod vmselect-prod /usr/local/bin/
    
    主要参数:
      -httpListenAddr string
    	Address to listen for http connections (default ":8482")
      -vminsertAddr string
    	TCP address to accept connections from vminsert services (default ":8400")
      -vmselectAddr string
    	TCP address to accept connections from vmselect services (default ":8401")
    
    
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手
14.2.3.2.1 部署vmstorage-prod组件
复制代码
    root@node1:~# vim /etc/systemd/system/vmstorage.service
    [Unit]
    Description=Vmstorage Server
    After=network.target
    
    [Service]
    ExecStart=/usr/local/bin/vmstorage-prod -loggerTimezone Asia/Shanghai -storageDataPath /data/vmstorage-data -httpListenAddr :8482 -vminsertAddr :8400 -vmselectAddr :8401
    
    [Install]
    WantedBy=multi-user.target
    
    root@node1:~# systemctl enable --now vmstorage
    
    root@node1:~# scp /etc/systemd/system/vmstorage.service 172.31.2.182:/etc/systemd/system/  
    root@node1:~# scp /etc/systemd/system/vmstorage.service 172.31.2.183:/etc/systemd/system/
    
    root@node1:~# scp /usr/local/bin/vm* 172.31.2.182:/usr/local/bin
    root@node1:~# scp /usr/local/bin/vm* 172.31.2.183:/usr/local/bin
    
    root@node2:~# systemctl enable --now vmstorage
    root@node3:~# systemctl enable --now vmstorage
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手
14.2.3.2.2 部署vminsert-prod组件
复制代码
    root@node1:~# vim /etc/systemd/system/vminsert.service
    [Unit]
    Description=Vminsert Server
    After=network.target
    
    [Service]
    Restart=on-failure
    WorkingDirectory=/tmp
    ExecStart=/usr/local/bin/vminsert-prod -httpListenAddr :8480 -storageNode=172.31.2.181:8400,172.31.2.182:8400,172.31.2.183:8400
    
    [Install]
    WantedBy=multi-user.target
    
    root@node1:~# systemctl enable --now vminsert
    
    root@node1:~# scp /etc/systemd/system/vminsert.service 172.31.2.182:/etc/systemd/system/   
    root@node1:~# scp /etc/systemd/system/vminsert.service 172.31.2.183:/etc/systemd/system/
    
    root@node2:~# systemctl enable --now vminsert
    root@node3:~# systemctl enable --now vminsert
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手
14.2.3.2.3 部署vmselect-prod组件
复制代码
    root@node1:~# vim /etc/systemd/system/vmselect.service
    [Unit]
    Description=Vmselect Server
    After=network.target
    
    [Service]
    Restart=on-failure
    WorkingDirectory=/tmp
    ExecStart=/usr/local/bin/vmselect-prod -httpListenAddr :8481 -storageNode=172.31.2.181:8401,172.31.2.182:8401,172.31.2.183:8401
    
    [Install]
    WantedBy=multi-user.target
    
    root@node1:~# systemctl enable --now vmselect
    
    root@node1:~# scp /etc/systemd/system/vmselect.service 172.31.2.182:/etc/systemd/system/ 
    root@node1:~# scp /etc/systemd/system/vmselect.service 172.31.2.183:/etc/systemd/system/
    
    root@node2:~# systemctl enable --now vmselect
    root@node3:~# systemctl enable --now vmselect
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手
14.2.3.2.4 验证服务端口
复制代码
    181:
    root@node1:~# curl 172.31.2.181:8480/metrics
    root@node1:~# curl 172.31.2.181:8481/metrics
    root@node1:~# curl 172.31.2.181:8482/metrics
    
    182:
    root@node2:~# curl 172.31.2.182:8480/metrics
    root@node2:~# curl 172.31.2.182:8481/metrics
    root@node2:~# curl 172.31.2.182:8482/metrics
    
    183:
    root@node3:~# curl 172.31.2.183:8480/metrics
    root@node3:~# curl 172.31.2.183:8481/metrics
    root@node3:~# curl 172.31.2.183:8482/metrics
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手
14.2.3.3 prometheus配置
复制代码
    root@prometheus1:/apps/prometheus# vim 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).
    
    remote_write:
      - url: http://172.31.2.181:8480/insert/1/prometheus
      - url: http://172.31.2.182:8480/insert/1/prometheus
      - url: http://172.31.2.183:8480/insert/1/prometheus  
    ...
    
    root@prometheus1:/apps/prometheus# systemctl restart prometheus
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手
14.2.3.4 配置负载均衡
复制代码
    root@k8s-ha1:~# vim /etc/haproxy/haproxy.cfg
    ...
    listen kubernetes-8481
    bind 172.31.7.189:8481
    mode tcp
    log global
    server 172.31.2.181 172.31.2.181:8481 check inter 3s fall 2 rise 5
    server 172.31.2.182 172.31.2.182:8481 check inter 3s fall 2 rise 5
    server 172.31.2.183 172.31.2.183:8481 check inter 3s fall 2 rise 5
    
    root@k8s-ha1:~# systemctl restart haproxy
    
    root@k8s-ha2:~# vim /etc/haproxy/haproxy.cfg
    ...
    listen kubernetes-8481
    bind 172.31.7.189:8481
    mode tcp
    log global
    server 172.31.2.181 172.31.2.181:8481 check inter 3s fall 2 rise 5
    server 172.31.2.182 172.31.2.182:8481 check inter 3s fall 2 rise 5
    server 172.31.2.183 172.31.2.183:8481 check inter 3s fall 2 rise 5
    
    root@k8s-ha2:~# systemctl restart haproxy
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
    AI助手
.14.2.3.5 grafana配置数据源
https://github.com/VictoriaMetrics/VictoriaMetrics#grafana-setup
14.2.3.6 添加数据源

http://172.31.7.189:8481/select/1/prometheus

在这里插入图片描述

导入指定模版:

13824:

在这里插入图片描述

验证数据:

在这里插入图片描述

11074:

在这里插入图片描述

14.2.4 开启数据复制

https://docs.victoriametrics.com/Cluster-VictoriaMetrics.html#replication-and-data-safety

默认情况下,默认情况下,
数据通过vminsert组件采用哈希算法分别持久化到不同的vmstorage节点。
同时支持-replicationFactor=N 复制功能。
在各个节点存储完整副本的数据以保证数据的高可用性。

全部评论 (0)

还没有任何评论哟~