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. ”文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
说明了啥?简单而言logstash-forwarder寿终正寝了,将由filebeat替代了。文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
前面一文《ELK部署指南》是用logstash-forwarder来收集日志的,当时刚刚研究ELK,没有细读文档,凭借之前的了解来研究的。后面将logstash-forwarder换成filebeat,请关注。文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
filebeat介绍
filebeat最初是基于logstash-forwarder源码的日志数据shipper。Filebeat安装在服务器上作为代理来监视日志目录或特定的日志文件,要么将日志转发到Logstash进行解析,要么直接发送到Elasticsearch进行索引。文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
Filebeat 架构如下:文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
安装Filebeat
deb:文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
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:文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
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:文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
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 默认预定了适应大部分场景的配置参数。对于最基本的Filebeat配置,可以定义一个单一路径的单一prospector,如:文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
filebeat: prospectors: - paths: - "/var/log/*.log"
该配置将获取/va/log/目录下的所有以.log结尾的文件。文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
如果要获取子目录下的所有文件可以这么设置/var/log/*/*.log。只会收集到/var/log/目录的子目录以.log结尾的文件,不包括 /var/log自身目录下的以.log结尾的文件。同时,也不会递归的去获取子目录的子目录下的文件。文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
一个配置文件可以包含多个prospector和每个prospector多个路径,如:文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
filebeat: prospectors: - paths: - /var/log/system.log - /var/log/wifi.log - paths: - "/var/log/apache/*"
该配置文件启动两个prospector,第一个prospector具有两个harvester,一个获取system.log文件另一个获取wifi.log文件。第二个prospector启动一个harvester获取/var/log/apache目录下的每个文件。文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
向Elasticsearch加载索引模板
在启动filebeat之前,需要向elasticsearch加载索引模板,以让Elasticsearch知道哪些字段应以何种方式进行分析。文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
推荐的模板文件已经由Filebeat软件包提供,使用下面的命令进行加载:文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
# curl -XPUT 'http://10.1.19.18:9200/_template/filebeat?pretty' -d@/etc/filebeat/filebeat.template.json { "acknowledged" : true }
es地址换成你自己的。文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
导出的字段
由Filebeat导出的字段,包括下面两类:文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
- Common Fields
- Log File Content Fields
common fields
包含所有事件可用的类型。文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
- shipper
类型:字符串 - @timestamp
类型:日期
例如:2015年1月24日14:06:05.071000
格式:YYYY-MM-DDTHH:MM:SS.milliZ
必须:是
日志读取的时间戳。精度为毫秒。时区是UTC。 - type
必须:是
日志事件的名称,设置为prospectors document_type 配置选项。 - input_type
必须:是
Log File Content Fields
包含日志文件行。文章源自运维生存时间-https://www.ttlsa.com/elk/filebeat-replacement-logstash-forwarder/
- source
类型:字符串
必须:是 - offset
类型:int
必须:否 - line
类型:int
必须:是 - message
类型:字符串
必须:是 - fields Fields
包含用户可配置的领域。 - fileinfo Fields
操作系统特定文件的信息用于标识源文件。例如在Linux上inode可能会报告。
配置选项
Filebeat的配置文件使用YAML格式。配置前看看默认设置以及描述信息。filebeat.yml 包含下面几个部分:
- Shipper
- Output
- Filebeat
- Logging (optional)
- Run options (optional)
具体请看文档: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
命令行选项
# 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
所有的配置参数需要写入到配置文件中。

2F
请教一下老师,最新的ELK是5.0了,那么怎样的架构模式更合理?
Filebeat —-> [ Logstash ] —-> [ Redis ] —-> Elasticsearch —- > Kibana
[ ] 环节是否需要? 性能优化方面老师有什么建议吗?
B1
@ 贵在坚持 我觉得是 Filebeat –> Redis –> Logstash –> Elasticsearch –> Kibana –> Nginx
http://www.jinsk.vip/2017/05/24/elksetup/ 这是我搭建的过程记录文章
1F
赞一个