Logstash-Logstash简介+安装

Posted on 2020-08-18 07:48  MissRong  阅读(240)  评论(0)    收藏  举报

Logstash

一、Logstash简介

Logstash is a tool for managing events and logs. You can use it to collect logs, parse them, and store them for later use (like, for searching).

logstash是一个数据分析软件,主要目的是分析log日志。整一套软件可以当作一个MVC模型,logstash是controller层,Elasticsearch是一个model层,kibana是view层。

首先将数据传给logstash,它将数据进行过滤和格式化(转成JSON格式),然后传给Elasticsearch进行存储、建搜索的索引,kibana提供前端的页面再进行搜索和图表可视化,它是调用Elasticsearch的接口返回的数据进行可视化。logstash和Elasticsearch是用Java写的,kibana使用node.js框架。

这个软件官网有很详细的使用说明,https://www.elastic.co/,除了docs之外,还有视频教程。这篇博客集合了docs和视频里面一些比较重要的设置和使用。

 

二、Logstash 安装

直接下载官方发布的二进制包的,可以访问 https://www.elastic.co/downloads/logstash 页面找对应操作系统和版本,点击下载即可。

下载之后解压即可使用

 

在终端中,像下面这样运行命令来启动 Logstash 进程:

# bin/logstash -e 'input{stdin{}}output{stdout{codec=>rubydebug}}' 

操纵文件的话就用-f

解释:

input:{标准的输入--命令行}

output{标准的输出}

codec=>输出的样式

注意:如果出现如下报错,请调高虚拟机内存容量。

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)

#

# There is insufficient memory for the Java Runtime Environment to continue.

# Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.

# An error report file with more information is saved as:

# /usr/local/logstash-6.6.2/confs_test/hs_err_pid3910.log

然后你会发现终端在等待你的输入。没问题,敲入 Hello World,回车,

{

      "@version" => "1",

          "host" => "***",

       "message" => "hello world",

    "@timestamp" => 2019-03-18T02:51:18.578Z

}

每位系统管理员都肯定写过很多类似这样的命令:

cat randdata | awk '{print $2}' | sort | uniq -c | tee sortdata。

Logstash 就像管道符一样!

你输入(就像命令行的 cat )数据,然后处理过滤(就像 awk 或者 uniq 之类)数据,最后输出(就像 tee )到其他地方。

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3