hadoop学习之flume(4):flume的安装与使用

来源:互联网 发布:各个国家的域名 编辑:程序博客网 时间:2024/06/06 03:21

flume是一个海量日志采集,聚合,传输的系统

一,安装

首先下载解压。

然后将flume/conf下,cp -a flume-env.sh.template flume-env.sh

修改JAVA_HOME为本机的jdk安装目录即可。

二,flume使用

flume通过读取按照一定规则写好的配置文件,来启动agent,进行传输,每一行数据被封装成一个event

举例介绍配置文件的写法

1,监听一个文件夹,并将文件夹中新增内容输出到控制台(屏幕)

# vim spooldir-logger.conf

a1.sources = r1a1.sinks = k1a1.channels = c1# Describe/configure the source#监听目录,spoolDir指定目录, fileHeader要不要给文件夹前坠名a1.sources.r1.type = spooldira1.sources.r1.spoolDir = /root/data_hadoop/data_flumea1.sources.r1.fileHeader = true# Describe the sinka1.sinks.k1.type = logger# Use a channel which buffers events in memorya1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channela1.sources.r1.channels = c1a1.sinks.k1.channel = c1

保存退出。然后启动agent:

$ bin/flume-ng agent -c conf -f conf/spooldir-logger.conf -n a1 -Dflume.root.logger=INFO,console

参数 -Dflume.root.logger=INFO,console 指定结果输出到控制台。

这样一来,你在/root/data_hadoop/data_flume文件夹下添加文件,都会将信息显示在屏幕上。


2,监听一个文件夹,将其下新增文件上传到hdfs上。

vim spooldir-hdfs.conf

a1.sources = r1a1.sinks = k1a1.channels = c1# Describe/configure the source#监听目录,spoolDir指定目录, fileHeader要不要给文件夹前坠名a1.sources.r1.type = spooldira1.sources.r1.spoolDir = /root/data_hadoop/data_flumea1.sources.r1.fileHeader = true# Describe the sinka1.sinks.k1.type = hdfsa1.sinks.k1.channel = c1a1.sinks.k1.hdfs.path = /flume/events/%y-%m-%d/%H%M/a1.sinks.k1.hdfs.filePrefix = events-a1.sinks.k1.hdfs.round = truea1.sinks.k1.hdfs.roundValue = 10a1.sinks.k1.hdfs.roundUnit = minutea1.sinks.k1.hdfs.rollCount = 2a1.sinks.k1.hdfs.batchSize = 1a1.sinks.k1.hdfs.useLocalTimeStamp = truea1.sinks.k1.hdfs.fileType = DataStream# Use a channel which buffers events in memorya1.channels.c1.type = memorya1.channels.c1.capacity = 1000a1.channels.c1.transactionCapacity = 100# Bind the source and sink to the channela1.sources.r1.channels = c1a1.sinks.k1.channel = c1
保存退出,然后启动agent:

bin/flume-ng agent -c conf -f conf/spooldir-hdfs.conf -n a1

然后可以在本地文件夹下新增文件,flume就按照指定的规则上传到hdfs上。

0 0
原创粉丝点击