ELK beat 配置说明

Beats配置文件是以YAML语法,该文件包含用于所有的beats的通用配置选项,以及其特点的选项。下面说说通用的配置,特定的配置要看各自beat文档。 通用的配置如下几部分:

  • Shipper
  • Output
  • Logging(可选)
  • Run Options(可选)

Shipper

包含beat配置选项和一些控制其行为的常规设置。

其实每个配置选项的注释说明已经说的很清楚了,有些人就是视而不见。

如下所示:

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

shipper:

  # The name of the shipper that publishes the network data. It can be used to group

  # all the transactions sent by a single shipper in the web interface.

  # If this options is not defined, the hostname is used.

  #name:

 

  # The tags of the shipper are included in their own field with each

  # transaction published. Tags make it easy to group servers by different

  # logical properties.

  tags: ["service-X", "web-tier"]

 

  # Uncomment the following if you want to ignore transactions created

  # by the server on which the shipper is installed. This option is useful

  # to remove duplicates if shippers are installed on multiple servers.

  ignore_outgoing: true

 

  # How often (in seconds) shippers are publishing their IPs to the topology map.

  # The default is 10 seconds.

  refresh_topology_freq: 10

 

  # Expiration time (in seconds) of the IPs published by a shipper to the topology map.

  # All the IPs will be deleted afterwards. Note, that the value must be higher than

  # refresh_topology_freq. The default is 15 seconds.

  topology_expire: 15

 

  # Configure local GeoIP database support.

  # If no paths are not configured geoip is disabled.

  #geoip:

    #paths:

    #  - "/usr/share/GeoIP/GeoLiteCity.dat"

    #  - "/usr/local/var/GeoIP/GeoLiteCity.dat"

 

name

beat名称,如果没设置以hostname名自居。该名字包含在每个发布事务的shipper字段。可以以该名字对单个beat发送的所有事务分组。

在启动时,每个beat将发送自己的IP、端口、名字到elasticsearch。这些信息存储在elasticsearch作为网络拓扑图,将每个beat的IP和端口与在这里你所指定的名字映射。

当一个beat接收到一个新的请求和响应称为事务,beat会查询elasticsearch查看网络拓扑是否包含该源服务器IP和端口以及目标服务器。如果该信息可用,在输出的client_server字段被设置成运行在源服务器的beat名称,并且server字段被设置成运行在目标服务器的beat名称。

要在elasticsearch中使用拓扑图的话,必须设置save_topology为TRUE并且elasticsearch为输出。

 

1

2

shipper:

  name: "ttlsa-shipper"

 

tags

beat标签列表,包含在每个发布事务的tags字段。标签可用很容易的按照不同的逻辑分组服务器。例如,一个web集群服务器,可以对beat添加上webservers标签,然后在kibana的visualisation界面以该标签过滤和查询整组服务器。

 

1

2

shipper:

  tags: ["mysql-db", "aws", "rdb"]

 

ignore_outgoing

如果启用了ignore_outgoing选项,beat将忽略从运行beat服务器上所有事务。不好描述,看下面的解释。

这是非常有用的,当两个beat发布相同的事务。因为一个beat认为是输出队列的事务,另一个beat认为是输入队列的事务。你可以结束这个重复的事务,启用该选项即可。

例如,有下面这个情景,三台服务器每台都安装了一个beat,t1在server1和server2之间交换事务,t2在server2和server3之间交换事务。

beats

默认情况下,每个事务要被索引两次,因为beat2会看到两个事务。当ignore_outgoing为false时,发布的事务是这样的:

  • Beat1: t1
  • Beat2: t1 and t2
  • Beat3: t2

为了避免重复,需要强制beat只发送输入的事务,忽略本地服务器创建的事务。当ignore_outgoing为true时,发布的事务是这样的:

  • Beat1: none
  • Beat2: t1
  • Beat3: t2
refresh_topology_freq

