Filebeat是一个开源的文件收集器,主要用于获取日志文件,并把它们发送到logstash或elasticsearch。与libbeat lumberjack一起替代logstash-forwarder。
在logstash-forwarder项目上,看到下面一些信息“The filebeat project replaces logstash-forwarder. Please use that instead.No further development will occur on this project. Major bug fixes or security fixes may be worked on through 2016, at which point this repository and its project will be abandoned.The replacement is filebeat which receives new features and fixes frequently. ”
说明了啥?简单而言logstash-forwarder寿终正寝了,将由filebeat替代了。
前面一文《ELK部署指南》是用logstash-forwarder来收集日志的,当时刚刚研究ELK,没有细读文档,凭借之前的了解来研究的。后面将logstash-forwarder换成filebeat,请关注。
Filebeat 架构如下:
deb:
1
2
|
curl
-
L
-
O
https
:
//download.elastic.co/beats/filebeat/filebeat_1.0.0-rc1_amd64.deb
sudo
dpkg
-
i
filebeat_1
.
0.0
-
rc1_amd64
.
deb
|
rpm:
1
2
|
curl
-
L
-
O
https
:
//download.elastic.co/beats/filebeat/filebeat-1.0.0-rc1-x86_64.rpm
sudo
rpm
-
vi
filebeat
-
1.0.0
-
rc1
-
x86_64
.
rpm
|
mac:
1
2
|
curl
-
L
-
O
https
:
//download.elastic.co/beats/filebeat/filebeat-1.0.0-rc1-darwin.tgz
tar
xzvf
filebeat
-
1.0.0
-
rc1
-
darwin
.
tgz
|
filebeat 默认预定了适应大部分场景的配置参数。对于最基本的Filebeat配置,可以定义一个单一路径的单一prospector,如:
1
2
3
4
5
|
filebeat
:
prospectors
:
-
paths
:
-
"/var/log/*.log"
|
一个配置文件可以包含多个prospector和每个prospector多个路径,如:
1
2
3
4
5
6
7
8
9
|
filebeat
:
prospectors
:
-
paths
:
-
/
var
/
log
/
system
.
log
-
/
var
/
log
/
wifi
.
log
-
paths
:
-
"/var/log/apache/*"
|
在启动filebeat之前,需要向elasticsearch加载索引模板,以让Elasticsearch知道哪些字段应以何种方式进行分析。
推荐的模板文件已经由Filebeat软件包提供,使用下面的命令进行加载:
1
2
3
4
|
# curl -XPUT 'http://10.1.19.18:9200/_template/filebeat?pretty' -d@/etc/filebeat/filebeat.template.json
{
"acknowledged"
:
true
}
|
由Filebeat导出的字段,包括下面两类:
包含所有事件可用的类型。
包含日志文件行。
Filebeat的配置文件使用YAML格式。配置前看看默认设置以及描述信息。filebeat.yml 包含下面几个部分:
具体请看文档:https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-configuration-details.html
https://www.elastic.co/guide/en/beats/libbeat/1.0.0-rc1/configuration.html#configuration
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# filebeat -h
Usage
of
filebeat
:
-
N
Disable
actual
publishing
for
testing
-
c
string
Configuration
file
(
default
"/etc/filebeat/filebeat.yml"
)
-
cpuprofile
string
Write
cpu
profile
to
file
-
d
string
Enable
certain
debug
selectors
-
e
Log
to
stderr
and
disable
syslog
/
file
output
-
memprofile
string
Write
memory
profile
to
this
file
-
test
Test
configuration
and
exit
.
-
v
Log
at
INFO
level
-
version
Print
version
and
exit
|
所有的配置参数需要写入到配置文件中。
转自:http://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
因篇幅问题不能全部显示,请点此查看更多更全内容