• (0.3)logstash安装


    【基本介绍】

    官方文档:https://www.elastic.co/guide/en/logstash/current/first-event.html

    【0.1】概念介绍

    Logstash是一个具有实时管道的开源数据收集引擎。可以动态地统一不同来源的数据,并将数据归到不同目的地。也是一个管理事件和日志工具。你可以用它来收集日志,分析它们,并将它们储存起来以供以后使用。

    Logstash 通常都是和 Kibana 以及 Elasticsearch 一起使用,且版本要一样。

    【0.2】save your event

      Logstash管道具有两个必需元素inputoutput,以及一个可选元素filter输入插件使用来自源的数据,过滤器插件根据您的指定修改数据,输出插件将数据写入目标。

      

    【1】Centos7.X 下载

    【1.1】下载

    要和 es/kibana 下载同一个版本,最佳;

    https://www.elastic.co/cn/downloads/logstash

      

    【1.2】前置环境配置(JVM)

    Logstash需要以下版本之一:

    • Java 8
    • Java 11
    • Java 14

    使用 官方的Oracle发行版或开源发行版,例如 OpenJDK

    如果要使用捆绑版本以外的JDK,请使用JAVA_HOME环境变量。如果您将JAVA_HOME环境变量设置为使用自定义JDK,则即使升级后,Logstash仍将继续使用您指定的JDK版本。

      

     安装包里有自带捆绑JDK;

    注意,如果操作系统并环境变量中没有配置 JAVA_HOME,则使用其自带的捆绑JDK;

    【2】安装

    【2.1】解压、移动位置、授权

    tar -zxvf logstash-7.11.1-linux-x86_64.tar.gz 
    mv logstash-7.11.1 /usr/local/logstash
    groupadd elk
    useradd elk -g elk
    chown -R elk:elk /usr/local/logstash

    【2.2】快速启动的方法

    #启动 基本的 intput output
    #stdin stdout 标准输入、标准输出插件
    /usr/local/logstash/bin/logstash -e 'input{ stdin{} } output{ stdout{} }'
    
    # codec插件,指定输出格式为json
    /usr/local/logstash/bin/logstash -e 'input{ stdin{} } output{ stdout{ codec => json } }'
    
    # 日志内容写入elasticsearch
    /usr/local/logstash/bin/logstash -e 'input{ stdin{} } output{ elasticsearch{hosts => ["192.168.175.129:9200"]} }'
    
    #日志内容写入elasticsearch,同时标准输出
    #注意elasticsearch插件的语法格式:hosts 对应数组
    /usr/local/logstash/bin/logstash -e 'input{ stdin{} } output{ elasticsearch{hosts => ["192.168.175.129:9200"]} stdout{} }'

    【3】启动演示

    【3.1】标准输入、输出启动演示

    (1)启动

    su -l elk -c "/usr/local/logstash/bin/logstash -e 'input{ stdin{} } output{ stdout{} }'"

    机器性能太差启动花了好几分钟,我还以为我出问题了呢,详细启动信息如下图:

      

    (2)输入,输出,核验

      

     在默认情况下,stdout输出插件的编码解释器为 rubydebug,所以输出内容中包含了时间、版本等额外信息;其中 message 就是我们输入的信息了;

    (3)停止,我们没有后台运行,直接 ctrl c 即可

      

    【3.2】更换编解器启动

     在默认情况下,stdout输出插件的编码解释器为 rubydebug,所以输出内容中包含了时间、版本等额外信息;其中 message 就是我们输入的信息了;

    换一些编码解码器试试:

    (1)JSON

    /usr/local/logstash/bin/logstash -e 'input{ stdin{} } output{ stdout{ codec => json } }'

      

    (2)plain

    /usr/local/logstash/bin/logstash -e 'input{ stdin{} } output{ stdout{ codec => plain } }'

      

    【3.3】使用配置文件启动,连接 ES

    在我们上面几种启动方法中,都是直接使用命令加 -e 参数传输配置字符串,指定了标准输入 stdin 和 标准输出 stdout 插件

    (1)修改配置文件

    logstash有两种类型的文职文件,一种是 .yml,一种是.conf;

    我们这次用 .conf

    vim /usr/local/logstash/config/logstash-sample.conf

    input {
      stdin {
      }
    }
    
    output {
      elasticsearch {
        host = > ["http://192.168.175.129:9200"]
        index = > "stdin"
      }
    }

    里面有个默认简单案例配置在里面,我们注释掉就好了;然后把我们上面的代码粘贴进来

      

    (2)以配置文件启动

    记得把配置文件修改成utf8格式不然十有八九就报错

    /usr/local/logstash/bin/logstash -f /usr/local/logstash/config/logstash-sample.conf

    【错误】

    (1) Failed to execute action {:action=>LogStash::PipelineAction::Create/pipeline_id:main

      

     解决:把.conf  文件转成utf8格式

     (2)org.jruby.exceptions.SystemExit: (SystemExit) exit

    org.jruby.exceptions.SystemExit: (SystemExit) exit
            at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:747) ~[jruby-complete-9.2.13.0.jar:?]
            at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:710) ~[jruby-complete-9.2.13.0.jar:?]
  • 相关阅读:
    CentOS安装扩展软件支持库
    SpringBoot 定时任务 @Scheduled cron表达式
    docker启动mysql 自定义配置文件
    Informix从一个表更新多选数据到另一个表
    maven构建web项目,用jetty测试的配置pom.xml
    STSdb数据库的实现使用类
    C#操作MySQL的类
    C#操作SQLServer2012类
    小米开源数据库<pegasus>简介
    Java虚拟机运行时内存区域简析
  • 原文地址:https://www.cnblogs.com/gered/p/14473420.html
Copyright © 2020-2023  润新知