packetbeat mysql_ELK Packetbeat 协议和进程配置项(16th)

本文详细介绍了Packetbeat的配置,包括DNS、HTTP、MySQL等协议的配置选项,如ports、send_request、send_response等。Packetbeat支持多种协议的流量捕获,并提供了隐藏敏感信息、设置超时时间等功能,帮助用户实现网络流量的监控和分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Packetbeat 协议部分包含支持每个协议的配置项,如ports, send_request, send_response 和 特定的协议选项。

目前Packetbeat支持以下协议:

DNS

HTTP

Mysql

PostgreSQL

Thrift-RPC

配置如下:

protocols:

dns:

ports: [53]

http:

ports: [80, 8080, 8000, 5000, 8002]

memcache:

ports: [11211]

mysql:

ports: [3306]

redis:

ports: [6379]

pgsql:

ports: [5432]

thrift:

ports: [9090]

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

protocols:

dns:

ports:[53]

http:

ports:[80,8080,8000,5000,8002]

memcache:

ports:[11211]

mysql:

ports:[3306]

redis:

ports:[6379]

pgsql:

ports:[5432]

thrift:

ports:[9090]

通用协议选项

下面的选项可用于所有协议:

ports

Packetbeat以该端口捕获具体协议流量。 Packetbeat 基于这个端口安装一个BPF过滤器。如果数据包不匹配该过滤器直接丢弃。Packetbeat还使用该端口以确定每个数据包使用哪个分析器解析。

send_request

如果启用了,请求的信息(request字段)将发送到elasticsearch。默认是 false。 如果想索引整个请求该选项要启用。注意对于HTTP,请求体默认不包含,仅仅是HTTP头部。

send_response

如果启用了,响应的信息(response字段)将发送到elasticsearch。默认是 false。 如果想索引整个请求该选项要启用。注意对于HTTP,请求体默认不包含,仅仅是HTTP头部。

如下图

1241be8dcfbb73ae08c5852956046a3f.png

transaction_timeout

每个协议事务超时时间。过期事务将不再关联输入响应,但是立即发送到elasticsearch。

DNS配置选项

配置实例如下:

protocols:

dns:

ports: [53]

# include_authorities controls whether or not the dns.authorities field

# (authority resource records) is added to messages.

# Default: false

include_authorities: true

# include_additionals controls whether or not the dns.additionals field

# (additional resource records) is added to messages.

# Default: false

include_additionals: true

1

2

3

4

5

6

7

8

9

10

11

12

protocols:

dns:

ports:[53]

# include_authorities controls whether or not the dns.authorities field

# (authority resource records) is added to messages.

# Default: false

include_authorities:true

# include_additionals controls whether or not the dns.additionals field

# (additional resource records) is added to messages.

# Default: false

include_additionals:true

include_authorities

如果启用, dns.authority 字段 (权威资源记录) 将加入到DNS 事件。默认false。

include_additionals

如果启用,dns.additionals字段 (额外资源记录) 将加入到DNS 事件。默认false。

HTTP 配置选项

配置实例如下:用的最多是这个,注意看

protocols:

http:

# Configure the ports where to listen for HTTP traffic. You can disable

# the http protocol by commenting the list of ports.

ports: [80, 8080, 8000, 5000, 8002]

# Uncomment the following to hide certain parameters in URL or forms attached

# to HTTP requests. The names of the parameters are case insensitive.

# The value of the parameters will be replaced with the 'xxxxx' string.

# This is generally useful for avoiding storing user passwords or other

# sensitive information.

hide_keywords: ["pass", "password", "passwd"]

# Uncomment the following to export a list of extra HTTP headers. By

default is none sent.

send_headers: ["User-Agent", "Cookie", "Set-Cookie"]

# Uncomment the following to export Cookie or Set-Cookie headers. By

# default is false.

split_coookie: true

# Configure the HTTP header that contains the real IP address.

real_ip_header: "X-Forwarded-For"

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

protocols:

http:

# Configure the ports where to listen for HTTP traffic. You can disable

# the http protocol by commenting the list of ports.

ports:[80,8080,8000,5000,8002]

# Uncomment the following to hide certain parameters in URL or forms attached

# to HTTP requests. The names of the parameters are case insensitive.

# The value of the parameters will be replaced with the 'xxxxx' string.

