🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[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 #... } ```