springboot 日志收集_SpringBoot使用ELK日志收集ELASTIC (ELK) STACK

喜欢的麻烦点个赞

1:资源

907b5c0dec994493826e5a4b90ceceb9
# 文档向导        # logstash    https://www.elastic.co/guide/en/logstash/current/index.html    #kibana    https://www.elastic.co/guide/en/kibana/current/index.html    #elasticsearch    https://www.elastic.co/guide/en/elasticsearch/current/index.html# 资源下载    https://www.elastic.co/cn/downloads/elasticsearch    https://www.elastic.co/cn/downloads/kibana    https://www.elastic.co/cn/downloads/logstash
907b5c0dec994493826e5a4b90ceceb9
8516fc0f943e47599250ee08de8c7a1d

没有VPN的我这里提供最新版本的软件包:

链接:https://pan.baidu.com/s/1XtIL_6MJgn7vplILKG31_A 提取码:825n

2:安装ELK

安装ELK基本tar –xzvf 解压就行 这里给出关键配置

Kibana配置

conf文件夹下 kibana.yml

907b5c0dec994493826e5a4b90ceceb9
修改config/kibana.yml文件配置:vim kibana.ymlkibana.yml常见配置项# pingElasticsearch超时时间elasticsearch.pingTimeout# 读取Elasticsearch数据超时时间elasticsearch.requestTimeout  #Elasticsearch主机地址elasticsearch.url: "http://ip:9200" # 允许远程访问server.host: "0.0.0.0" # Elasticsearch用户名 这里其实就是我在服务器启动Elasticsearch的用户名elasticsearch.username: "es"  # Elasticsearch鉴权密码 这里其实就是我在服务器启动Elasticsearch的密码elasticsearch.password: "es"

server.port: 5601server.host: "127.0.0.1"server.name: tanklogelasticsearch.hosts: ["http://localhost:9200/"]

907b5c0dec994493826e5a4b90ceceb9

Logstash配置

logstash目录下 新建conf文件

907b5c0dec994493826e5a4b90ceceb9
input {    file {        path => ["/usr/local/logstash/logstash-tutorial-dataset"]        type => "syslog"        tags => ["有用的","标识用的"]        start_position => "beginning"        sincedb_path => "/dev/null"    }}output {  elasticsearch {    hosts => ["http://localhost:9200"]    index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"  }}
907b5c0dec994493826e5a4b90ceceb9

3:启动配置

907b5c0dec994493826e5a4b90ceceb9
# 启动 elasticsearch    #>>>   ./elasticsearch        #访问  dgw@ubuntu:~$ curl -L http://localhost:9200/        {          "name" : "ubuntu",          "cluster_name" : "elasticsearch",          "cluster_uuid" : "CqSWrvU8TLiw_haNYjB0Ow",          "version" : {            "number" : "7.6.0",            "build_flavor" : "default",            "build_type" : "tar",            "build_hash" : "7f634e9f44834fbc12724506cc1da681b0c3b1e3",            "build_date" : "2020-02-06T00:09:00.449973Z",            "build_snapshot" : false,            "lucene_version" : "8.4.0",            "minimum_wire_compatibility_version" : "6.8.0",            "minimum_index_compatibility_version" : "6.0.0-beta1"          },          "tagline" : "You Know, for Search"        }# 启动 kibana    #>>>   kibana-7.6.0-linux-x86_64/bin$ ./kibana        #访问  dgw@ubuntu:~$ curl -L http://localhost:5601/# 启动 logstash   #>>>   dgw@ubuntu:~/Documents/logstash/logstash-7.6.0/bin$  ./logstash -f ../config/logstash-my.conf
907b5c0dec994493826e5a4b90ceceb9

浏览器http://localhost:5601/ 显示下面的画面即为成功

4c3dbe93ad474428afaf158ff509305f

4:导入POM依赖

net.logstash.logback    logstash-logback-encoder    6.3

5配置logstash

907b5c0dec994493826e5a4b90ceceb9
<?xml version="1.0" encoding="UTF-8"?>127.0.0.1:4560UTC                        {                        "logLevel": "%level",                        "serviceName": "${springAppName:-}",                        "pid": "${PID:-}",                        "thread": "%thread",                        "class": "%logger{40}",                        "rest": "%message"                        }                    
907b5c0dec994493826e5a4b90ceceb9
907b5c0dec994493826e5a4b90ceceb9
input {  tcp {    mode => "server"    host => "0.0.0.0"    port => 4560    codec => json_lines  }}output {  elasticsearch {    hosts => "localhost:9200"    index => "springboot-logstash-%{+YYYY.MM.dd}"  }}
907b5c0dec994493826e5a4b90ceceb9

6: 启动类设置输出信息

907b5c0dec994493826e5a4b90ceceb9
@SpringBootApplication@RestControllerpublic class SpringbootLogstashApplication {    Logger logger = LoggerFactory.getLogger(SpringbootLogstashApplication.class);    @GetMapping("test")    public void test(){        logger.info("测试初始一些日志吧!");    }    public static void main(String[] args) {        SpringApplication.run(SpringbootLogstashApplication.class, args);    }}
907b5c0dec994493826e5a4b90ceceb9

7:测试

对maven 项目执行 mvn package 打包 得到 jar文件 拷贝到Linux下

dgw@ubuntu:~/Documents$ java -jar logstash-0.0.1-SNAPSHOT.jar
1f798c507b034b5aa68d624c122ac4f9

上面页面创建索引后, 在发现页面: 找到我们项目info

f1612b97542347da8783a469ca6f9c15
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值