# This is generally useful for avoiding storing user passwords or other

# sensitive information.

hide_keywords:["pass","password","passwd"]

# Uncomment the following to export a list of extra HTTP headers. By

defaultisnonesent.

send_headers:["User-Agent","Cookie","Set-Cookie"]

# Uncomment the following to export Cookie or Set-Cookie headers. By

# default is false.

split_coookie:true

# Configure the HTTP header that contains the real IP address.

real_ip_header:"X-Forwarded-For"

hide_keywords

查询参数列表,Packetbeat将自动审查已存的事务。与这些参数相关的值将被替代成 'xxxxx'。默认情况下,是不会更改HTTP信息的。

Packetbeat 有这个选项,是因为不同于 SQL 流量只含有密码的hash值,HTTP 流量可能包含敏感的数据。为了降低安全风险,可配置此选项避免HTTP POST发送特定的参数。

redact_authorization

当启用该选项, Packetbeat 隐藏  Authorization值和 Proxy-AuthorizationHTTP头部,并检查响应的字符串。

如果使用Basic Authentication验证,应该启用该选,因为可能包含base64未加密的用户名和密码。

send_headers

捕获一系列头部名并发送到 Elasticsearch。这些头部以json格式放在headers字典里。

send_all_headers

发送头部白名单到 Elasticsearch,如果要发送所有头部,该选项设置为TRUE。默认是false。

3b80cfca812f070073db0cafc4b06072.png

include_body_for

列出内容类型列表,Packetbeat 将在response字段包含完整的HTTP有效载荷。该选项要和send_response选项一起使用。

如:

protocols:

http:

ports: [80, 8080]

send_response: true

include_body_for: ["text/html"]

1

2

3

4

5

protocols:

http:

ports:[80,8080]

send_response:true

include_body_for:["text/html"]

split_cookie

如果Cookie 或者 Set-Cookie 头部被发送, 该选项控制是否把它们分割成独自值。默认false。例如,设置了该选项, HTTP 响应将成下面的json格式结果:

