侧边栏壁纸
博主头像
福福不服博主等级

孩子会穿过大雨,去懂人间的道理。

  • 累计撰写 92 篇文章
  • 累计创建 98 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Filebeat日志采集到Elasticsearch集群

Monster
2024-01-29 / 0 评论 / 2 点赞 / 71 阅读 / 3857 字 / 正在检测是否收录...
温馨提示:
请确保在评论和互动中保持礼貌和尊重。避免使用侮辱性、歧视性或攻击性语言。我们鼓励建设性的讨论和意见交流。

一、安装Filebeat

注意:所有版本需要一直,我这里Elasticsearch是7.10.1,包括后期的Logstash那些都需要版本一致。

我在/data下新建了一个filebeat目录

下载并解压filebeat

curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.10.1-linux-x86_64.tar.gz
tar xzvf filebeat-7.10.1-linux-x86_64.tar.gz

进入解压后的filebeat目录,嫌目录文件名长的话可以用mv命令修改一下。

[root@postgresql filebeat]# cd filebeat-7.10.1-linux-x86_64

二、配置Filebeat

解压后就是已经安装好了,接下来配置filebeat

在目录下可以看见有个filebeat.yml文件,默认是不启用的。

编辑配置文件filebeat.yml

vim filebeat.yml 

修改filebeat.inputs输入设置

将enabled设置为True,默认关闭的

paths的路径就是你要收集的日志文件路径。

filebeat.inputs:

# Each - is an input. Most options can be set at the input level, so
# you can use different inputs for various configurations.
# Below are the input specific configurations.

- type: log

  # Change to true to enable this input configuration.
  enabled: true

  # Paths that should be crawled and fetched. Glob based paths.
  paths:
    - /data/logs/*.log
    #- c:\programdata\elasticsearch\logs\*

接着修改output.elasticsearch输出设置

这里我是通过filebeat直接推到Elasticsearch,默认也是推到Elasticsearch的,其它地方都是注释掉的。

hosts:设置你的Elasticsearch地址,将localhost替换为你的es地址,我这里是都在本机。

index:默认是没有的,这里设置索引格式为ffbf_nginx-版本号-日期,默认格式为filebeat-版本号-日期。

setup.template.name :模板的名称。默认是filebeat。 Filebeat 版本始终附加到给定名称,因此最终名称为 filebeat-%{[agent.version]}。

setup.template.pattern :应用到默认索引设置的模板模式。默认模式是 filebeat-*。 Filebeat 版本始终包含在模式中,所以最终的模式是 filebeat-%{[agent.version]}-*。通配符 -* 用于匹配所有每日索引。

setup.ilm.enabled :对 Filebeat 创建的任何新索引启用或禁用索引生命周期管理。 有效值为 true、false 和 auto。 当在 7.0 及更高版本上指定 auto(默认)时,如果 Elasticsearch 中启用了该功能并且具有所需的许可证,Filebeat 会自动使用索引生命周期管理; 否则,Filebeat 将创建每日索引。

output.elasticsearch:
  # Array of hosts to connect to.
  hosts: ["localhost:9200","localhost:9201","localhost:9202"]
  index: "ffbf_nginx-%{[agent.version]}-%{+yyyy.MM.dd}"
#注意:自定义索引就必须配置下面的参数,下面3项配置不要和index平齐,放在顶格不然启动报错.
setup.template.name: "ffbf_nginx"
setup.template.pattern: "ffbf_nginx-*"
setup.ilm.enabled: false

:wq保存退出

三、启动Filebeat

启动filebeat,此时是占用命令行的,输入Ctrl+C终止

./filebeat

输入下面的命令启动filebeat并控制台打印信息,也直接可以后台运行。

./filebeat -e

四、索引管理

查看索引管理,是按我们设置的格式创建的。

但是在Discover默认只有filebeat-*,在索引模式创建个新的索引模式

匹配所有以ffbf_nginx-开头的

选择时间字段

设置为默认索引

这时候回到Discover查看,默认显示ffbf_nginx的日志

我这里是手动把/data/logs/下的日志文件多复制了一份出来,可以看到16:19分的时候又记录了一千多条日志进来。

2
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin
  3. QQ打赏

    qrcode qq

评论区