spring boot 结合 ELK
elasticsearch
install elasticsearch
apt-get upgrade
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
apt-get install apt-transport-https
apt-get update
apt-get install elasticsearch
configurate elasticsearch
vim /etc/elasticsearch/elasticsearch.yml
1
2network.host: 0.0.0.0
port: 9200启动:
systemctl start elasticsearch.service
测试:
curl -X GET "localhost:9200"
kibana
install kibana
apt-get install kibana
Configure Kibana
vim etc/kibana/kibana.yml
1
2
3server.port: 5601
server.host: "localhost"
elasticsearch.hosts: ["http://localhost:9200"]启动:
systemctl start kibana
开机启动(可选):
systemctl enable kibana
开放防火墙, 浏览器测试访问
http://localhost:5601
Logstash
install logstash
主要作用: input 收集, filter过滤, output输出
apt-get install logstash
开机启动(可选):
systemctl enable logstash
Configure Logstash
vim /etc/logstash/conf.d/logstash.conf
其他配置配置说明: 以
beats
为例,下面使用filebeat
1
2
3
4
5
6
7
8
9
10
11
12input {
beats {
port => 5044
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "%{[@metadata][beat]}-%{[@metadata][version]}"
}
}
FileBeat(可选)
install fileBeat
apt-get install filebeat
configure filebeat
vim /etc/filebeat/filebeat.yml
注释es配置,打开logstash配置
1 | # output.elasticsearch: |
(可选)启动一个module(预设的一些日志处理模块):
filebeat modules enable system
system module在linux系统下会对/var/logs下面所有日志传输
其他配置加载日志:
filebeat setup -e
其他通用日志设置修改:
1
2
3
4
5
6
7
8
9
10
11
12- type: filestream
# Unique ID among all inputs, an ID is required.
id: my-filestream-id
# Change to true to enable this input configuration.
enabled: false
# Paths that should be crawled and fetched. Glob based paths.
paths:
- /var/log/*.log
#- c:\programdata\elasticsearch\logs\*enable 设置为ture, paths设置为日志文件目录
启动:
systemctl start filebeat
开机启动(可选): systemctl enable filebeat
spring-boot
add dependency
1 | implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '7.2' |
configure logstash
input moule选择tcp, 其他不变, 详见文档
1 | input { |
set log file
logback.xml
1 | <?xml version="1.0" encoding="UTF-8"?> |