ELK自定义索引配置

发布时间 2023-04-06 17:48:28作者: woaibaobei

目前知道的架构方式有三种:

  1. Logstash –> Elasticsearch –> Kibana 弃用
  2. Filebeat –> Elasticsearch –> Kibana 简单需求使用
  3. Filebeat –> Logstash –> Elasticsearch –> Kibana 复杂需求使用

 

1、Filebeat output 到ES(待验证):
修改filebeat.yml配置文件

# 配置输入
filebeat.inputs:
- type: log
enabled: true
paths:
- /home/wwwlogs/access.log
json.keys_under_root: true
json.add_error_key: true
fields:
source: 'nginx-access'

- type: log
enabled: true
paths:
- /home/wwwlogs/kibana.log
json.keys_under_root: true
json.add_error_key: true
fields:
source: 'kibana-access'

# 配置输出
output.elasticsearch:
hosts: ["192.168.0.4:9200"]
indices:
- index: "%{[fields.source]}-%{+yyyy.MM.dd}"
when.contains:
fields.source: "nginx-access"
- index: "%{[fields.source]}-%{+yyyy.MM.dd}"
when.contains:
fields.source: "kibana-access"
yml yaml复制代码
主要是在input那里配置自定义字段fields.source,然后再output es那里使用indices+when,即实现自定义索引。

2、Filebeat output 到Logstash(已验证):
这一个需要filebeat和logstash的配合,索引的自定义在logstash的output完成。

1)修改filebet的配置
vim filebeat.yml

# 配置输入
filebeat.inputs:

- type: log
enabled: true
paths:
- /data/logs/ca/ca.log
fields:
type: "ca"


- type: log
enabled: true
paths:
- /data/logs/ws-fund/ws-fund.log
fields:
type: "ws-fund"

# 配置输出
output.logstash:
hosts: ["192.168.0.4:5044"]
yml yaml复制代码
2) 修改logstash配置
vim logstash.conf

# 配置输入
input {
beats {
port => 5044
}
}

# 配置输出
output {
if [fields][type] == "ws-fund"{
elasticsearch {
hosts => ["http://es01:9200"]
index => "ws-fund-%{+YYYY.MM.dd}"
}
}else if [fields][type] == "ca"{
elasticsearch {
hosts => ["http://es01:9200"]
index => "ca-%{+YYYY.MM.dd}"
}
}else {
elasticsearch {
hosts => ["http://es01:9200"]
index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
}
}
}

 

 

 

参考地址:https://www.langxw.com/2021/02/02/ELK%E8%87%AA%E5%AE%9A%E4%B9%89%E7%B4%A2%E5%BC%95%E9%85%8D%E7%BD%AE/