拓扑图刷新的间隔。也就是设置每个beat向拓扑图发布其IP地址的频率。默认是10秒。

topology_expire

拓扑的过期时间。在beat停止发布其IP地址时非常有用。当过期后IP地址将自动的从拓扑图中删除。默认是15秒。

geoip.paths

GeoIP数据库的搜索路径。beat找到GeoIP数据库后加载,然后对每个事务输出client的GeoIP位置。

推荐值为/usr/share/GeoIP/GeoLiteCity.dat 和/usr/local/var/GeoIP/GeoLiteCity.dat。

目前只有Packetbeat使用该选项。

Output

可以配置多个输出来导出相关事务。当前支持的输出类型有:

  • Elasticsearch
  • Logstash
  • Redis (不推荐)
  • File
  • Console

可以同时启用一个或多个输出。输出插件负责发送JSON格式化的事务数据到下一个管道。同时还维护网络拓扑。

Elasticsearch Output

当指定elasticsearch作为输出,beat通过elasticsearch HTTP API将事务直接发送到elasticsearch。

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

output:

  elasticsearch:

    # The Elasticsearch cluster

    hosts: ["http://es.ttlsa.com:9200"]

 

    # Comment this option if you don't want to store the topology in

    # Elasticsearch. The default is false.

    # This option makes sense only for Packetbeat

    save_topology: true

 

    # Optional index name. The default is packetbeat and generates

    # [packetbeat-]YYYY.MM.DD keys.

    index: "packetbeat"

 

    # List of root certificates for HTTPS server verifications

    cas: ["/etc/pki/root/ca.pem"]

 

    # TLS configuration.

    tls:

      # Certificate for TLS client authentication

      certificate: "/etc/pki/client/cert.pem"

 

      # Client Certificate Key

      certificatekey: "/etc/pki/client/cert.key"

启用SSL,在hosts配置项指定https。

 

1

2

3

4

5

6

7

8

9

10

11

12

13

output:

  elasticsearch:

    # The Elasticsearch cluster

    hosts: ["https://localhost:9200"]

 

    # Comment this option if you don't want to store the topology in

    # Elasticsearch. The default is false.

    # This option makes sense only for Packetbeat

    save_topology: true

 

    # HTTP basic auth

    username: "admin"

    password: "s3cr3t"

如果elasticsearch节点通过IP:PORT定义,需要加protocol: https,如下:

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

output:

  elasticsearch:

    # The Elasticsearch cluster

    hosts: ["localhost"]

 

    # Optional http or https. Default is http

    protocol: "https"

 

    # Comment this option if you don't want to store the topology in

    # Elasticsearch. The default is false.

    # This option makes sense only for Packetbeat

    save_topology: true

 

    # HTTP basic auth

    username: "admin"

    password: "s3cr3t"

 

hosts

可以指定连接的elasticsearch节点列表。事件将随机分配到这些节点。如果某个节点不可达,事件将自动发送到另一个节点。每个elasticsearch节点定义个格式:URL或者IP:PORT。如http://es1.ttlsa.com,https://es2.ttlsa.com或者10.0.0.1。如果没有指定端口默认是9200。

当以IP:PORT形式定义elasticsearch节点,则schema和path取自protocol和path配置项。如:

 

1

2

3

4

5

6

7

8

9

10

output:

  elasticsearch:

    # The Elasticsearch cluster

    hosts: ["10.45.3.2:9220", "10.45.3.1:9230"]

 

    # Optional http or https. Default is http

    protocol: https

 

    # HTTP Path at which each Elasticsearch server lives

    path: /elasticsearch

在上面的例子中,Elasticsearch可用节点是https://10.45.3.2:9220/elasticsearch和https://10.45.3.1:9230/elasticsearch。

worker

配置每台主机发送事件到elasticsearch的worker数量。在负载均衡模式下最好启用。例如,2台主机和3个worker,一共将启动6个worker,每台主机3个worker。

