The configuration file allows the user to control the input and output behavior of Fluentd by (1) selecting input and output plugins and (2) specifying the plugin parameters. The file is required for Fluentd to operate properly.
配置文件允许用户控制Fluentd的输入和输出行为,通过(1)选择输入和输出插件(2)指定插件的参数。Fluentd的正常运作,这个配置文件是必须的。
If you installed Fluentd using the rpm or deb packages, the config file is located at /etc/td-agent/td-agent.conf. sudo /etc/init.d/td-agent reload
will reload the config file.
如果你安装Fluentd运用的是rpm或是deb 的安装包,这个配置文件在/etc/td-agent/td-agent.conf 这个目录。重新安装将会安装conf 配置文件。
$ sudo vi /etc/td-agent/td-agent.conf
If you installed Fluentd using the Ruby Gem, you can create the configuration file using the following commands. Sending a SIGHUP signal will reload the config file.
如果你安装Fluentd 用的是Ruby Gem,你可以创建一个配置文件运用下面的命令。发出一个终止信号将会重新安装配置文件。(如果你修改了配置文件—fluent.conf 文件,ctrl c c 终止进程,然后在配置文件下重新启动)
$ ctrl c
$fluentd -c fluent.conf
$ sudo fluentd --setup /etc/fluent $ sudo vi /etc/fluent/fluent.conf
The configuration file consists of the following directives:
这个配置文件由以下指令组成:
Fluentd’s input sources are enabled by selecting and configuring the desired input plugins using source directives. Fluentd’s standard input plugins include http
and forward
.
Fluentd 的输入源是通过选择和配置所需要的输入插件使用source指令。Fluentd的标准输入插件包含http和forward(转发)模式。
# Receive events from 24224/tcp #从24224/tcp 中接收事件,tcp模式
# This is used by log forwarding and the fluent-cat command #使用日志转发和fluent-cat 命令
# http://this.host:9880/myapp.access?json={"event":"data"}
Each source directive must include a type
parameter. The type
parameter specifies the input plugin to use.
The ‘source’ submits events into the Fluentd’s routing engine. An event consists of three entities: tag, time and record. The tag is a string separated by ‘.’s (e.g. myapp.access), and is used as the directions for Fluentd’s internal routing engine. The time is the UNIX time when the event occurs. The record is a JSON object.
source 把事件提交到fluentd的路由引擎中。一个事件包含三个实体标签:tag,time和record。tag是一个通过 . 来分离的字符串 (e.g. myapp.access),用作Fluentd内部路由引擎的方向。time是当事件产生unix时间。record是一个JSON对象。
(主要的是tag,用来指导方向,所要匹配的地方)
In the example above, the HTTP input plugin submits the following event::
# generated by http://this.host:9880/myapp.access?json={"event":"data"}
tag: myapp.access
time: (current time)
record: {"event":"data"}
Users can expand Fluentd’s input sources beyond the default options by writing their own plugins. For further information regarding Fluentd’s input sources, please refer to the Input Plugin Overview article.
用户可以扩展输入源Fluentd,通过编写自己的插件而超出默认选项。为了进一步关于fluentd 的信息,请参考 Input Plugin Overview 文章。(怎样修改fluentd的默认插件的内容,就是修改fluent.conf文件)
Fluentd’s output destinations are enabled by selecting and configuring the desired output plugins using match directives. Fluentd’s standard output plugins include file
and forward
.
Fluentd 的输入源是通过选择和配置所需要的输入插件使用source指令。Fluentd的标准输入插件包含http和forward(转发)模式。
# Match events tagged with "myapp.access" and match 事件是为了匹配 tag myapp.access和 这就是为什么 # store them to /var/log/fluent/access.%Y-%m-%dtype file path /var/log/fluent/access type file format /var/log/fluent/myapp_hourly time_slice_format %Y%m%d%H
Each match directive must include a match pattern and a type
parameter. Match patterns are used to filter the events. Only events with tag matching the pattern will be sent to the output destination. The type
parameter specifies the output plugin to use.
For example, the user can send all matches to the pattern myapp.accesslog.**
to file
in a specified directory.
Users can expand Fluentd’s output sources beyond the default options by writing their own plugins. For further information regarding Fluentd’s output destinations, please refer to the Output Plugin Overview article.
The following match patterns can be used:
*
matches a single tag element. 匹配单个tag元素 a.* = a.b
不等于a.b.c
a.*
matches a.b
, but does not match a
or a.b.c
**
matches zero or more tag elements. a.**=a和
a.b
和a.b.c
a.**
matches a
, a.b
and a.b.c
{X,Y,Z}
matches X, Y, or Z, where X, Y, and Z are match patterns.
For example, the pattern {a,b}
matches a
and b
, but does not match c。
{a,b}
匹配 a
and b
,但不匹配 c
This can be used in combination with the *
or **
patterns. Examples include a.{b,c}.*
and a.{b,c.**}
Directives in separate configuration files can be imported using the include directive::
指令在单独的配置文件可以导入使用 include 指令::
# Include config files in the ./config.d directory include config.d/*.conf
The include directive supports regular file path, glob pattern, and http URL conventions::
include 指令支持常规路径,glob模式和http约定::
# absolute path 绝对路径 include /path/to/config.conf # if using a relative path, the directive will use # the dirname of this config file to expand the path
如果使用性对路径,这个配置文件的目录名将使用扩张后的路径命令。
include extra.conf # glob match pattern include config.d/*.conf # http include http://example.com/fluent.conf