辅助系统-flume

解压到apps文件夹下

tar -zxvf apps/apache-flume-1.6.0-bin.tar.gz -C apps/

进入conf文件夹

[hadoop@Linux1 ~]$ cd apps/apache-flume-1.6.0-bin/conf/

增加配置文件

[hadoop@Linux1 conf]$ vi netcat-logger.conf
 

# example.conf: A single-node Flume configuration

# Name the components on this agent
#给那三个组件取个名字
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
#类型, 从网络端口接收数据,在本机启动, 所以localhost, type=spoolDir采集目录源,目录里有就采
a1.sources.r1.type = netcat
a1.sources.r1.bind = localhost
a1.sources.r1.port = 44444

# Describe the sink
a1.sinks.k1.type = logger

# Use a channel which buffers events in memory
#下沉的时候是一批一批的, 下沉的时候是一个个eventChannel参数解释:
#capacity:默认该通道中最大的可以存储的event数量
#trasactionCapacity:每次最大可以从source中拿到或者送到sink中的event数量
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

启动命令:
#告诉flum启动一个agent,指定配置参数, --name:agent的名字,

[hadoop@Linux1 ~]$ cd apps/apache-flume-1.6.0-bin/
[hadoop@Linux1 ~]$ bin/flume-ng agent --conf conf --conf-file conf/netcat-logger.conf --name a1 -Dflume.root.logger=INFO,console

在另一个窗口传入数据:
$ telnet localhost 44444
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
Hello world! <ENTER>
OK

telnet的安装

扫描二维码关注公众号,回复: 3792012 查看本文章
yum list telnet*               列出telnet相关的安装包
yum install telnet-server      安装telnet服务
yum install telnet.*           安装telnet客户端
 日志采集

[hadoop@Linux1 conf]$ vi tail-hdfs.conf 

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /home/hadoop/log/test.log
a1.sources.r1.channels = c1

# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.channel = c1
a1.sinks.k1.hdfs.path = /flume/events/%y-%m-%d/%H%M/
a1.sinks.k1.hdfs.filePrefix = events-
a1.sinks.k1.hdfs.round = true
a1.sinks.k1.hdfs.roundValue = 10
a1.sinks.k1.hdfs.roundUnit = minute
a1.sinks.k1.hdfs.rollInterval = 3
a1.sinks.k1.hdfs.rollSize = 20
a1.sinks.k1.hdfs.rollCount = 5
a1.sinks.k1.hdfs.batchSize = 1
a1.sinks.k1.hdfs.useLocalTimeStamp = true
#生成的文件类型,默认是Sequencefile,可用DataStream,则为普通文本
a1.sinks.k1.hdfs.fileType = DataStream



# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

检查是否有日志目录

touch /home/hadoop/log/test.log

mkdir /home/hadoop/log/

模拟日志

[hadoop@Linux1 ~]$ while true; do echo 12321312321321 >> /home/hadoop/log/test.log; sleep 0.5; done

用tail命令获取数据,下沉到hdfs
启动命令:

[hadoop@Linux1 ~]$ cd apps/apache-flume-1.6.0-bin/
bin/flume-ng agent -c conf -f conf/tail-hdfs.conf -n a1

猜你喜欢

转载自blog.csdn.net/weixin_38702350/article/details/83418107