VictoriaLogs Grafana Filebeat - 构建轻量高性能日志管理平台

36 天前
Songxwn  Songxwn

VFG 技术架构

Filebeat 接收 Syslog ,并进行日志分段,VictoriaLogs  持久化存储日志 ,Grafana 可视化、数据查询、告警、数据导出。

为什么要用 VictoriaLogs ?

简介

Docker 国内安装

https://mirror.nju.edu.cn/mirrorz-help/docker-ce/?mirror=NJU

Docker Hub 国内加速

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
    "registry-mirrors": [
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn"
    ]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

部署 VictoriaLogs

创建 victoria-logs-data 文件夹

docker run -d --restart always \
  -p 9428:9428 \
  -v ./victoria-logs-data:/victoria-logs-data \
  --name victoria-logs-syslog-songxwn.com \
  docker.io/victoriametrics/victoria-logs:latest \
  --retentionPeriod=365d





# by songxwn.com

部署 Grafana

docker run -d --name=grafana -p 3000:3000 \
 -e GF_INSTALL_PLUGINS=victoriametrics-logs-datasource \
 --name Grafana \
 grafana/grafana-enterprise

Grafana 接入 VictoriaLogs 数据源

插件已默认安装,添加对应数据源即可,目标为 http://192.168.1.1:9428

Filebeat 部署 - 接收 Syslog ,输出到 VL

vim filebeat.docker.yml

filebeat.inputs:
  - type: udp
    enabled: true
    max_message_size: 10KiB
    host: "0.0.0.0:514"
    fields:
      type: udp

output.elasticsearch:
  hosts: ["http://127.0.0.1:9428/insert/elasticsearch/"]
  parameters:
    _msg_field: "message"
    _time_field: "@timestamp"
    _stream_fields: "host.hostname"
  allow_older_versions: true

PS:注意 127.0.0.1 替换为宿主机 IP.

运行

docker run -d  \
  --name Filebeat \
  --user=root \
  --volume="$(pwd)/filebeat.docker.yml:/usr/share/filebeat/filebeat.yml:ro" \
  -p 514:514/udp \
  docker.elastic.co/beats/filebeat:8.17.2

Docker compose 一把梭

创建并进入 /opt/VFG 文件夹

mkdir /opt/VFG

cd /opt/VFG

filebeat 配置文件 - vim filebeat.docker.yml

http:
  enabled: true
  host: "http://0.0.0.0:5066"


filebeat.inputs:
  - type: udp
    enabled: true
    max_message_size: 10KiB
    host: "0.0.0.0:514"
    fields:
      type: udp

output.elasticsearch:
  hosts: ["http://syslog-victoria-logs:9428/insert/elasticsearch/"]
  parameters:
    _msg_field: "message"
    _time_field: "@timestamp"
    _stream_fields: "host.hostname"
  allow_older_versions: true

PS:如果需要字段分割,可以参考如下。增加到输入输出中间即可。

processors:
  - dissect:
      tokenizer: "<%{syslog_pri}>%{timestamp} %{hostname} %%{log_level}/%{log_code}/%{log_action}(l):IPVer=%{ipver},Protocol=%{protocol},SourceIP=%{source_ip},DestinationIP=%{destination_ip},SourcePort=%{source_port},DestinationPort=%{destination_port},SourceNatIP=%{source_nat_ip},SourceNatPort=%{source_nat_port},BeginTime=%{begin_time},EndTime=%{end_time},S>
      field: "message"
      target_prefix: "parsed"

victoria-logs 数据目录

mkdir victoria-logs-data

chown -R 472:472 victoria-logs-data

Grafana 数据目录和配置文件

mkdir grafana-data

chown -R 472:472 grafana-data

数据源配置文件

mkdir -p ./provisioning/datasources

vim ./provisioning/datasources/vm.yml

apiVersion: 1
datasources:
    # <string, required> Name of the VictoriaLogs datasource
    # displayed in Grafana panels and queries.
  - name: VictoriaLogs-songxwn.com
    # <string, required> Sets the data source type.
    type: victoriametrics-logs-datasource
    # <string, required> Sets the access mode, either
    # proxy or direct (Server or Browser in the UI).
    access: proxy
    # <string> Sets URL for sending queries to VictoriaLogs server.
    # see https://docs.victoriametrics.com/victorialogs/querying/
    url: http://syslog-victoria-logs:9428
    # <string> Sets the pre-selected datasource for new panels.
    # You can set only one default data source per organization.
    isDefault: true

vim docker-compose.yml 文件

