ELK Packetbeat 部署指南(15th)


Packetbeat 是一个实时网络数据包分析工具,与elasticsearch一体来提供应用程序的监控和分析系统。

Packetbeat通过嗅探应用服务器之间的网络通讯,来解码应用层协议类型如HTTP、MySQL、redis等等,关联请求与响应,并记录每个事务有意义的字段。

Packetbeat可以帮助我们快速发现后端应用程序的问题,如bug或性能问题等等,修复排除故障也很快捷。

Packetbeat目前支持的协议有:

  • HTTP
  • MySQL
  • PostgreSQL
  • Redis
  • Thrift-RPC
  • MongoDB
  • DNS
  • Memcache

Packetbeat可以将相关事务直接插入到elasticsearch或redis(不推荐)或logstash。

Packetbeat可以运行在应用服务器上或者独自的服务器。当运行在独自服务器上时,需要从交换机的镜像端口或者窃听设备上获取网络流量。

对第七层信息解码后,Packetbeat关联与请求相关的响应,称之为事务。每个事务,Packetbeat插入一个json格式文档到elasticsearch。然后可通过kibana进行分析展示。

安装

先配置beats yum 源,参见前文。

# yum install packetbeat

配置

选择要从哪个网卡嗅探网络通讯,默认是所有的网络接口。

interfaces:  # Select on which network interfaces to sniff. You can use the "any"  # keyword to sniff on all connected interfaces.  device: any

在协议部分,配置端口以便Packetbeat找到每个端口对应的协议。如果使用非标准端口,需要添加上。多个端口以逗号分隔。

protocols:  # Configure which protocols to monitor and on which ports are they  # running. You can disable a given protocol by commenting out its  # configuration.  http:    ports: [80, 8080, 8081, 5000, 8002]  memcache:    ports: [11211]  mysql:    ports: [3306]  redis:    ports: [6379]  pgsql:    ports: [5432]  thrift:    ports: [9090]

定义elasticsearch服务

output:  elasticsearch:    # Uncomment out this option if you want to output to Elasticsearch. The    # default is false.    enabled: true    # Set the host and port where to find Elasticsearch.    host: 192.168.1.42    port: 9200    # Uncomment this option and set it to true if you want to store the topology in    # Elasticsearch. Default behavior if this setting is left out of the    # config file is equivalent to setting "save_topology" to "false"    #save_topology: false

加载elasticsearch索引模板

加载索引模板,以便elasticsearch知道哪些字段该以何种方式进行分析。

# curl -XPUT 'http://10.1.19.18:9200/_template/packetbeat' -d@/etc/packetbeat/packetbeat.template.json

启动服务

# /etc/init.d/packetbeat start

查看数据

加载kibana Packetbeat的仪表盘

这个在前面的文章中,有加载过。这里不再重复加载。

配置选项

beats公用的配置选前文有说的。下面说说Packetbeat自有的配置项:Interfaces、Protocols、Processes(可选)。

interfaces

interfaces 部分配置嗅探器

# Select the network interfaces to sniff the data. You can use the "any"# keyword to sniff on all connected interfaces.interfaces:  # On which device to sniff  device: any  # The maximum capture size of a single packet.  snaplen: 1514  # The type of the sniffer to use  type: af_packet  # The size of the sniffing buffer  buffer_size_mb: 100

device

从哪个网络接口捕获通讯。指定的设备自动设置为混杂模式,这意味着Packetbeat可以从同一个LAN捕获其它主机的流量。

interfaces:  device: eth0

在Linux上,可以指定任何的设备。当指定为any时,接口不会设置成混杂模式。

查看可用设备,可以使用下面的命令:

# packetbeat -devices0: eth0 (No description available)1: eth1 (No description available)2: usbmon1 (USB bus number 1)3: any (Pseudo-device that captures on all interfaces)4: lo (No description available)

device可以指定为上述返回列表的索引,如

interfaces:  device: 0

表示是eth0。这对于设备名称很长的情况下非常有用咯。

