ELK自定义索引配置
目前知道的架构方式有三种:
- Logstash –> Elasticsearch –> Kibana 弃用
- Filebeat –> Elasticsearch –> Kibana 简单需求使用
- 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/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
2021-04-06 c语言学习之路