原文链接:http://www.ttlsa.com/elk/elk-packetbeat-deployment-guide/

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

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

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

Packetbeat目前支持的协议有:

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

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

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

安装

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

 
1
# yum install packetbeat

配置

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

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

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

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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服务

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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知道哪些字段该以何种方式进行分析。

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

启动服务

 
1
# /etc/init.d/packetbeat start

查看数据

加载kibana Packetbeat的仪表盘

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

配置选项

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

interfaces

interfaces 部分配置嗅探器

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 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捕获其它主机的流量。

 
1
2
interfaces:
  device: eth0

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

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

 
1
2
3
4
5
6
# packetbeat -devices
0: 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可以指定为上述返回列表的索引,如

 
1
2
interfaces:
  device: 0

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

snaplen

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

 
1
2
3
interfaces:
  device: eth0
  snaplen: 1514

type

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

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

默认的嗅探器类型是pcap。

 
1
2
3
interfaces:
  device: eth0
  type: af_packet

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

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

buffer_size_mb

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

 
1
2
3
4
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 过滤器,如:

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

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

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

ELK Packetbeat 部署指南(15th)的更多相关文章

  1. ELK Packetbeat 部署指南

    http://www.ttlsa.com/elk/elk-packetbeat-deployment-guide/

  2. Docker环境 ELK 快速部署

    Docker环境 ELK快速部署 环境 Centos 7.4 , Docker version 17.12 Docker至少3GB内存: #内核配置 echo ' vm.max_map_count = ...

  3. 首发福利!全球第一开源ERP Odoo系统架构部署指南 电子书分享

    引言 Odoo,以前叫OpenERP,是比利时Odoo S.A.公司开发的一个企业应用软件套件,开源套件包括一个企业应用快速开发平台,以及几千个Odoo及第三方开发的企业应用模块.Odoo适用于各种规 ...

  4. [转]Nginx反向代理和负载均衡部署指南

    Nginx反向代理和负载均衡部署指南   1.        安装 1)         从Nginx官网下载页面(http://nginx.org/en/download.html)下载Nginx最 ...

  5. ELK 安装部署实战 (最新6.4.0版本)

    一.实战背景 根据公司平台的发展速度,对于ELK日志分析日益迫切.主要的需求有: 1.用户行为分析 2.运营活动点击率分析 作为上述2点需求,安装最新版本6.4.0是非常有必要的,大家可根据本人之前博 ...

  6. Istio 1.4 部署指南

    原文链接:Istio 1.4 部署指南 Istio 一直处于快速迭代更新的过程中,它的部署方法也在不断更新,之前我在 1.0 版本中介绍的安装方法,对于最新的 1.4 版本已经不适用了.以后主流的部署 ...

  7. 精讲 使用ELK堆栈部署Kafka

    使用ELK堆栈部署Kafka 通过优锐课的java架构学习分享,在本文中,我将展示如何使用ELK Stack和Kafka部署建立弹性数据管道所需的所有组件. 在发生生产事件后,恰恰在你最需要它们时,日 ...

  8. NTP 集群简略部署指南

    NTP 集群简略部署指南 by 无若 1. NTP 简介 网络时间协议(英语:Network Time Protocol,简称NTP)是在数据网络潜伏时间可变的计算机系统之间通过分组交换进行时钟同步的 ...

  9. Web项目部署指南

    Web项目部署指南 本文记录了部署Vue项目到阿里云服务器上的过程,其中云服务器的操作系统是CentOS 7,Web服务器用的是nginx.因为项目涉及发送异步请求,而由Flask编写的后端应用监听的 ...

随机推荐

  1. lower_bound()函数

    头文件 # include<algorithm> 函数简介 lower_bound()返回一个 iterator 它指向在[first,last)标记的有序序列中可以插入value,而不会 ...

  2. 嵌入式web server——Goahead启用SSL

    前言 之前已经介绍过如何把goahead移植到linux平台,现在再介绍goahead应用SSL的一些关键要点.因为此博文是继承于上一篇关于移植的博文,有不明白的请先回看.移植篇点这里. 移植环境 g ...

  3. Windows Phone 之下拉菜单ListPicker

    默认情况下,Visual Studio的ToolBox里没有任何下拉菜单的控件可供使用,虽然可以手工输入代码使用隐藏的ComboBox来实现下拉菜单,但是显示出来的菜单与Metro UI主题不匹配.S ...

  4. Git (1)

    对于程序员来说,版本管理工具可称得上是必需品.越来越多的版本管理开始使用Git,特别是Github的流行更加使得大家对于Git越来越关注.因此对于Git的学习是非常必要和重要的. 先看几个好玩的数据: ...

  5. 纯javascript联动的例子

    有人想要学习下纯javascript联动的一些技巧,我这里就以日期的联动为例,附上一些代码至于复杂的省市区联动,不建议用纯javascript的,而是用ajax的方式,该不在此讨论范围内,想要了解aj ...

  6. Successfully installed matplotlib

    Installing /usr/local/lib/python2.7/dist-packages/matplotlib-1.4.0-py2.7-nspkg.pthSuccessfully insta ...

  7. windows相关小知识

    获得本机MAC1 快捷键win+R打开运行窗口, 输入cmd回车进入控制台2 输入ipconfig -all  找到本地连接中的物理地址 根据IP获得MAC方法:1 进入cmd控制台,执行:ping ...

  8. iptables 配置需要保存

    iptables-save > /root/myiptables 将iptables规则导入到文件/root/myiptablse iptables-restore < /root/myi ...

  9. spoj cot: Count on a tree 主席树

    10628. Count on a tree Problem code: COT You are given a tree with N nodes.The tree nodes are number ...

  10. [CF Round #294 div2] D. A and B and Interesting Substrings 【Map】

    题目链接:D. A and B and Interesting Substrings 题目大意 给定26个小写字母的权值,一共26个整数(有正有负). 给定一个小写字母组成的字符串(长度10^5),求 ...