snaplen

捕获包的最大大小。默认65535。足够应付所有网络和接口类型。如果嗅探物理网络接口,该值设置为MTU大小。对于虚拟接口,还是最好使用默认值。

interfaces:  device: eth0  snaplen: 1514

type

Packetbeat 支持下面的嗅探器类型:

  • pcap, 使用libpcap 库,可工作在大多数平台上,但是不是最快的选项。
  • af_packet, 使用 memory-mapped 嗅探。比 libpcap 快且不需要kernel模块,Linux特定的。
  • pf_ring, 使用 ntop.org 项目。此设置提供了最好的嗅探速度,但是需要一个kernel模块,Linux特定的。

默认的嗅探器类型是pcap。

interfaces:  device: eth0  type: af_packet

在Linux上,如果想优化Packetbeat耗CPU占用率,建议使用 af_packet 和 pf_ring 选项。

如果使用 af_packet, 可以通过下面选项调整行为:

buffer_size_mb

内核和用户空间之间使用的最大共享内存缓冲区大小。默认30MB。缓冲区越大,CPU使用率越低,但是会消耗更多内存。只对af_packet 有效。

interfaces:  device: eth0  type: af_packet  buffer_size_mb: 100

with_vlans

Packetbeat 自动生成一个BPF来捕获已知协议的端口流量。 例如,配置HTTP 80 和 MySQL 3306,  Packetbeat 生成 BPF 过滤器如下: "port 80 or port 3306"。

然而,如果通讯包含VLAN标记,Packetbeat生成的过滤器将是无效的,因为offset通过四个字节移动的。为了解决这个问题,启用 with_vlans 选项,生成的 BPF 过滤器是这样的: "port 80 or port 3306 or (vlan and (port 80 or port 3306))"。

bpf_filter

Packetbeat 自动生成一个BPF来捕获已知协议的端口流量。 例如,配置HTTP 80 和 MySQL 3306,  Packetbeat 生成 BPF 过滤器如下: "port 80 or port 3306"。

可以使用 bpf_filter 覆盖生成的BPF 过滤器,如:

interfaces:  device: eth0  bpf_filter: "net 192.168.238.0/0 and port 80 and port 3306"

此设置是禁用自动生成的BPF过滤器。如果使用此设置,你需要保持BPF过滤器与协议部分定义的端口同步。

Protocols和Processes配置项,下文再说了。

你应该知道的十大常见黑客技术

使用简单的黑客攻击,黑客可以了解您可能不想透露的未经授权的个人信息。了解这些常见的黑客技术,如网络钓鱼、DDoS、点击劫持等,可以为您的人身安全派上用场。由于这些原因,了解一些通常用于以未经授权的方式获取您的个人信息的黑客技术也很重要。1. 诱饵和开关使用诱饵...
服务器安全黑客黑客技术

云盾CNAME接入操作步骤及流程

云盾CNAME接入操作步骤及流程一、注册账号1.登陆http://www.yundun.com/reg,注册账号2.登陆邮箱,收到激活邮件后,激活账号。二、云盾账号下添加网站和解析记录1.登陆到账号,点击添加域名。2.输入域名,选择CNAME接入,点击添加域名...
服务器安全云盾CNAME

云数据库安全防护方案步骤

由于云环境、企业云应用系统、核心数据的复杂性,选择适合的云数据保护方案变得尤为重要。因此,为了保护云端的数据,需要有计划、有步骤的实施云数据库安全防护方案:步骤1:分析并确定需要保护的关键数据在对云数据进行保护前,首先需要准确的分析哪些数据需要保护,和为什么要...
服务器安全云数据库安全防护

Linux服务器怎么卸载云锁

如果对linux系统不熟悉,对云锁不了解,请勿启用Linux服务器怎么卸载云锁一、wdcp可以登录,直接在wdcp上面卸载ssh 远程登陆服务器:2 执行卸载的命令echo y|/usr/local/yunsuo_agent/uninstall ...
linux服务器服务器安全云锁