[TOC] ## 一、概述 Filebeat是一个轻量级托运人,用于转发和集中日志数据。Filebeat作为代理安装在您的服务器上,监控您指定的日志文件或位置,收集日志事件,并将其转发到[Elasticsearch](https://www.elastic.co/products/elasticsearch)或[Logstash](https://www.elastic.co/products/logstash)进行索引。 Filebeat的工作原理如下:当您启动Filebeat时,它会启动一个或多个输入,这些输入查看您为日志数据指定的位置。对于Filebeat找到的每个日志,Filebeat都会启动一个收割机。每个收割机都会读取新内容的单个日志,并向新日志数据tlibbeat发送,以汇总事件并将汇总的数据发送到您为Filebeat配置的输出。 ![](https://img.kancloud.cn/37/1d/371da7386a13d5fbb4f6f99a0363cbfc_940x735.png) ## 二、下载 [https://www.elastic.co/cn/downloads/logstash](https://www.elastic.co/cn/downloads/logstash) ![](https://img.kancloud.cn/6f/6c/6f6cc4ed3b16e0b07816d82ba6dac422_2594x1062.png) 获取历史版本: ![](https://img.kancloud.cn/15/37/1537bc1d4ea57d7d8642d21d5b16fbd7_2956x1192.png) ## 三、安装 ### 3.1. 配置文件filebeat.yml ![](https://img.kancloud.cn/19/b9/19b9b9ab9862e333e718c97418de0e45_1056x172.png) ``` vim filebeat.yml ``` #### 3.1.1. 修改filebeat.inputs 其中: >[info] paths:为项目的日志路径; > docType:索引名称。elasticsearch和logstash需要使用; ![](https://img.kancloud.cn/23/6f/236fdbd5e9e3cd97c958053e3b7a530a_1796x2080.png) ``` filebeat.inputs: - type: log enabled: true paths: - /Users/herw/Workspaces/eclipse/greatwall-microservice/logs/application/*/*.log exclude_lines: ['\sDEBUG\s\d'] exclude_files: ['sc-admin.*.log$'] fields: docType: sys-log project: greatwall-microservice multiline: pattern: '^\[\S+:\S+:\d{2,}] ' negate: true match: after - type: log enabled: true paths: - /Users/herw/Workspaces/eclipse/greatwall-microservice/greatwall-gateway/logs/point/*.log fields: docType: point-log project: greatwall-microservice - type: log enabled: true paths: - /usr/local/mysql/data/heruowendeMBP-slow.log fields: docType: mysqlslowlogs exclude_lines: ['^\# Time'] multiline: pattern: '^\# Time|^\# User' negate: true match: after - type: log enabled: true paths: - /Users/herw/Workspaces/eclipse/greatwall-microservice/greatwall-business/logs/audit/*.log fields: docType: audit-log project: greatwall-microservice ``` #### 3.1.2. 修改output.logstash 其中: >[info] hosts:为logstash的部署地址 ![](https://img.kancloud.cn/cc/41/cc41e55e520a899d9c5b719c2e39fb1b_1412x966.png) ``` hosts: ["localhost:5044"] bulk_max_size: 2048 ``` >[danger] 注释elasticsearch接口,因为filebeat要输出到logstash > #output.elasticsearch: > #hosts: \["localhost:9200"\] ## 四、启动 ``` ./filebeat -c filebeat.yml -e ```