Flume-ng1.5安装配置

本人亲自执行操作,希望可以帮到想学Flume的你

1)简介

Flume是一个分布式、可靠、和高可用的海量日志聚合的系统,支持在系统中定制各类数据发送方,用于收集数据;同时,Flume提供对数据进行简单处理,并写到各种数据接受方(可定制)的能力。

设计目标:

(1) 可靠性

当节点出现故障时,日志能够被传送到其他节点上而不会丢失。Flume提供了三种级别的可靠性保障,从强到弱依次分别为:end-to-end(收到数据agent首先将event写到磁盘上,当数据传送成功后,再删除;如果数据发送失败,可以重新发送。),Store on failure(当数据接收方crash时,将数据写到本地,待恢复后,继续发送),Best effort(数据发送到接收方后,不会进行确认)。

(2) 可扩展性

Flume采用了三层架构,分别为agent,collector和storage,每一层均可以水平扩展。其中,所有agent和collector由master统一管理,这使得系统容易监控和维护,且master允许有多个(使用ZooKeeper进行管理和负载均衡),这就避免了单点故障问题。

(3) 可管理性

所有agent和colletor由master统一管理,这使得系统便于维护。多master情况,Flume利用ZooKeeper和gossip,保证动态配置数据的一致性。用户可以在master上查看各个数据源或者数据流执行情况,且可以对各个数据源配置和动态加载。Flume提供了web 和shell script command两种形式对数据流进行管理。

(4) 功能可扩展性

用户可以根据需要添加自己的agent,collector或者storage。此外,Flume自带了很多组件,包括各种agent(file, syslog等),collector和storage(File,HDFS,HBase等)。


2)配置

之前配置过Hadoop和hbase,所以需要先将hadoop和hbase启动,才能将文件写入hdfs和hbase。hadoop-2.2.0和hbase-0.96.0的配置分别参考《Ubuntu和CentOS中分布式配置Hadoop-2.2.0》 http://www.21ops.com/front-tech/10782.html 和《CentOS分布式环境安装HBase-0.96.0》 http://www.21ops.com/front-tech/10788.html 。

本次配置环境为两台装有centos 的测试集群。主机名为master的机器负责收集日志,主机名为node的机器负责日志的写入,本次配置的写入方式有三种:写入普通目录,写入hdfs。


首先下载flume-ng的二进制压缩文件。地址:http://flume.apache.org/download.html。下载好后,解压文件。首先编辑/etc/profile文件,在其中添加如下几行:

export FLUME_HOME=/home/aaron/apache-flume-1.5.0-bin
export FLUME_CONF_DIR=$FLUME_HOME/conf
export PATH=$PATH:$FLUME_HOME/bin

 

添加好之后记得运行$ source /etc/profile命令使修改生效。

在master的flume文件夹的conf目录中,新建一个flume-master.conf文件,内容如下:

agent.sources = seqGenSrc
agent.channels = memoryChannel
agent.sinks = remoteSink
# For each one of the sources, the type is defined
agent.sources.seqGenSrc.type = exec
agent.sources.seqGenSrc.command = tail -n +0 -F /home/aaron/test
# The channel can be defined as follows.
agent.sources.seqGenSrc.channels = memoryChannel
# Each sink's type must be defined
agent.sinks.loggerSink.type = logger
#Specify the channel the sink should use
agent.sinks.loggerSink.channel = memoryChannel
# Each channel's type is defined.
agent.channels.memoryChannel.type = memory
# Other config values specific to each type of channel(sink or source)
# can be defined as well
# In this case, it specifies the capacity of the memory channel
agent.channels.memoryChannel.capacity = 100
agent.channels.memoryChannel.keep-alive = 100
agent.sinks.remoteSink.type = avro
agent.sinks.remoteSink.max.message.size=1000000
agent.sinks.remoteSink.hostname = node
agent.sinks.remoteSink.port = 23004
agent.sinks.remoteSink.channel = memoryChannel

 

在node机器上也将/etc/profile文件添加上面的配置。然后,在conf中新建一个flume-node.conf文件,修改如下:

agent.sources = seqGenSrc1
agent.channels = memoryChannel
#agent.sinks = fileSink
agent.sinks = fileSink
# For each one of the sources, the type is defined
agent.sources.seqGenSrc1.type = avro
agent.sources.seqGenSrc1.bind = node
agent.sources.seqGenSrc1.port = 23004
# The channel can be defined as follows.
agent.sources.seqGenSrc1.channels = memoryChannel
# Each sink's type must be defined
agent.sinks.loggerSink.type = logger
#Specify the channel the sink should use
agent.sinks.loggerSink.channel = memoryChannel
# Each channel's type is defined.
agent.channels.memoryChannel.type = memory
# Other config values specific to each type of channel(sink or source)
# can be defined as well
# In this case, it specifies the capacity of the memory channel
agent.channels.memoryChannel.capacity = 100
agent.channels.memoryChannel.keep-alive = 100
agent.sources.flieSink.type = avro
agent.sources.flieSink.max.message.size=1000000
agent.sources.fileSink.channel = memoryChannel
agent.sources.fileSink.sink.directory = /home/aaron/
agent.sources.fileSink.serializer.appendNewline = true

