ELK安装整合springboot

概述

ELK是 elasticsearch + logstash + kibana 的简称。这套组合类似于MVC模型,其中logstash是controller层,数据首先传给它,它负责将数据进行过滤和格式化;elasticsearch是model层,负责数据的存储,建立搜索索引;kibana是view层,负责数据的展示。

环境

系统:centos 6.10
软件版本:tar包安装
elasticsearch-6.3.1
logstash-6.3.1
kibana-6.3.1

安装

直接tar -zxvf 解压缩即可
演示安装在/opt 下

Elasticsearch

配置

主要配置文件/etc/elasticsearch/elasticsearch.yml,修改如下内容

# Use a descriptive name for your cluster:
cluster.name: tisco_es
#bootstrap.memory_lock: true 针对低版本centos的
bootstrap.system_call_filter: false
# Set the bind address to a specific IP (IPv4 or IPv6):
network.host: 0.0.0.0
# Set a custom port for HTTP:
http.port: 9200

启动

命令目录:cd /opt/elasticsearch-6.3.1/bin/
./elasticsearch -d 后台启动
curl http://172.17.171.228:9200/
如果有类似如下的输出则是正常启动了
在这里插入图片描述

logstash

配置

/opt/logstash-6.3.1/ 下新建一个文件名为 logstash.conf,然后写入以下配置:
在这里插入图片描述

启动

安装目录下:
nohup ./bin/logstash -f ./logstash.conf &
查看启动日志:
/opt/logstash-6.3.1/logs/
查看端口:
在这里插入图片描述
9600为程序端口,4560为监听端口

kibana

配置

文件:
/opt/kibana-6.3.1-linux-x86_64/config/ kibana.yml
修改内容:

# Kibana is served by a back end server. This setting specifies the port to use.
server.port: 5601
server.host: "0.0.0.0" #监听任意地址
# The URL of the Elasticsearch instance to use for all your queries.
elasticsearch.url: http://172.17.171.228:9200

启动

/opt/kibana-6.3.1-linux-x86_64/bin/kibana

访问网站:
http://172.17.171.228:5601
在这里插入图片描述

整合spring 项目

添加依赖:
在这里插入图片描述
logback配置文件:
在这里插入图片描述

演示

Kibana管理界面创建Kinaba Index Patterns:
在这里插入图片描述
在Index pattern里输入我们在logstash配置文件logstash.conf里output.index指定的值
logstash-*
在这里插入图片描述
点击Next Step,在下拉框里选择@timestamp:
在这里插入图片描述
最后点击Create Index Pattern按钮完成创建
在Kibana里搜索相应的logback日志:
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spring Boot可以很容易地集成ElasticSearch作为日志存储,然后使用Logstash将日志从Spring Boot应用程序传输到ElasticSearch,最后可以使用Kibana进行数据可视化。 以下是实现Spring Boot整合ELK的基本步骤: 1. 安装ElasticSearch,Logstash和Kibana。 2. 当Spring Boot应用程序运行时,将日志记录到文件中。 3. 使用Logstash配置文件来监控日志文件,并将数据发送到ElasticSearch。 4. 在Kibana中创建一个索引模式来解析ElasticSearch中的数据。 5. 创建仪表板和可视化,以显示日志数据。 下面是一个简单的Logstash配置文件,将日志文件发送到ElasticSearch: ``` input { file { path => "/path/to/spring-boot-app.log" sincedb_path => "/dev/null" start_position => "beginning" } } filter { grok { match => { "message" => "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:loglevel} \[%{DATA:thread}\] %{DATA:class} - %{GREEDYDATA:logmessage}" } } } output { elasticsearch { hosts => [ "localhost:9200" ] index => "spring-boot-app-logs-%{+YYYY.MM.dd}" } stdout { codec => rubydebug } } ``` 这个配置文件使用Grok来解析日志文件中的日志条目,并将其发送到ElasticSearch中的名为“spring-boot-app-logs”索引的索引中。stdout输出是可选的,它允许将数据输出到控制台进行调试。 在使用Logstash转发日志数据之前,确保运行ElasticSearch和Kibana,并且ElasticSearch集群和索引模式已经设置好。在Kibana中,您可以通过“索引模式”页面创建新的索引模式。在这个页面上,您需要指定ElasticSearch索引的名称模式,并为每个字段定义Type。 创建模式后,您可以使用可视化编辑器创建仪表板和可视化,以显示日志数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值