Logstash 简明教程

Logstash - Installation

要在系统上安装 Logstash,我们应遵循以下步骤−

To install Logstash on the system, we should follow the steps given below −

Step 1 − 检查计算机中安装的 Java 版本;它应为 Java 8,因为它与 Java 9 不兼容。您可以通过以下方式进行检查:

Step 1 − Check the version of your Java installed in your computer; it should be Java 8 because it is not compatible with Java 9. You can check this by −

在 Windows 操作系统 (OS) 中(使用命令提示符)−

In a Windows Operating System (OS) (using command prompt) −

> java -version

在 UNIX OS 中(使用终端)-

In UNIX OS (Using Terminal) −

$ echo $JAVA_HOME

Step 2 − 从以下位置下载 Logstash −

Step 2 − Download Logstash from −

  1. For Windows OS, download the ZIP file.

  2. For UNIX OS, download the TAR file.

  3. For Debian OS download the DEB file.

  4. For Red Hat and other Linux distributions, download the RPN file.

  5. APT and Yum utilities can also be used to install Logstash in many Linux distributions.

Step 3 − 安装 Logstash 的过程非常简单。让我们看看如何在不同平台上安装 Logstash。

Step 3 − The installation process for Logstash is very easy. Let’s see how you can install Logstash on different platforms.

Note − 安装文件夹中不要有任何空格或冒号。

Note − Do not put any whitespace or colon in the installation folder.

  1. Windows OS − Unzip the zip package and the Logstash is installed.

  2. UNIX OS − Extract the tar file in any location and the Logstash is installed.

$tar –xvf logstash-5.0.2.tar.gz

Using APT utility for Linux OS −

Using APT utility for Linux OS −

  1. Download and install the Public Signing Key −

$ wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
  1. Save the repository definition −

$ echo "deb https://artifacts.elastic.co/packages/5.x/apt stable main" | sudo
   tee -a /etc/apt/sources.list.d/elastic-5.x.list
  1. Run update −

$ sudo apt-get update
  1. Now you can install by using the following command −

$ sudo apt-get install logstash

Using YUM utility for Debian Linux OS

Using YUM utility for Debian Linux OS

  1. Download and install the Public Signing Key −

$ rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
  1. Add the following text in the file with the .repo suffix in your o “/etc/yum.repos.d/” directory. For example, logstash.repo

[logstash-5.x]
name = Elastic repository for 5.x packages
baseurl = https://artifacts.elastic.co/packages/5.x/yum
gpgcheck = 1
gpgkey = https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled = 1
autorefresh = 1
type = rpm-md
  1. You can now install Logstash by using the following command −

$ sudo yum install logstash

Step 4 − 前往 Logstash 主目录。在 bin 文件夹内,如果使用 Windows,则运行 elasticsearch.bat 文件,或者你同样可以通过命令提示符或终端来执行相同操作。在 UNIX 中运行 Logstash 文件。

Step 4 − Go to the Logstash home directory. Inside the bin folder, run the elasticsearch.bat file in case of windows or you can do the same using the command prompt and through the terminal. In UNIX, run the Logstash file.

我们需要指定输入源、输出源和可选项过滤器。为了验证安装,你可以使用标准输入流 (stdin) 作为输入源和标准输出流 (stdout) 作为输出源通过基本配置来运行它。你可以在命令行中使用 –e 选项指定配置。

We need to specify the input source, output source and optional filters. For verifying the installation, you can run it with the basic configuration by using a standard input stream (stdin) as the input source and a standard output stream (stdout) as the output source. You can specify the configuration in the command line also by using –e option.

In Windows −

In Windows −

> cd logstash-5.0.1/bin
> Logstash -e 'input { stdin { } } output { stdout {} }'

In Linux −

In Linux −

$ cd logstash-5.0.1/bin
$ ./logstash -e 'input { stdin { } } output { stdout {} }'

Note − 如果使用 Windows,你可能会收到一条指出 JAVA_HOME 未设置的错误消息。就此,请在环境变量中将其设置为“C:\Program Files\Java\jre1.8.0_111”或你安装 Java 的位置。

Note − in case of windows, you might get an error stating JAVA_HOME is not set. For this, please set it in environment variables to “C:\Program Files\Java\jre1.8.0_111” or the location where you installed java.

Step 5 - Logstash Web 界面的默认端口为 9600 至 9700,在 logstash-5.0.1\config\logstash.yml 中定义为 http.port ,它将选取给定范围内的第一个可用端口。

Step 5 − Default ports for Logstash web interface are 9600 to 9700 are defined in the logstash-5.0.1\config\logstash.yml as the http.port and it will pick up the first available port in the given range.

我们可以通过浏览 http://localhost:9600 来检查 Logstash 服务器是否启动和运行,或者端口是否不同,然后检查命令提示符或终端。我们可以看到分配的端口,如 “成功启动 Logstash API 终结点 {:port ⇒ 9600}”。它将返回一个 JSON 对象,其中包含有关已安装 Logstash 的以下信息 -

We can check if the Logstash server is up and running by browsing http://localhost:9600 or if the port is different and then please check the command prompt or terminal. We can see the assigned port as “Successfully started Logstash API endpoint {:port ⇒ 9600}. It will return a JSON object, which contains the information about the installed Logstash in the following way −

{
   "host":"manu-PC",
   "version":"5.0.1",
   "http_address":"127.0.0.1:9600",
   "build_date":"2016-11-11T22:28:04+00:00",
   "build_sha":"2d8d6263dd09417793f2a0c6d5ee702063b5fada",
   "build_snapshot":false
}