文章目录
ELK整合实战
案例:采集SpringBoot应用日志
一个springboot应用,打了一个jar包,使用nohup java -jar XXX.jar &运行
日志内容如下所示
2024-08-16 16:04:04.605 INFO 9164 --- [nio-8081-exec-1] com.hs.single.controller.UserController : 请求参数为:1
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4196ffc2] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@790df42b] will not be managed by Spring
==> Preparing: SELECT id,username,password,name,description,status,create_time,update_time FROM sys_user WHERE id=?
==> Parameters: 1(Long)
<== Total: 0
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@4196ffc2]
使用FileBeats将日志发送到Logstash
创建配置文件filebeat-logstash.yml,配置FileBeats将数据发送到Logstash
vim filebeat-logstash.yml
#因为Tomcat的web log日志都是以IP地址开头的,我们应用日志一般是以日期时间开头。所以我们需要修改下匹配字段。
# 不以日期时间开头的行追加到上一行
filebeat.inputs:
- type: log
enabled: true
paths:
- /root/application/nohup.out
multiline.pattern: '^\d{4}-\d{2}-\d{2}'
multiline.negate: true
multiline.match: after
output.logstash:
enabled: true
hosts: ["192.168.75.65:5044"]
- pattern:正则表达式
- negate:true 或 false;默认是false,匹配pattern的行合并到上一行;true,不匹配pattern的行合并到上一行
- match:after 或 before,合并到上一行的末尾或开头
# 启动可能会报错 因为安全原因不要其他用户写的权限,去掉写的权限就可以了,
chmod 644 filebeat-logstash.yml
启动FileBeat,并指定使用指定的配置文件
# -e 前台运行 -c 指定配置文件
./filebeat -e -c filebeat-logstash.yml
可能出现的异常:
Exiting: error loading config file: config file ("filebeat-logstash.yml") can only be writable by the owner but the permissions are "-rw-rw-r--" (to fix the permissions use: 'chmod go-w /home/es/filebeat-7.17.3-linux-x86_64/filebeat-logstash.yml')
因为安全原因不要其他用户写的权限,去掉写的权限就可以了
Failed to connect to backoff(async(tcp://192.168.75.65:5044)): dial tcp 192.168.75.65:5044: connect: connection refused
FileBeat将尝试建立与Logstash监听的IP和端口号进行连接。但此时,我们并没有开启并配置Logstash,所以FileBeat是无法连接到Logstash的。
配置Logstash接收FileBeat收集的数据并打印
输入的使用5044端口接收输入,输出是直接在控制台打印,查看是否能正常接收数据
vim config/filebeat-console.conf
# 配置从FileBeat接收数据
input {
beats {
port => 5044
}
}
output {
stdout {
codec => rubydebug
}
}
启动logstash
# -t检查配置文件是否存在语法错误
[root@hs-es-node1 logstash-7.17.3

1852

被折叠的 条评论
为什么被折叠?