host (不推荐)

elasticsearch服务的主机。该选项不建议使用,已经被hosts替换。

port (不推荐)

elasticsearch服务的端口。该选项不建议使用,已经被hosts替换。

username

连接elasticsearch的基础验证用户名。

password

连接elasticsearch的基础验证密码。

protocol

定义哪种协议可达elasticsearch。选项有http或者https。默认是http。但是,如果在hosts配置项指定了URL,URL中指定的协议将覆盖protocol值。

path

调用HTTP API的前置路径前缀。一般用在elasticsearch监听在HTTP反向代理,同时又自定义API前缀。

index

指定写入事件的索引根名称。默认是beat名称。例如Packetbeat,根索引名称是[packetbeat-]YYYY.MM.DD (如, packetbeat-2015.11.29)。

max_retries

发送到特定logstash的最大尝试次数。如果达到该次数仍不成功,事件将被丢弃。默认是3。

值0表示禁用重试。值小于0将无限重试知道事件已经发布。

如果输出插件把事件丢弃,每个beat要实现必须去顶是否要丢失事件或者尝试再次发送。如果到达max_retries后发送操作还是不成功,beat可选通知。

bulk_max_size

单个elasticsearch批量API索引请求的最大事件数。默认是50。

timeout

elasticsearch请求超时事件。默认90秒。

flush_interval

新事件两个批量API索引请求之间需要等待的秒数。如果bulk_max_size在该值之前到达,额外的批量索引请求生效。

save_topology

elasticsearch是否保持拓扑。默认false。该值只支持Packetbeat。

topology_expire

elasticsearch保存拓扑信息的有效时间。默认15秒。

tls

配置TLS参数选项,如证书颁发机构等,用于基于https的连接。如果tls丢失,主机的CAs用于https连接elasticsearch。

Logstash Output

logstash输出通过使用lumberjack协议将事件直接发送到logstash。要使用此选项,必须在logstash上安装和配置logstash-input-beats插件。logstash允许额外的处理和生成事件路由。

每个发送到logstash事件包含额外的索引和过滤元数据。如:

 

1

2

3

4

5

6

7

{

    ...

    "@metadata": {

      "beat": "<beat>",

      "type": "<event type>"

    }

}

在logstash,你可以配置elasticsearch输出插件使用元数据和事件类型进行索引。

下面的logstash1.5配置文件设置logstash使用beat报告的索引和文档类型将事件索引到elasticsearch。索引使用取决于logstash确定的@timestamp字段。

 

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

input {

  beats {

    port => 5044

  }

}

 

output {

  elasticsearch {

    host => "localhost"

    port => "9200"

    protocol => "http"

    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"

    document_type => "%{[@metadata][type]}"

  }

}

logstash 2.x 相同的配置:

 

1

2

3

4

5

6

7

8

9

10

11

12

13

input {

  beats {

    port => 5044

  }

}

 

output {

  elasticsearch {

    hosts => ["http://localhost:9200"]

    index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"

    document_type => "%{[@metadata][type]}"

  }

}

事件被索引到elasticsearch,类似于将事件通过beats直接索引到elasticsearch。如下配置,如何配置beat使用logstash:

 

1

2

3

4

5

6

7

output:

  logstash:

    hosts: ["localhost:5044"]

 

    # index configures '@metadata.beat' field to be used by Logstash for

    # indexing. By Default the beat name is used (e.g. filebeat, topbeat, packetbeat)

    index: mybeat

 

hosts

要连接logstast的服务器列表。每个列表项可以包含端口号。如果没有指定端口,将使用默认值。

worker

配置每个主机发布事件的worker数量。在负载均衡模式下最好启用。例如,如果2台主机和3个worker,一共6个worker将启动,每台3个worker。

loadbalance

如果设置为TRUE和配置了多台logstash主机,输出插件将负载均衡的发布事件到所有logstash主机。如果设置为false,输出插件发送所有事件到随机的一台主机上,如果选择的不可达将切换到另一台主机。默认是false。

 

