# 請教如何令filebeat做到多個indexes配上不同template和ilm

**URL:** <https://discuss.elastic.co/t/filebeat-indexes-template-ilm/277106>\
**Category:** 中文提问与讨论\
**Created:** [June 26, 2021, 12:08am UTC](https://discuss.elastic.co/t/filebeat-indexes-template-ilm/277106 "2021-06-26T00:08:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cecil](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@cecil](https://discuss.elastic.co/u/cecil)\
**Post date:** [June 26, 2021, 12:08am UTC](https://discuss.elastic.co/t/filebeat-indexes-template-ilm/277106/1 "2021-06-26T00:08:34Z")

</div>

我是新手，已測試了filebeat如何取得多個不同log源，也試了單一ilm是怎樣發生，也稍為明白template的用途。  
現在有一個以下問題，目標是在同一伺服器上，把/var/log/syslog和/var/log/auth.log經filebeat分別套用在不同template上，然後各自也配不同ilm  
例如syslog的ilm是hot 1day, delete 30days，而auth.log的ilm是hot 30 day, delete 365days。  
應該要怎樣做?  
如果單用Filebeat設定ilm便會所有放進同一indexes裡，我想系統能夠分別有像server001-auth和server001-syslog之類分別查看。

使用版本:  
elasticsearch 7.13  
filebeat 7.13  
kibana 7.13

謝謝

---

<div class="post-metadata">

**Author:** ![joecwu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joecwu/32/37258_2.png) [@joecwu](https://discuss.elastic.co/u/joecwu)\
**Post date:** [July 15, 2021, 2:33am UTC](https://discuss.elastic.co/t/filebeat-indexes-template-ilm/277106/2 "2021-07-15T02:33:41Z")

</div>

filebeat 的設定上可以自定義 fields，將這兩種不同來源的資料區分開來。

```auto
filebeat.inputs:
- type: log
  paths:
    - /var/log/syslog/*
  fields:
    - log_type: syslog
- type: log
  paths:
    - /var/log/auth.log
  fields:
    - log_type: authlog

```

ILM 自己先在 Elasticsearch 設定好這兩種不同的規則，建立好各自的 aliases，然後把 Filebeat 的 ILM disable，不要讓 Filebeat 自己決定 Elasticsearch output 時的 index name.

```auto
setup.ilm.enabled: false

```

在 output 時，可以指定 index name 包含這個自定義的 fields.

```auto
output.elasticsearch:
  hosts: ["http://localhost:9200"]
  index: "server001-%{[fields.log_type]}"

```

這樣就可以寫到不同的 alias 之中 (這時應該就不用指定日期，就讓 ILM 的機制自己去 rollover index)。

======  
中文的討論歡迎到 Facebook 社團: [Elasticsearch Taiwan - ELK 台灣臉書群](https://www.facebook.com/groups/elastictaiwan)  
或是 [喬叔的 Elastic 技術交流粉絲頁](https://www.facebook.com/Joe.ElasticStack)

---

<div class="post-metadata">

**Author:** ![cecil](https://avatars.discourse-cdn.com/v4/letter/c/eb8c5e/32.png) [@cecil](https://discuss.elastic.co/u/cecil)\
**Post date:** [July 21, 2021, 3:33am UTC](https://discuss.elastic.co/t/filebeat-indexes-template-ilm/277106/3 "2021-07-21T03:33:45Z")

</div>

好像做到了XD  
在filebeat裡備註所有setup.template.XXXX  
然後只加入setup.template.enable: false和joecwu介紹的setup.ilm.enabled: false，接著在kibana建立index templates和ilm

成功了，真的大大大的感謝

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 18, 2021, 3:34am UTC](https://discuss.elastic.co/t/filebeat-indexes-template-ilm/277106/4 "2021-08-18T03:34:14Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
