单点安装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
192.168.1.11 执行
yum -y install elasticsearch
yum -y install kibana
systemctl enable elasticsearch
systemctl enable kibana
vi /etc/elasticsearch/elasticsearch.yml
network.host: 0.0.0.0
discovery.seed_hosts: ["0.0.0.0"]
vi /etc/kibana/kibana.yml
server.host: "192.168.1.11"
elasticsearch.hosts: ["http://localhost:9200"]
yum restart elasticsearch
yum restart kibana
192.168.1.100 执行
yum -y install filebeat
systemctl enable 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 目录至
/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/normal 可看到返回normal,并生成日志
- 浏览器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日志格式匹配
- filebeat
- kibana 5601
- elasticsearch 9200
- elasticsearch 9300 集群内TCP