栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

SpringBoot整合ELK日志收集

SpringBoot整合ELK日志收集

首先下载ELK,官网:https://www.elastic.co/cn/
小编这里下载的7.16.1版本,注意,elasticsearch、logstash、kibana的版本要一致,否则可能报错。

需要提前安装JDK1.8。

启动顺序为:Logstash >= Elasticsearch > Kibana

1. Elasticsearch
# 解压
tar -zxvf elasticsearch-7.16.1-linux-x86_64.tar.gz
# 切换目录
cd elasticsearch-7.16.1/

修改配置文件 config/elasticsearch.yml

node.name: node-1
network.host: 192.168.12.128
http.port: 9200
cluster.initial_master_nodes: ["node-1"]

启动es:

# ./bin/elasticsearch -d 加-d后台运行
./bin/elasticsearch

注:若启动时报错不允许root用户启动、权限不足、内存大小与默认配置等问题,请查阅小编的上一篇文章:https://blog.csdn.net/RookiexiaoMu_a/article/details/122023471

启动成功,访问192.168.37.189:9200

2. Logstash
# 解压
tar -zxvf logstash-7.16.1-linux-x86_64.tar.gz
# 切换目录
cd logstash-7.16.1/

修改配置文件 config/logstash.yml,在最后追加:

http.host: "192.168.12.128"

在logstash-7.16.1目录下编辑文件:

vi logstash.conf

输入以下内容:

input {
  tcp {
    #模式选择为server
    mode => "server"
    #ip和端口根据自己情况填写,端口默认4560,对应下文logback.xml里appender中的destination
    host => "192.168.12.128"
    port => 4560
    #格式json
    codec => json_lines
  }
}
filter {
  #过滤器,根据需要填写
}
output {
  elasticsearch {
    action => "index"
    #这里是es的地址,多个es要写成数组的形式
    hosts => "192.168.12.128:9200"
    #用于kibana过滤,可以填项目名称
    index => "api_log"
  }
}

在logstash-7.16.1目录下使用命令启动:

./bin/logstash -f logstash.conf

访问http://192.168.12.128:9600,成功的话会显示一个JSON串

3. Kibana
# 解压
tar -zxvf kibana-7.16.1-linux-x86_64.tar.gz
# 切换目录
cd kibana-7.16.1-linux-x86_64/

修改配置文件 config/kibana.yml

server.port: 5601
server.host: "0.0.0.0"
# 原默认是30000(30s),酌情修改,也可使用默认
elasticsearch.requestTimeout: 60000
#修改为es的地址【.url的方式会报错】
#elasticsearch.url: http://192.168.12.128:9200
elasticsearch.hosts: ["http://192.168.12.128:9200/"]

elasticsearch.url的方式会报错:
FATAL Error: [elasticsearch.url]: definition for this key is missing

进入kibana-7.16.1-linux-x86_64目录启动:

# 非后台启动
./bin/kibana --allow-root
# 后台启动
nohub ./bin/kibana --allow-root &

kibana也不能使用root用户启动,可以创建一个新用户给予权限启动,也可在启动命令后追加 --allow-root

启动成功访问页面:http://192.168.12.128:5601

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/674139.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号