1

2

3

4

5

6

7

8

9

output:

  logstash:

    hosts: ["localhost:5044", "localhost:5045"]

 

    # configure index prefix name

    index: mybeat

 

    # configure logstash plugin to loadbalance events between the logstash instances

    loadbalance: true

 

port

hosts配置项如果没有指定端口好将使用的默认端口。默认是10200。

index

如上解释

tls

如上解释

timeout

等待logstash响应的超时时间,默认30秒。

max_retries

如上解释

Redis Output (不推荐)

被beats代替,不推荐使用了。不再此做介绍了。

File Output

文件输出将事务转存到一个文件,每个事务是一个JSON格式。主要用于测试。也可以用作logstash输入。

 

1

2

3

4

5

6

7

8

9

10

11

12

13

output:

 

  # File as output

  # Options:

  # path: where to save the files

  # filename: name of the files

  # rotate_every_kb: maximum size of the files in path

  # number of files: maximum number of files in path

  file:

    path: "/tmp/packetbeat"

    filename: packetbeat

    rotate_every_kb: 1000

    number_of_files: 7

 

path

指定文件保存的路径。必须的。

filename

文件名。默认是 Beat 名称。上面配置将生成 packetbeatpacketbeat.1packetbeat.2 等文件。

rotate_every_kb

定义每个文件最大大小。当大小到达该值文件将轮滚。默认值是1000 KB。

number_of_files

保留文件最大数量。文件数量到达该值将删除最旧的文件。默认是7,一星期。

Console Output

标准输出,JSON 格式。

 

 

1

2

3

output:

  console:

    pretty: true

 

pretty

如果设置为TRUE,事件将很友好的格式化标准输出。默认false。

Logging (Optional)

配置beats日志。日志可以写入到syslog也可以是轮滚日志文件。默认是syslog。

 

1

2

3

4

5

6

7

8

9

10

11

12

13

logging:

  level: warning

 

  # enable file rotation with default configuration

  to_files: true

 

  # do not log to syslog

  to_syslog: false

 

  files:

    path: /var/log/mybeat

    name: mybeat.log

    keepfiles: 7

 

Logging options

to_syslog

如果启用发送所有日志到系统日志。

to_files

日志发送到轮滚文件。

level

日志级别。debug, info, warning, error 或 critical。如果使用debug,但没有配置selectors,* selectors将被使用。默认error。

selectors

The list of debugging-only selector tags used by different Beats components. Use * to enable debug output for all components. For example add publish to display all the debug messages related to event publishing. When starting the Beat, selectors can be overwritten using the -d command line option (-dalso sets the debug log level).

files.path

日志文件目录。

files.name

日志文件名称。默认是Beat 名称。

files.rotateeverybytes

日志文件的最大大小。默认 10485760 (10 MB)。

files.keepfiles

保留日志周期。 默认 7。值范围为2 到 1024。

Logging Format

每个日志类型有不同的日志格式:

  • to syslog: 系统日志加上自己的时间戳。
  • to file: RFC 3339 格式用于时间戳2006-01-02T15:04:05Z07:00 WARN log-message. 该给事包含时区和日志级别。
  • to stderr: UTC  格式用于时间戳 2015/11/12 09:03:37.369262 geolite.go:52: WARN log-message。该格式包括UTC时间戳和毫秒,主要用于调试。

Run Options (Optional)

beats创建套接字后放权。打开套接字需要root访问权限,但不是所有都需要该权限。因此,建议以普通用户运行beats。可以通过uid、gid来指定。

Linux上,setuid不会改变所有线程的uid,所以Go garbage收集器还将以root用户运行。另外注意,进程监控需要以root权限运行。

 

1

2

3

runoptions:

  uid=501

  gid=501

转载于:https://my.oschina.net/FrankXin/blog/1595740

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值