#命令参数说明

-c conf 指定配置目录为conf

-f conf/example.conf 指定配置文件为conf/example.conf

-n agent1 指定agent名字为agent1,需要与example.conf中的一致(这里不一致,可能会一直停在那里,请参考笔记中后面的错误全集Flume部分,那里介绍了错误的分析,原因,解决)

-Dflume.root.logger=INFO,console 指定DEBUF模式在console输出INFO信息



在master上面运行命令:

[[email protected]]# ./bin/flume-ng agent -c conf/ -f conf/flume-maste.conf -n agent -Dflume.root.logger=INFO,console

 

在node上运行命令:

[[email protected]]# ./bin/flume-ng agent -c conf/ -f conf/flume-node.conf -n agent -Dflume.root.logger=INFO,console

 

启动之后,就可以发现两者之间可以相互通信,master上面的文件就能发送到node上,修改master上的test文件,在后面追加内容时,node也可以接收到。

如果想要将内容写入hadoop,可以将node中的flume-node.conf文件做如下修改:

agent.sinks = k2
agent.sinks.k2.type = hdfs
agent.sinks.k2.channel = memoryChannel
agent.sinks.k2.hdfs.path = hdfs://master:8089/hbase
agent.sinks.k2.hdfs.fileType = DataStream
agent.sinks.k2.hdfs.writeFormat = Text

 
其中,hdfs://master:8089/hbase为hadoop的hdfs文件路径。

另外一个source可以配置多个channal和sink

producer.sources = s
producer.channels = c1 c2
producer.sinks = r1 r2
############################################
# producer config
#使用:kafka的jar、程序jar放到flume的lib下
#配置文件放到conf下
###########################################

#agent section
producer.sources = s
producer.channels = c
producer.sinks = r
# Each sources's type must be defined(Դ)
#producer.sources.s.type = seq
producer.sources.s.channels = c
producer.sources.s.type = exec
producer.sources.s.batchSize = 100
producer.sources.s.command= tail -n +0 -F /usr/local/nginx/nginxlog/access.log
#不删除来源文件
producer.sources.s.deletePolicy=never
#producer.sources.s.type = avro
#producer.sources.s.bind = 10.1.1.100(接收端绑定的机器ip)
#producer.sources.s.port = 10000

# Each sink's type must be defined
#producer.sinks.r.type = avro
#producer.sinks.r.hostname = 10.1.1.100(发送到机器ip)
#producer.sinks.r.port = 10000
producer.sinks.r.type = org.xx.clickstream.sink.kafka.KafkaSink
producer.sinks.r.metadata.broker.list =127.0.0.1:9092,127.0.0.1:9093
producer.sinks.r.zk.connect = 127.0.0.1:2181,127.0.0.1:2182
producer.sinks.r.partitioner.class=org.jd.clickstream.partition.TypePartitioner
producer.sinks.r.serializer.class=kafka.serializer.StringEncoder
producer.sinks.r.request.required.acks=1
producer.sinks.r.max.message.size=1000000
producer.sinks.r.producer.type=sync
producer.sinks.r.custom.encoding=UTF-8
producer.sources.r.batchSize = 100
producer.sinks.r.channel = c

# Each channel's type is defined.定义memory类型channel,数据缓存在内存中,访问速度快
producer.channels.c.type = memory
producer.channels.c.capacity = 100 #channel内最多缓存数据条数
producer.channels.c.transactionCapacity = 100 #每次发送数据条数
#producer.channels.c.type=file
#producer.channels.c.checkpointDir=/usr/local/yting/flume/checkpointdir/tcpdir/example_agent1_001
#producer.channels.c.dataDirs=/usr/local/yting/flume/datadirs/tddirs/example_agent1_001

执行命令:

./flume-ng agent -c /usr/local/flumeng/apache-flume-1.5.0-bin/conf/ -f /usr/local/flumeng/apache-flume-1.5.0-bin/conf/flume-single.properties -n producer -Dflume.root.logger=INFO,console

说明:

#batchSize是针对Source和Sink提出的一个概念,它用来限制source和sink对event批量处理的

#注意,这里有一个隐晦的地方,就是batchSize一定不能大于transactionCapacity

producer.sources.s.batchSize = 100

producer.sources.r.batchSize = 100

#定义memory类型channel,数据缓存在内存中,访问速度快

#transactionCapacity 事务容量,它就是putList和takeList的容量大小

# Put queue for MemoryTransaction of capacity表示channels不够使用了 要进行拆分了

a1.channels.c1.type = memory
a1.channels.c1.capacity = 100  #channel内最多缓存数据条数
a1.channels.c1.transactionCapacity = 20  #每次发送数据条数
a1.channels.c1.keep-alive=10  #连接超时时间

相关推荐