services:
  victoria-logs:
    image: victoriametrics/victoria-logs:latest
    container_name: syslog-victoria-logs
    volumes:
      - ./victoria-logs-data:/victoria-logs-data
    restart: always
    command: [
      "--retentionPeriod=365d"
    ]
    environment:
      - TZ=Asia/Shanghai
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:9428/health"]
      interval: 1m30s
      timeout: 10s
      retries: 3

  grafana:
    image: grafana/grafana-enterprise
    container_name: syslog-grafana
    ports:
      - "3000:3000"
    environment:
      - GF_INSTALL_PLUGINS=victoriametrics-logs-datasource
      - GF_SECURITY_ADMIN_PASSWORD=Songxwn.com
      - TZ=Asia/Shanghai
    volumes:
      - ./grafana-data:/var/lib/grafana
      - ./provisioning:/etc/grafana/provisioning
    restart: always
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3000/api/health"]
      interval: 1m30s
      timeout: 10s
      retries: 3

  filebeat:
    image: docker.elastic.co/beats/filebeat:8.17.2
    container_name: syslog-filebeat
    ports:
      - "514:514/udp"
    volumes:
      - ./filebeat.docker.yml:/usr/share/filebeat/filebeat.yml:ro
    restart: always
    environment:
      - TZ=Asia/Shanghai
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:5066"]
      interval: 60s
      timeout: 10s
      retries: 3

compose 启动命令 (需要 Docker Engine 19.03.0 以上版本)


docker compose up -d

停止、升级


docker compose down

dcker compose pull

docker compose up -d

compose 文件说明

1. Victoria-Logs 服务

2. Grafana 服务

3. Filebeat 服务

这些配置用来部署和管理 Victoria-Logs 、Grafana 和 Filebeat 服务,确保它们处于良好运行状态,且在故障发生时可以自动恢复。各自的健康检查提供了针对服务运行状态的简易确认方式,进一步提高系统的稳定性和可靠性。

VFG Compose 部署使用

Grafana 示例

资源占用 - 有较高日志输入的情况下

CONTAINER ID   NAME                   CPU %     MEM USAGE / LIMIT     MEM %     NET I/O           BLOCK I/O        PIDS
1c7fe73fc896   syslog-filebeat        0.52%     63.14MiB / 3.822GiB   1.61%     14.1MB / 5.38MB   0B / 8.19kB      15
4a6ee8b19475   syslog-grafana         0.61%     147.3MiB / 3.822GiB   3.76%     9.85MB / 12.8MB   299kB / 305MB    33
a80d91af294c   syslog-victoria-logs   0.04%     195.7MiB / 3.822GiB   5.00%     5.4MB / 604kB     520kB / 6.86MB   14

通过 Git 下载 Compose 文件


git clone https://github.com/Songxwn/VGF-Docker-compose.git

cd VGF-Docker-compose

chown -R 472:472 grafana-data

chown -R 472:472 victoria-logs-data

docker compose up -d

docker ps

# 查看状态,两分钟之后应该都是 healthy

运维技术交流群

发送邮件到 ➡️ me@songxwn.com

或者关注 WX 公众号:网工格物

博客(最先更新)

https://songxwn.com/

1180 次点击
所在节点    程序员
8 条回复
RedisMasterNode
35 天前
VL 没有集群版本的就是玩具
spritecn
35 天前
强烈推荐 openObserve,原生支持 Filebeat,自带的查询和面板也够用
https://github.com/openobserve/openobserve
下面是我搭的时候的一些备忘
https://blog.jascript.cn/posts/OpenObserve 日志方案.html
spritecn
35 天前
话说怎么把下面这个连接连到一起
https://blog.jascript.cn/posts/OpenObserve 日志方案.html
只能这样,看到以后写博客标题不能带空格
https%3A%2F%2Fblog.jascript.cn%2Fposts%2FOpenObserve%20%E6%97%A5%E5%BF%97%E6%96%B9%E6%A1%88.html
wei2629
35 天前
@spritecn #2 有大规模的使用吗。 感觉性能一般, 集群方案的后端用的 s3. 在查询性能上能跟的上吗?
defunct9
35 天前
不错不错
spritecn
35 天前
@wei2629 iot 场景,一天 2500 万左右日志,根据设备号做了 8 个分区,根据设备号查一天日志数据在 2371ms,我是 ecs+oss,同区域走内网流量的,网络不是问题,我用的是是 ecs 2c2g 的经济型实例,瓶颈在 SSD 的 IOPS 和内存缓存上
tcpdump
35 天前
检索能力很差的 尤其是全文,如果日志格式不规范,更是灾难
ericFork
35 天前
用来替代了 graylog ,搭配 vector ,还是轻量高效不少的

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1112137

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX