文件内容如下:
#define agent
agent.sources = r2
agent.channels = c2
agent.sinks = k2
# defined source
agent.sources.r2.type = exec
agent.sources.r2.command = tail -f /home/bxp/Documents/doc/flume/test.log
agent.sources.r2.shell = /bin/bash -c
# defined channel
agent.channels.c2.type = memory
#设置channel的容量
agent.channels.c2.capacity = 1000
#设置sink每次从channel中拉取的event的数量
agent.channels.c2.transactionCapacity = 100
# defined sinks
agent.sinks.k2.type = hdfs
agent.sinks.k2.hdfs.path = hdfs://hadoop-series.bxp.com:8020/user/bxp/flume/test-log
agent.sinks.k2.hdfs.fileType = DataStream
agent.sinks.k2.hdfs.writeFormat = Text
agent.sinks.k2.hdfs.batchSize = 10
#bind the sources and sink to the channel
agent.sources.r2.channels = c2
agent.sinks.k2.channel = c2
执行命令:
bin/flume-ng agent --conf conf/ --name agent --conf-file conf/agent-commad.conf -Dflume.root.logger=DEBUG,console
中途遇到hdfs 8020端口无法访问,最后发现我的hadoop的core.site.xml配置文件中hdfs文件系统配置的端口是9000,修改为8020,或者直接使用9000即可:
配置hadoop的core.site.xml配置文件:
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop-series.bxp.com:8020</value>
</property>
有时候我们需要再hdfs创建的目录和时间有关联(每天的日志放再以时间为目录的文件夹下),此时进行如下设置:
(1)配置hdfs文件目录如下:
agent.sinks.k2.hdfs.path = hdfs://hadoop-series.bxp.com:8020/user/bxp/flume/%Y%m%d
(2)设置useLocalTimeStamp值为true
agent.sinks.k2.hdfs.useLocalTimeStamp = true
需要注意的是,这里的时间获取的本地(flume客户端)的时间。