[TOC]
### 管道配置文件的結構
對于每一種你想要添加到事件處理管道中的插件,Logstash管道配置文件中都有一個獨立的配置段.示例:
```json
# This is a comment. You should use comments to describe
# parts of your configuration.
input {
...
}
filter {
...
}
output {
...
}
```
每個配置段包含一個或多個插件的配置.如果你定義了多個filter,他們會按照配置文件中出現的順序生效.
### 插件配置
一個插件的配置由插件名和其后跟隨的一塊此插件的設置組成.如,這個配置段包含兩個文件的inputs:
```con
input {
file {
path => "/var/log/message"
type => "syslog"
}
file {
path => "/var/log/apache/access.log"
type => "apache"
}
}
```
這個示例中,配置了兩個設置給兩個不同的inputs類型:path 和 type.
你可以根據插件的不同類型進行不同的配置.更多關于每個插件的信息可以查看:[Input Plugins](https://www.elastic.co/guide/en/logstash/current/input-plugins.html), [Output Plugins](https://www.elastic.co/guide/en/logstash/current/output-plugins.html), [Filter Plugins](https://www.elastic.co/guide/en/logstash/current/filter-plugins.html), and [Codec Plugins](https://www.elastic.co/guide/en/logstash/current/codec-plugins.html).
### 值類型
插件的某個設定的值可以使用某些類型的值來指定.如布爾,列表,或哈希.下面是支持的數據類型.
#### 數組
現在這種類型基本不再使用,而是使用標準類型如`string`來定義為形如`:list => true`以方便檢查.對于仍然需要處理哈希列表或混合之類不需要檢查的地方仍然需要.
原文:This type is now mostly deprecated in favor of using a standard type like string with the plugin defining the :list => true property for better type checking. It is still needed to handle lists of hashes or mixed types where type checking is not desired.
示例:
```conf
users => [ {id => 1, name => bob}, {id => 2, name => jane } ]
```
#### 列表
本身不是類型,但是可以有屬性類型.This makes it possible to type check multiple values. Plugin authors can enable list checking by specifying `:list => true` when declaring an argument.
示例:
```conf
path => [ "/var/log/messages", "/var/log/*.log" ]
uris => [ "http://elastic.co", "http://example.net" ]
```
這個示例配置`path`,一個包含三個字符串中的每個元素的`string`列表.同時使用`uris`配置了一個URI列表,如果包含不可用的URIs,配置將會失敗.原文:This example configures path, which is a string to be a list that contains an element for each of the three strings. It also will configure the uris parameter to be a list of URIs, failing if any of the URIs provided are not valid.
> <font color=#1E90FF size=4>TIP</font> :我只看到兩個字符串,但是原文是三個.可能我理解有誤.但我覺得是文檔寫錯了.
#### 布爾
一個布爾值必然是`true`或`false`.注意`true`和`false`關鍵字不要使用引號引起來.
示例:
```conf
ssl_enable => true
```
#### 字節
字節字段是表示有效字節單位的字符串的字段.是一種很方便的方式在你的插件配置中聲明特定的大小. SI (k M G T P E Z Y)和二進制(Ki Mi Gi Ti Pi Ei Zi Yi)單位都是支持的.二進制使用base-1024換算,SI使用1000換算.這個字段不區分大小寫,并且在值和單位之間可以有空格.如果沒有指定單位,則表示字節.
示例:
```conf
my_bytes => "1113" # 1113 bytes
my_bytes => "10MiB" # 10485760 bytes
my_bytes => "100kib" # 102400 bytes
my_bytes => "180 mb" # 180000000 bytes
```
一個codec是Logstash codec用來表示數據的名字.Codec可以同時用在inputs和outputs.
Input codecs提供了一中在你的數據進入input之前解碼數據的簡單的方法.Output codecs提供了一種在你的數據從output出去之前編碼的簡單的方法.使用input和output codecs可以不必在你的Logstash管道中設置單獨的filter.
可以在[Codec Plugins](https://www.elastic.co/guide/en/logstash/current/codec-plugins.html)頁面查看可用的codecs列表.
示例:
```conf
codec => "json"
```
#### 哈希
一個哈希是一個格式為`"fild1" => "value1"`的K/V集合.注意多個鍵值對使用空格而不是逗號分隔.
示例:
```conf
match => {
"field1" => "value1"
"field2" => "value2"
...
}
```
#### 數字
數字必須是一個有效的數值(浮點型或整型).
示例:
```conf
port => 33
```
#### 密碼
密碼是一個不會被記錄日志或輸出的單一的字符串值.
示例:
```conf
my_password => "password"
```
#### URI
URI可以是完整的URL,如http://elastic.co/,也可以是像foobar這樣的簡單標識符。如果一個URI包含密碼類似*http://user:pass@example.net*,其中的密碼部分將不會被記錄日志或顯示.
示例:
```conf
my_uri => "http://foo:bar@example.net"
```
#### Path
一個Path是一個用來表示一個有效的操作系統path的字符串.
示例:
```conf
my_path => "/tmp/logstash"
```
#### 字符串
字符串必須是一個單字符序列.注意字符串的值需要用引號引起來,單引號雙引號都可以.
#### 轉義序列
默認情況下轉義序列是未開啟的.如果你想在引用的字符串中使用轉義序列.你需要在`logstash.yml`文件中設置`config.support_escapes: true`.當設置為`true`時,帶引號(單引號和雙引號)的字符串將按照下面的進行轉義:
| Text | Result |
| ---- | ---------------- |
| \r | 回車(ASCII 13) |
| \n | 換行(ASCII 10) |
| \t | tab(ASCII 9) |
| \\\ | 反斜杠(ASCII 92) |
| \\" | 雙引號(ASCII 34) |
| \\' | 單引號(ASCII 39) |
示例:
```conf
name => "Hello world"
name => 'It\'s a beautiful day'
```
### 注釋
注釋方式同perl,ruby,python相同.在注釋內容的前面加一個#號,并且不需要在行首.如:
```conf
# this is a comment
input { # comments can appear at the end of a line, too
#...
}
```
- Emmm
- Logstash簡介
- 開始使用Logstash
- 安裝Logstash
- 儲存你的第一個事件
- 通過Logstash解析日志
- 多個輸入和輸出插件的混合使用
- Logstash是如何工作的
- 執行模型Execution Model
- 設置并運行Logstash
- Logstash目錄布局
- Logstash配置文件
- logstash.yml
- Secrets keystore for secure settings
- 從命令行運行Logstash
- 以服務的方式運行Logstash
- 在Docker中運行Logstash
- 配置容器版Logstash
- Logging
- 關閉Logstash
- 安裝X-Pack
- 設置X-Pack
- 升級Logstash
- 使用包管理升級
- 直接下載進行升級
- 升級至6.0
- Upgrading with the Persistent Queue Enabled
- 配置Logstash
- 管道配置文件的結構
- 訪問配置中的事件數據和字段
- 在配置中使用環境變量
- Logstash配置示例
- 多管道
- 管道間通信(beta)
- 重載配置文件
- 管理多行事件
- Glob Pattern Support
- Converting Ingest Node Pipelines
- Logstash間通信
- 配置集中式管道管理
- X-Pack Monitoring
- X-Pack Security
- X-Pack Settings
- Field References Deep Dive(深入字段引用)
- 管理Logstash
- 集中式管道管理
- 使用Logstash模塊
- 使用Elastic Cloud
- Logstash ArcSight模塊