前言
Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集、聚合和传输的系统。
Flume的优点:
1.可以和任意存储进程集成。
2.输入的的数据速率大于写入目的存储的速率,flume会进行缓冲,减小hdfs的压力。
3.flume中的事务基于channel,使用了两个事务模型(sender + receiver),确保消息被可靠发送。
Flume保证数据的可靠性:
Flume使用两个独立的事务分别负责从soucrce到channel,以及从channel到sink的事件传递。
一旦事务中所有的数据全部成功提交到channel,那么source才认为该数据读取完成。
同理,只有成功被sink写出去的数据,才会从channel中移除。
安装部署Flume:
1、准备好Flume安装包并上传到虚拟机:
apache-flume-1.8.0-bin.tar.gz
2、解压Flume安装包:
tar -zxvf apache-flume-1.8.0-bin.tar.gz -C /usr/local/cluster/
为了方便使用,这里对Flume进行了软连接:
ln -s apache-flume-1.8.0-bin/ flume
3、进行配置更改:
cp flume-env.sh.template flume-env.sh
在这个新命名的文件中加入:
export JAVA_HOME=/usr/local/cluster/jdk
4、创建一个Flume配置文件:
touch flume-netcat-logger.conf
加入以下配置信息:
# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
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
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
5、 启动Flume任务,监控本机44444端口:
bin/flume-ng agent --conf conf/ --name a1 --conf-file job/flume-netcat-logger.conf -Dflume.root.logger=INFO,console
6、用netcat向本机的44444端口发送内容:
nc localhost 44444
案例:
在netcat输入数据源:
Flume监听44444端口: