Kibana+ElasticSearch 已经安装完毕
FileBeat配置详解(感谢作者分享):https://www.cnblogs.com/wshenjin/p/13652361.html
检测目标:监测Mycat日志,包括请求的IP,执行的SQL,以及Route路由地址
1、开启Mycat的Log Debug
进入Mycat安装目录conf
vim log4j2.xml
<asyncRoot level="debug" includeLocation="true">
## 改成Debug
- Mycat.log
1、FileBeat RPM安装
## curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.9.2-x86_64.rpm
## sudo rpm -vi filebeat-7.9.2-x86_64.rpm
- vim /etc/filebeat/filebeat.yml
# ============================== Filebeat inputs ===============================
filebeat.inputs:
- type: log
enabled: true
paths:
- /home/mycatserver/mycat/logs/mycat.log #Mycat的日志
#
multiline.pattern: '^\d{4}\-\d{2}\-\d{2}\s\d{2}:\d{2}:\d{2}' ## 合并多行正则
multiline.negate: true ## 是否合并到上一行
multiline.match: after ## 追加到上一行的头还是未
# ======================= Elasticsearch template setting =======================
setup.template.settings:
index.number_of_shards: 1
#index.codec: best_compression
#_source.enabled: false
setup.template.name: "mycat"
setup.template.pattern: "mycat-*"
setup.kibana:
host: "192.168.1.111:5601"
# ================================== Outputs ===================================
# Configure what output to use when sending the data collected by the beat.
# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["192.168.1.111:9200"]
index: "mycat_log"
# index: "mycat_log_%{+yyyy.MM.dd}" #按天创建Index,需要的可以放开
# Protocol - either `http` (default) or `https`.
#protocol: "https"
# Authentication credentials - either API key or username/password.
#api_key: "id:api_key"
#username: "elastic"
#password: "changeme"
# ================================= Processors =================================
processors:
- add_host_metadata:
when.not.contains.tags: forwarded
- add_cloud_metadata: ~
- add_docker_metadata: ~
- add_kubernetes_metadata: ~
启动:sudo filebeat -e -c filebeat.yml -d "publish"
- 注意:filebeat6配置index需要添加setup对应项,不然启动会报错
setup.template.name: "mycat" #顶格,和output对齐
setup.template.pattern: "mycat-*" #顶格,和output对齐
output.elasticsearch:
hosts: ["192.168.1.111:9200"]
index: "mycat_log" #和hosts对齐
问题:
启动之后发现,index没用,根本没有根据配置创建index,而是filebeat-xxx,
ElasticStack从2019年1月29日的6.6.0版本的开始,引入了索引生命周期管理的功能,新版本的Filebeat则默认的配置开启了ILM,导致索引的命名规则被ILM策略控制。本文用的filebeat-7.9.2-x86_64.rpm
- 修改:
# filebeat 配置关闭 ILM 即可解决Index Pattern不生效的问题
setup.ilm.enabled: false