filebeat 一般处理日志类型的数据,只是beats 产品系列的一种,logstash 和他的区别就是logstash处理的数据类型跟为全面。
-
下载filebeat,解压。部署到需要搜集日志数据机器上。
curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.15.2-linux-x86_64.tar.gz tar xzvf filebeat-7.15.2-linux-x86_64.tar.gz # curl -O 参数表示用url的最后一部分当作文件名保存下载的文件,—L 参数是表示跟随重定向
-
filebeat 使用
参考文档:https://blog.csdn.net/zyxwvuuvwxyz/article/details/108831962
配置文件详情:
filebeat.inputs: - type: log #log类型 enabled: true #默认为true, paths: - /var/log/system.log - /var/log/wifi.log - type: filestream paths: - "/var/log/apache2/*" fields: apache: true fields_under_root: true #控制台输出 output.console: pretty: true #输出到es中 output.elasticsearch: hosts: ["https://localhost:9200"] index: "filebeat-%{[beat.version]}-%{+yyyy.MM.dd}" ssl.certificate_authorities: ["/etc/pki/root/ca.pem"] ssl.certificate: "/etc/pki/client/cert.pem" ssl.key: "/etc/pki/client/cert.key" #输出到logstash中 output.logstash: hosts: ["127.0.0.1:5044"]
filebeat 启动modules
./filebeat modules list #列出模块名 ./filebeat modules enable system nginx mysql #启动system,nginx,mysql模块
启动配置文件
./filebeat -e -c filebeat配置文件
配置文件解释
paths:待收集日志的路径列表,可以为每行指定一个路径,每行以破折号(-)开头。Filebeat会为它在指定路径下找到的每个文件启动一个harvester(收集器) encoding:读取数据时使用的编码 exclude_lines:filebeat会删除与列表中正则表达式匹配的任何行,默认情况下,不会删除任何行 enabled:使用enabled去启用或禁用inputs,默认设置为true tags:Filebeat在每个已发布事件的标记字段中包含的标记列表。标记使得在Kibana中选择特定事件或在Logstash中应用条件过滤变得很容易。这些标记将被附加到常规配置中指定的标记列表中。 fields:可选字段,您可以指定将附加信息添加到输出中。例如,可以添加可用于筛选日志数据的字段。字段可以是标量值、数组、字典或它们的任何嵌套组合。默认情况下,此处指定的字段将分组到输出文档的字段子字典下。 fields_under_root: 将自定义字段显示为顶级字段
-
测试output是否连接成功,如果要输出到elasticsearch或者logstash,可以用下面命令测试是否连接成功
./filebeat test output
-
filebeat自定义索引名称
# 定义app、zabbix、nginx等应用的input类型、以及存放的具体路径 filebeat.inputs: - type: log enabled: true paths: - /var/log/*.log fields: source: app - type: log enabled: true paths: - /var/log/nginx/*.log fields: source: nginx - type: log enabled: true paths: - /var/log/zabbix/*.log fields: source: zabbix filebeat.config.modules: path: ${path.config}/modules.d/*.yml reload.enabled: true setup.template.settings: index.number_of_shards: 1 # 定义kibana的IP:PORT setup.kibana: host: "10.0.0.11:5601" # 定义模板的相关信息 setup.template.name: "lile_log" setup.template.pattern: "lile-*" setup.template.overwrite: true setup.template.enabled: true # 在7.4这个版本中,自定义ES的索引需要把ilm设置为false setup.ilm.enabled: false # 定义app、zabbix、nginx的output output.elasticsearch: # 定义ES的IP:PORT hosts: ["10.0.0.24:9200"] # 这里的index前缀lile与模板的pattern匹配,中间这一串设置为field.source变量,方面后面具体的匹配 index: "lile-%{[fields.source]}-*" indices: # 这里的前缀lile同为与模板的pattern匹配,中间为field.source具体的值,当前面的input的field.source值与这里的匹配时,则index设置为定义的 - index: "lile-app-%{+yyyy.MM.dd}" when.equals: fields: source: "app" - index: "lile-zabbix-%{+yyyy.MM.dd}" when.equals: fields.source: "zabbix" - index: "lile-nginx-%{+yyyy.MM.dd}" when.equals: fields.source: "nginx" processors: - add_host_metadata: ~ - add_cloud_metadata: ~