Flume 从入门到实时日志采集实例

#flume-ng 初始配置
bin/flume-ng agent --conf conf --conf-file example.conf --name a1 -Dflume.root.logger=INFO,console
#agent 启动的进程为agent进程
#conf  指定flume-env.sh和log4j.properties的路径
#conf-file  指定agent的配置文件
#name  为agent的名称,与配置文件中的agent名称相同

#flume-ng 用zookeeper管理配置
bin/flume-ng agent --conf conf -z 10.238.18.80:2181,10.238.18.80:2181 -p /flume --name a1 -Dflume.root.logger=INFO,console
#-p  为zookeeper下flume的路径
#--name 为zookeeper下配置数据所在的节点
#-z  为zookeeper集群访问信息多台主机用逗号隔开

#开启一个arvo客户端把数据传到指定collector的arvo的source中
bin/flume-ng avro-client -H localhost -p 4141 -F /opt/cloudera/parcels/CDH/lib/zookeeper/LICENSE.txt

#使用avro的source去接受其它agent传送过来的avro格式的数据(形成agent->collector的模式)
# Describe the agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1
# Describe/configure the source
a1.sources.r1.type = avro
a1.sources.r1.channels = c1
a1.sources.r1.bind = hostname/ip  #必需为主机名或者是本机ip(不能用127.0.0.1)否则用其它主机连接传送数据过来时会出现连接拒绝的错误
a1.sources.r1.port = 41418   #绑定的端口
a1.sources.r1.ipFilter = true #是否使用拦截器
a1.sources.r1.ipFilterRules = deny:name:localhost,allow:ip:
#拦截器规则
#<’allow’ or deny>:<’ip’ or ‘name’ for computer name>:<pattern> or allow/deny:ip/name:pattern
#example: ipFilterRules=allow:ip:127.*,allow:name:localhost,deny:ip:*
# 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

# 使用 Exec Source 实时日志采集实例
# Describe the agent
a1.sources = r1
a1.channels = c1
a1.sinks = k1
# Describe the sources
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /root/test.txt
# 用tail命令读取日志中新生成日志到agent的channel中
# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = InterFinance02
a1.sinks.k1.port = 45454
# 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
# 启动实时采集日志的agent
bin/flume-ng agent --conf /opt/cloudera/parcels/CDH/lib/flume-ng/conf --conf-file execavro.conf --name a1 

# 使用Spooling Directory Source采集日志(官方建议用Spooling Directory Source 代替 Exec Source)
# Describe the agent
a1.sources = s1
a1.channels = c1
a1.sinks = k1
# Describe the sources
a1.sources.s1.type = spooldir
a1.sources.s1.spoolDir = /root/test/flume
# Spooling Directory Source 监控的目录,如果目录下面有新文件生成,就会被采集到channel中,然后文件被重命名加后缀.COMPLETED
a1.sources.s1.fileHeader = true
# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = InterFinance02
a1.sinks.k1.port = 45454
# 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








































  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flume是一个可靠、可扩展的分布式服务,用于高效地收集、聚合和移动大量的日志数据和事件。 Flume采用了基于数据流的体系结构,其主要目的是将数据从不同的数据源(例如Web服务器、数据库等)采集并将其传输到目标位置(例如Hadoop、Elasticsearch等)。在日志采集中,Flume通常被用作采集工具,它可以将日志数据收集到集中的位置,方便后续处理和分析。 Flume的体系结构由三个主要组件组成:Source、Channel和Sink。Source用于从数据源中获取数据,例如从日志文件、网络接口、系统日志等收集数据。Channel是一种缓冲机制,用于将数据从Source传输到Sink。Sink负责将数据发送到目标位置,例如将日志数据写入Hadoop HDFS或Apache Kafka等分布式消息系统中。Flume支持不同的Source和Sink,因此可以很容易地对不同类型的数据源进行采集和分发。 在使用Flume构建日志采集系统时,可以使用以下步骤: 1.选择和配置Source,例如使用TailSource从文件中收集日志数据。 2.选择和配置Channel,例如使用MemoryChannel将数据保存在内存中进行传输。 3.选择和配置Sink,例如使用HDFSSink将数据写入Hadoop HDFS中。 4.设置事件处理器,例如使用Interceptors进行数据转换和转发。 5.启动Flume Agent并监视其状态。 通过这些步骤,可以使用Flume快速构建高可用、高扩展性的日志采集系统。Flume还提供了灵活的配置选项和监视工具,可以方便地对系统进行管理和维护。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值