阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Flume-ng配置

104次阅读
没有评论

共计 6148 个字符,预计需要花费 16 分钟才能阅读完成。

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.linuxidc.com/Linux/2014-01/95799.htm 和《CentOS 分布式环境安装 HBase-0.96.0》http://www.linuxidc.com/Linux/2014-01/95801.htm。

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

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

  1. export FLUME_HOME=/home/aaron/apache-flume-1.4.0-bin
  2. export FLUME_CONF_DIR=$FLUME_HOME/conf
  3. export PATH=$PATH:$FLUME_HOME/bin

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

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

  1. agent.sources = seqGenSrc
  2. agent.channels = memoryChannel
  3. agent.sinks = remoteSink
  4. # For each one of the sources, the type is defined
  5. agent.sources.seqGenSrc.type = exec
  6. agent.sources.seqGenSrc.command = tail -F /home/aaron/test
  7. # The channel can be defined as follows.
  8. agent.sources.seqGenSrc.channels = memoryChannel
  9. # Each sink’s type must be defined
  10. agent.sinks.loggerSink.type = logger
  11. #Specify the channel the sink should use
  12. agent.sinks.loggerSink.channel = memoryChannel
  13. # Each channel’s type is defined.
  14. agent.channels.memoryChannel.type = memory
  15. # Other config values specific to each type of channel(sink or source)
  16. # can be defined as well
  17. # In this case, it specifies the capacity of the memory channel
  18. agent.channels.memoryChannel.capacity = 100
  19. agent.channels.memoryChannel.keep-alive = 100
  20. agent.sinks.remoteSink.type = avro
  21. agent.sinks.remoteSink.hostname = node
  22. agent.sinks.remoteSink.port = 23004
  23. agent.sinks.remoteSink.channel = memoryChannel

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

  1. agent.sources = seqGenSrc1
  2. agent.channels = memoryChannel
  3. #agent.sinks = fileSink
  4. agent.sinks = <SPANstyle=“FONT-FAMILY: Arial, Helvetica, sans-serif”>fileSink</SPAN>
  5. # For each one of the sources, the type is defined
  6. agent.sources.seqGenSrc1.type = avro
  7. agent.sources.seqGenSrc1.bind = node
  8. agent.sources.seqGenSrc1.port = 23004
  9. # The channel can be defined as follows.
  10. agent.sources.seqGenSrc1.channels = memoryChannel
  11. # Each sink’s type must be defined
  12. agent.sinks.loggerSink.type = logger
  13. #Specify the channel the sink should use
  14. agent.sinks.loggerSink.channel = memoryChannel
  15. # Each channel’s type is defined.
  16. agent.channels.memoryChannel.type = memory
  17. # Other config values specific to each type of channel(sink or source)
  18. # can be defined as well
  19. # In this case, it specifies the capacity of the memory channel
  20. agent.channels.memoryChannel.capacity = 100
  21. agent.channels.memoryChannel.keep-alive = 100
  22. agent.sources.flieSink.type = avro
  23. agent.sources.fileSink.channel = memoryChannel
  24. agent.sources.fileSink.sink.directory = /home/aaron/
  25. agent.sources.fileSink.serializer.appendNewline = true

在 master 上面运行命令:

  1. $ bin/flume-ng agent –conf ./conf/ -f conf/flume-maste.conf -Dflume.root.logger=DEBUG,console -n agent

在 node 上运行命令:

  1. $ bin/flume-ng agent –conf ./conf/ -f conf/flume-node.conf -Dflume.root.logger=DEBUG,console -n agent

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

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

  1. agent.sinks = k2
  2. agent.sinks.k2.type = hdfs
  3. agent.sinks.k2.channel = memoryChannel
  4. agent.sinks.k2.hdfs.path = hdfs://master:8089/hbase
  5. agent.sinks.k2.hdfs.fileType = DataStream
  6. agent.sinks.k2.hdfs.writeFormat = Text

 

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

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计6148字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中