filebeat 没有用我的名字创建索引

filebeat is not creating index with my name

我正在使用 filebeat 将我的应用程序日志发送到 Elasticsearch 并直接连接到我的 Elasticsearch 以发送日志。

我的文件节拍配置

filebeat.config:
  modules:
    path: ${path.config}/modules.d/*.yml
    reload.enabled: false

filebeat.inputs:
  - type: log
    paths:
      - "/var/log/*.log"
setup.ilm.enabled: false
setup.template.overwrite: true
output.elasticsearch:
  hosts: ["aws-es:443"]
  output.elasticsearch.index: "myapp-%{[agent.version]}-%{+yyyy.MM.dd}"
  username: '${ELASTICSEARCH_USERNAME:}'
  password: '${ELASTICSEARCH_PASSWORD:}

请注意,在 output.elasticsearch.index: 中,我将 myapp 作为我在 Elasticsearch 中的索引名称的前缀,但 filebeat 正在使用 filebeat-7.7.0-2020.05.31 名称创建索引,即使用其自己的名称 filebeat 作为前缀我不想要,因为我有多个应用程序并想为它们创建一个单独的索引。

您的 属性 名字有误。它是 output.elasticsearch.output.elasticsearch.index,但应该只是 output.elasticsearch.index 将您的配置更改为

output.elasticsearch:
  hosts: ["aws-es:443"]
  index: "myapp-%{[agent.version]}-%{+yyyy.MM.dd}"
  username: '${ELASTICSEARCH_USERNAME:}'
  password: '${ELASTICSEARCH_PASSWORD:}

你需要设置setup.template.namesetup.template.pattern 如错误消息中所述。请在 filebeat.yml.

中添加以下额外行
setup.template:
  name: 'myapp'
  pattern: 'myapp-*'
  enabled: false

现在你完成了 filebeat.yml 应该看起来像

filebeat.config: 模块: 路径:${ path.config } /modules.d/ *.yml reload.enabled: 假

  filebeat.inputs:
    -type: log
  paths:
    -"/var/log/*.log"
  setup.ilm.enabled: false
  setup.template.overwrite: true
  output.elasticsearch:
    hosts: ["aws-es:443"]
  output.elasticsearch.index: "myapp-%{[agent.version]}-%{+yyyy.MM.dd}"
  username: '${ELASTICSEARCH_USERNAME:}'
  password: '${ELASTICSEARCH_PASSWORD:}

  setup.template:
    name: 'myapp'
    pattern: 'myapp-*'
    enabled: false

将以下 属性 添加到您的配置中,它应该会按预期工作。

setup.ilm.enabled: false

Filebeat 默认使用 Index Lifecycle Management,这可能不错。要在启用 ILM 的情况下更改索引和索引模板的名称,您可以这样做:

setup.ilm.policy_name: yourname
setup.ilm.rollover_alias: yourname-%{[agent.version]}