ELK流程图以及部分搭建
大致框架架构
ELK是一组开源软件的简称,其包括Elasticsearch、Logstash 和 Kibana。ELK最近几年发展迅速,已经成为目前最流行的集中式日志解决方案。
Elasticsearch: 能对大容量的数据进行接近实时的存储,搜索和分析操作。 本项目中主要通过Elasticsearch存储所有获取的日志。
Logstash: 数据收集引擎,它支持动态的的从各种数据源获取数据,并对数据进行过滤,分析,丰富,统一格式等操作,然后存储到用户指定的位置。
Kibana: 数据分析与可视化平台,对Elasticsearch存储的数据进行可视化分析,通过表格的形式展现出来。
Filebeat: 轻量级的开源日志文件数据搜集器。通常在需要采集数据的客户端安装Filebeat,并指定目录与日志格式,Filebeat就能快速收集数据,并发送给logstash进行解析,或是直接发给Elasticsearch存储。
Redis:NoSQL数据库(key-value),也数据轻型消息队列,不仅可以对高并发日志进行削峰还可以对整个架构进行解耦
流程图:
目前的架构流程如下:
Filebeat 已经完全替代了 Logstash 成为新一代的日志采集器,同时鉴于它轻量、安全等特点,经消息队列输出插件输出到消息队列中。目前 Logstash 支持Redis等常见消息队列。然后 Logstash 通过消息队列输入插件从队列中获取数据,分析过滤后经输出插件发送到 Elasticsearch,最后通过 Kibana 展示
Filebeat设置
修改配置文件filebeat.yml:
filebeat.inputs:下设置
enabled: true
日志路径:
- type: log
enabled: true
paths:
- /opt/data/cjwl56log/log/*/*.log
fields:
log_source: action
log_type: action
tail_files: true
scan_frequency: 60s
backoff: 10s
- type: log
enabled: true
paths:
- /opt/data/logs/api-gateway/*/*.log
fields:
log_source: gateway
log_type: gateway
tail_files: true
scan_frequency: 60s
backoff: 10s
output.kafka:
enabled: true
max_retries: 5
hosts: ["x.x.x.x:9092","x.x.x.x:9092","x.x.x.x:9092"]
timeout: 300
topic: "filebeatlog"
注释掉Elasticsearch output:下的设置
其他的默认即可。
Logstash设置
input {
kafka {
bootstrap_servers => "1x.x.x.x:9092,x.x.x.x:9092,x.x.x.x:9092"
topics => ["filebeatlog"]
#group_id => “test-consumer-group”
codec => "json"
consumer_threads => 3
decorate_events => true
}}
设置索引:
output {
# log_type和之前配置的自定义字段对应
if [fields][log_type] == "action" {
elasticsearch {
hosts => ["http://x.x.x.x:9200","http://x.x.x.x.123:9200","http://x.x.x.x:9200"]
index => "action_test05" #定义一个索引的名称
}
}
if [fields][log_type] == "gateway" {
elasticsearch {
hosts => ["http://x.x.x.x:9200","http://x.x.x.x:9200","http://x.x.x.x:9200"]
index => "gateway_test5"
}
}
Kibana设置
server.port: 5601
#开启默认端口5601
server.host: “x.x.x.x” #kibana站点IP
elasticsearch.url: http://x.x.x.x:9200 #只想ES服务所在IP Port
kibana.index: “.kibana”