"response": {

"code": 200,

"headers": {

"connection": "close",

"content-language": "en",

"content-type": "text/html; charset=utf-8",

"date": "Fri, 21 Nov 2014 17:07:34 GMT",

"server": "gunicorn/19.1.1",

"set-cookie": {

"csrftoken": "S9ZuJF8mvIMT5CL4T1Xqn32wkA6ZSeyf",

"expires": "Fri, 20-Nov-2015 17:07:34 GMT",

"max-age": "31449600",

"path": "/"

},

"vary": "Cookie, Accept-Language"

},

"phrase": "OK"

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

"response":{

"code":200,

"headers":{

"connection":"close",

"content-language":"en",

"content-type":"text/html; charset=utf-8",

"date":"Fri, 21 Nov 2014 17:07:34 GMT",

"server":"gunicorn/19.1.1",

"set-cookie":{

"csrftoken":"S9ZuJF8mvIMT5CL4T1Xqn32wkA6ZSeyf",

"expires":"Fri, 20-Nov-2015 17:07:34 GMT",

"max-age":"31449600",

"path":"/"

},

"vary":"Cookie, Accept-Language"

},

"phrase":"OK"

}

real_ip_header

提取真实IP地址。该信息用于 real_ip 和 client_location 索引字段。

Memcache 配置选项

实例如下:

memcache:

ports: [11211]

parseunknown: false

maxvalues: 0

maxbytespervalue: 100

transaction_timeout: 200

udptransactiontimeout: 200

1

2

3

4

5

6

7

memcache:

ports:[11211]

parseunknown:false

maxvalues:0

maxbytespervalue:100

transaction_timeout:200

udptransactiontimeout:200

parseunknown

当启用该选项,迫使memcache文本协议分析器接受未知的命令。

maxvalues

信息(multi-get)存储值的最大数量。所有值base64编码。可能值如下:

maxvalue: -1, 存储所有值 (基于文本协议 multi-get)

maxvalue: 0, 不存储值 (默认)

maxvalue: N, 最多可存 N 值

maxbytespervalue

复制每个值元素的最大字节数。值以base64编码,因此JSON文档中的实际大小将是maxbytespervalue的4倍。

udptransactiontimeout

事务的超时时间。默认 10000 毫秒。

MySQL 和 PgSQL 配置选项

max_rows

发送到elasticsearch的SQL信息的最大行数。默认10行。

max_row_length

发送到elasticsearch的SQL信息的最大字节。默认1024 字节。

Thrift 配置选项

socket用的比较多,注意看。

实例如下:

thrift:

transport_type: socket

protocol_type: binary

idl_files: ["tutorial.thrift", "shared.thrift"]

string_max_size: 200

collection_max_size: 20

capture_reply: true

obfuscate_strings: true

drop_after_n_struct_fields: 100

1

2

3

4

5

6

7

8

9

thrift:

transport_type:socket

protocol_type:binary

idl_files:["tutorial.thrift","shared.thrift"]

string_max_size:200

collection_max_size:20

capture_reply:true

obfuscate_strings:true

drop_after_n_struct_fields:100

transport_type

Thrift 传输类型。 默认是 socket。

protocol_type

Thrift 协议类型。 只接受二进制的TBinary协议, 这是默认的Thrift 协议。

idl_files

Thrift 接口描述语言 (IDL)文件,Packetbeat 所监控的。 可选的,因为Thrift信息包含足够的信息去解码而无需IDL文件。 然而,提供 IDL使 Packetbeat 可包含参数和异常名字。

string_max_size

参数或返回值的字符串最大长度。如果超过该值,将会被自动截断,Packetbeat在字符串后面加上个点,标示被截断。默认200。

collection_max_size

Thrift list, set, map 或者 structure 最大元素个数。如果超过这个值,Packetbeat只捕获指定元素的个数。 Packetbeat 在集合后面添加一个虚拟的元素... 标明被截断。默认15。

capture_reply

如果设置为false, Packetbeat 解码来自应答的方法名称,对剩余的响应信息简单的跳过。该选项对性能、磁盘使用情况或者数据保留很有用。默认TRUE。

obfuscate_strings

如果设置为TRUE, Packetbeat 将以"*"字符串取代方法参数、返回码或者异常结构发现的字符串。

drop_after_n_struct_fields

Packetbeat忽略整个事务前,可保留的最大字段数。这是个内存保护机制,不至于Packetbeat内存无限增长。因此通常设置为一个相对高的值。默认500。

MongoDB 配置选项

用的也比较多,注意看

实例如下:

mongodb:

send_request: true

send_response: true

max_docs: 0

max_doc_length: 0

1

2

3

4

5

mongodb:

send_request:true

send_response:true

max_docs:0

max_doc_length:0

下面两个设置用于限制Packetbeat索引中的response字段的数据量。

max_docs

响应索引中的response字段最大的文档数。默认10。 可以设置为0,不限制文档数。

Packetbeat 在最后添加 [...] 一行标明未保存其它文档,是因为该设置。

max_doc_length

单个文档索引中的response字段的最大字符数。默认5000。 可以设置为0不限制。

如果因为该设置文档被修剪,Packetbeat在文档末尾添加... 字符串以标示。

注意,以该方式限制文档意味着它们将不再是正确的json格式对象了。

维护网络拓扑的实时状态

Packetbeat知道每个事务的源服务器和目标服务器的名称。这个之前说过的,会维护主机名、ip映射的。不清楚的看前面文章。

Packetbeat存储拓扑信息到elasticsearch索引。要保持网络拓扑,使用elasticsearch作为输出,并设置save_topology为TRUE。

进程 (可选)

可选的。捕获进程的通讯包。默认情况下,进程匹配是禁用的。只支持Linux系统。

procs:

enabled: true

monitored:

- process: mysqld

cmdline_grep: mysqld

- process: pgsql

cmdline_grep: postgres

- process: nginx

cmdline_grep: nginx

- process: app

cmdline_grep: gunicorn

1

2

3

4

5

6

7

8

9

10

11

12

13

14

procs:

enabled:true

monitored:

-process:mysqld

cmdline_grep:mysqld

-process:pgsql

cmdline_grep:postgres

-process:nginx

cmdline_grep:nginx

-process:app

cmdline_grep:gunicorn

process

指定进程名称,可随意定义以便可识。

cmdline_grep

该名字用于识别正在运行的进程名。定期扫描进程表与之匹配,一旦匹配从 /proc//cmdline读取信息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值