Data Collection to Hadoop (HDFS)
Last updated
Last updated
This article explains how to use Fluentd's WebHDFS Output plugin to aggregate semi-structured logs into Hadoop HDFS.
Fluentd is an advanced open-source log collector originally developed at Treasure Data, Inc. Fluentd is specifically designed to solve the big-data log collection problem. A lot of users are using Fluentd with MongoDB, and have found that it doesn't scale well for now.
HDFS (Hadoop) is a natural alternative for storing and processing a huge amount of data, but it didn't have an accessible API other than its Java library until recently. From Apache 1.0.0, CDH3u5, or CDH4 onwards, HDFS supports an HTTP interface called WebHDFS.
This article will show you how to use Fluentd to receive data from HTTP and stream it into HDFS.
The figure below shows the high-level architecture.
For simplicity, this article will describe how to set up an one-node configuration. Please install the following software on the same node.
(out_webhdfs)
HDFS (Apache 1.0.0, CDH3u5 or CDH4 onwards)
The WebHDFS Output plugin is included in the latest version of Fluentd's deb/rpm package (v1.1.10 or later). If you want to use Ruby Gems to install the plugin, please use gem install fluent-plugin-webhdfs
.
For CDH, please refer to the [downloads
page](https://ccp.cloudera.com/display/SUPPORT/CDH+Downloads)
(CDH3u5 and CDH4 onwards)
Let's start configuring Fluentd. If you used the deb/rpm package, Fluentd's config file is located at /etc/td-agent/td-agent.conf. Otherwise, it is located at /etc/fluentd/fluentd.conf.
For the input source, we will set up Fluentd to accept records from HTTP. The Fluentd configuration file should look like this:
The output destination will be WebHDFS. The output configuration should look like this:
The match section specifies the regexp used to look for matching tags. If a matching tag is found in a log, then the config inside <match>...</match>
is used (i.e. the log is routed according to the config inside).
flush_interval specifies how often the data is written to HDFS. An append operation is used to append the incoming data to the file specified by the path parameter.
Placeholders for both time and hostname can be used with the path parameter. This prevents multiple Fluentd instances from appending data to the same file, which must be avoided for append operations.
Other options specify HDFS's NameNode host and port.
Append operations are not enabled by default. Please put these configurations into your hdfs-site.xml file and restart the whole cluster.
Please confirm that the HDFS user has write access to the path specified as the WebHDFS output.
To test the configuration, just post the JSON to Fluentd (we use the curl command in this example). Sending a USR1 signal flushes Fluentd's buffer into WebHDFS.
We can then access HDFS to see the stored data.
Fluentd + WebHDFS make real-time log collection simple, robust and scalable! tagomoris has already been using this plugin to collect 20,000 msgs/sec, 1.5 TB/day without any major problems for several months now.
Fluentd Get Started
WebHDFS Output Plugin
If this article is incorrect or outdated, or omits critical information, please let us know. Fluentd is a open source project under Cloud Native Computing Foundation (CNCF). All components are available under the Apache 2 License.