springboot-fek
目标
单点安装filebeat -> elasticsearch -> kibana 解析spring boot 日志
FEK方式,日志收集使用filebeat收集springboot日志文件信息,发送至es。
环境
服务器列表
- 192.168.1.100 filebeat client
- 192.168.1.11 kibana elasticsearch server
软件环境
- jdk 1.8
- centos 7.6
- elk 7.3 (current yum latest)
双机准备
两台机器加入ELK yum仓库
rpm --import https://packages.elastic.co/GPG-KEY-elasticsearch
vi /etc/yum.repos.d/elastic.repo
[elastic-7.x]
name=Elastic repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
es and kibana安装
192.168.1.11 执行
yum -y install elasticsearch
yum -y install kibana
systemctl enable elasticsearch
systemctl enable kibana
9200 非localhost可访问
vi /etc/elasticsearch/elasticsearch.yml
network.host: 0.0.0.0
discovery.seed_hosts: ["0.0.0.0"]
非localhost IP可访问kibana
vi /etc/kibana/kibana.yml
server.host: "192.168.1.11"
elasticsearch.hosts: ["http://localhost:9200"]
启动
yum restart elasticsearch
yum restart kibana
filebeat 安装
192.168.1.100 执行
yum -y install filebeat
systemctl enable filebeat
修改filebeat生成默认索引名称
vi /etc/filebeat/filebeat.yml
output.elasticsearch:
# Array of hosts to connect to.
hosts: ["192.168.1.11:9200"]
setup.ilm.enabled: auto
setup.ilm.rollover_alias: "springapp1"
setup.ilm.pattern: "{now/d}-000001"
上传springboot应用解析模块
-
上传 springboot 目录至
/usr/share/filebeat/module
目录 -
上传 springboot.yml.disabled 文件至
/etc/filebeat/modules.d
目录
目录及文件在项目 filebeat 目录下
修改新增模块应用名称及收集日志来源
根据自己springboot 应用日志位置不同修改文件内容,默认是/root/log.txt
vi /usr/share/filebeat/module/springboot/debug/manifest.yml
os.linux:
- /root/log.txt
启用新日志收集模块
filebeat modules enable springboot
systemctl restart filebeat
应用部署
略
测试源码可通过 giteee 下载
- git clone https://github.com/walkwolf/springboot-fek.git
- cd spring-boot-fek
- mvn clean package
- java -jar springboot-fek.jar
验证
- springboot 日志
/root/log.txt
有内容 - 浏览器http://192.168.1.100:8080/test 可看到当前系统时间
- 浏览器http://192.168.1.100:8080/fail 可
/root/log.txt
看到异常堆栈信息 - chrome head 插件 访问 192.168.1.11:9200 可看到es索引情况,可见索引springapp1-yyyy.MM.dd-000001,索引。docs 数字不为0
- http://192.168.1.11:5601/ kibana discover 新建springapp1-*,可按到springboot日志内容,并可正确解析 level、TID、THREADNAME、message输出
- kibana 查看多行处理正常
调试提示
重新开始收集日志
- chrome es head 插件删除索引springapp1-yyyy.MM.dd-000001
- 停止filebeat
systemctl stop filebeat
- 删除现有filebeat 进度
rm -rf /var/lib/filebeat
- 删除filebeat module 在es缓存
curl XDELETE http://192.168.1.11:9200/_ingest/pipeline/filebeat-7.3.0-springboot-debug-default
- 修改调试位置
- 启动filebeat收集
systemctl start filebeat
关键日志
filebeat可以开启日志,或者直接从系统日志查看启动运行情况
tail -f /var/log/message
核心点
filebeat springboot module(/usr/share/filebeat/module/springboot/debug/default.json
) 解析配置及logback日志格式匹配
附1:开放端口号
- filebeat
- kibana 5601
- elasticsearch 9200
- elasticsearch 9300 集群内TCP