《安全监控体系搭建方法实战》
第3章 数据采集层技术

3. 数据采集层技术

数据采集层是安全监控体系的“感官神经”,负责从IT基础设施的各个角落收集原始数据。本节将深入剖析三大核心采集技术:日志采集、指标采集与网络流量采集,并对比其典型工具与适用场景。

3.1 日志采集:Filebeat vs Logstash

日志是系统运行状态的“黑匣子”,包含用户行为、错误堆栈、安全事件等关键信息。轻量级采集器Filebeat与重量级处理管道Logstash是ELK生态中的黄金搭档。

📄 Filebeat(轻量级采集器)

  • 定位:日志文件采集与转发
  • 资源占用:极低(Go语言编写)
  • 核心功能:文件追踪、多行合并、负载均衡
  • 输出:直接发送至Elasticsearch / Logstash / Kafka
  • 适用场景:边缘节点、容器环境、大规模部署

⚙️ Logstash(数据处理管道)

  • 定位:日志聚合、转换与增强
  • 资源占用:较高(JVM运行)
  • 核心功能:200+插件、Grok正则解析、数据脱敏
  • 输出:支持多种存储(ES、S3、HDFS)
  • 适用场景:复杂数据清洗、多源异构日志整合
应用服务器 /var/log/app.log Filebeat Logstash Elasticsearch 轻量采集 + 发送 解析 / 过滤 / 增强 存储与检索

▲ 日志采集典型架构:Filebeat → Logstash → Elasticsearch

3.2 指标采集:Prometheus Exporter

指标(Metrics)是系统健康度的“体温计”,通过数值化的方式反映CPU、内存、磁盘、网络等资源状态。Prometheus Exporter是Prometheus生态中的标准化采集适配器,将各类系统数据转换为Prometheus可识别的格式。

Exporter 名称 采集目标 默认端口 关键指标示例
node_exporter Linux/Windows 主机 9100 node_cpu_seconds_total, node_memory_MemAvailable_bytes
blackbox_exporter HTTP/HTTPS/TCP/ICMP 探测 9115 probe_success, probe_duration_seconds
mysqld_exporter MySQL 数据库 9104 mysql_global_status_connections, mysql_global_status_threads_connected
nginx_exporter Nginx 反向代理 9113 nginx_connections_active, nginx_http_requests_total
Linux 主机 MySQL 数据库 Nginx 服务 node_exporter mysqld_exporter nginx_exporter Prometheus Server (Pull)

▲ Prometheus Exporter 采集架构:Exporter 暴露 /metrics 端点,Prometheus 定期拉取

3.3 网络流量采集:sFlow vs NetFlow

网络流量数据是安全分析的“金矿”,能揭示异常连接、DDoS攻击、数据泄露等威胁。sFlow与NetFlow是两种主流的网络流量采样技术,各有侧重。

🌊 sFlow(采样+推送)

  • 采样方式:基于数据包随机采样(如1/4096)
  • 协议:UDP 推送至 Collector
  • 优势:实时性强,CPU开销极低
  • 典型场景:高速网络(10Gbps+)、实时流量监控
  • 厂商支持:HP、Arista、Dell、MikroTik

📊 NetFlow(流记录+缓存)

  • 采样方式:基于流(Flow)缓存聚合
  • 协议:UDP/TCP 导出流记录
  • 优势:提供完整流信息(IP、端口、协议、字节数)
  • 典型场景:安全审计、流量计费、应用识别
  • 厂商支持:Cisco(NetFlow v5/v9/IPFIX)、Juniper
核心交换机 sFlow / NetFlow 代理 Flow Collector sFlow-RT / ntopng 分析平台 Elasticsearch + Kibana 安全告警 异常流量检测 UDP 采样数据 流记录导出 实时流分析 历史流分析

▲ 网络流量采集与安全分析流程

3.4 实战配置示例

以下为Filebeat与Prometheus Exporter的典型配置片段,可直接用于生产环境。

Filebeat 配置(filebeat.yml)

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /var/log/nginx/access.log
    - /var/log/nginx/error.log
  fields:
    service: nginx
    env: production

output.elasticsearch:
  hosts: ["http://192.168.1.100:9200"]
  index: "filebeat-nginx-%{+yyyy.MM.dd}"

setup.kibana:
  host: "http://192.168.1.100:5601"

node_exporter 启动命令

# 下载并启动 node_exporter(监听端口 9100)
wget https://github.com/prometheus/node_exporter/releases/download/v1.6.0/node_exporter-1.6.0.linux-amd64.tar.gz
tar xvf node_exporter-1.6.0.linux-amd64.tar.gz
cd node_exporter-1.6.0.linux-amd64
./node_exporter --web.listen-address=":9100" --collector.systemd --collector.processes

sFlow 配置(以华为交换机为例)

system-view
sflow agent ip 10.0.0.1
sflow collector 1 ip 192.168.1.200 port 6343
sflow sampling-rate 4096
interface GigabitEthernet0/0/1
 sflow flow-counter collector 1
 sflow sampling enable

💡 最佳实践: 在安全监控体系中,建议采用“日志 + 指标 + 流量”三位一体的采集策略。日志用于事件溯源,指标用于性能基线,流量用于网络行为分析。三者互补,构建完整的可观测性视图。