Flume采集日志存储到HDFS

1 日志服务器上配置Flume,采集本地日志文件,发送到172.19.115.96 的flume上进行聚合,如日志服务器有多组,则在多台服务器上配置相同的配置

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

# Describe/configure the source
a1.sources.r1.type = TAILDIR
a1.sources.r1.filegroups = f1
#通配符是以.*为标识的,如采集所有文件则.*,此处表示采集.log结尾的文件
a1.sources.r1.filegroups.f1 = /home/admin/app/api/logs/.*log
#a1.sources.r1.filegroups = f1 f2
#a1.sources.r1.filegroups.f2 = /usr/local/flume-1.9.0/files2/.*
a1.sources.r1.positionFile = /usr/local/flume-1.9.0/taildir_position.json

# Describe the sink
a1.sinks.k1.type = avro
a1.sinks.k1.hostname = 172.19.115.96
a1.sinks.k1.port = 4141


# 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

2 hdfs服务器上配置flume

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

# Describe/configure the source
a1.sources.r1.type = avro
a1.sources.r1.bind = 172.19.115.96
a1.sources.r1.port = 4141


# Describe the sink
a1.sinks.k1.type = hdfs
a1.sinks.k1.hdfs.path = hdfs://localhost:8020/test/%Y%m%d
#生成的hdfs文件名的前缀
a1.sinks.k1.hdfs.filePrefix = logs-
#指定滚动时间,默认是30秒,设置为0表示禁用该策略 生产调整为3600
a1.sinks.k1.hdfs.rollInterval = 10
#指定滚动大小,设置为0表示禁用该策略,128M
a1.sinks.k1.hdfs.rollSize = 134217700
#指定滚动条数
a1.sinks.k1.hdfs.rollCount = 0
#a1.sinks.k1.hdfs.batchSize = 100
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

3 在hdfs服务器上启动HDFS

start-dfs.sh

4 先启动hdfs服务器上的flume

 bin/flume-ng agent -c conf/ -f job/avro-flume-hdfs.conf -n a1

后台运行 

 nohup ./bin/flume-ng agent -c conf/ -f job/avro-flume-hdfs.conf -n a1 &

5 再启动日志服务器上的flume

bin/flume-ng agent -c conf/ -f job/file-flume-avro.conf -n a1

后台运行

nohup ./bin/flume-ng agent -c conf/ -f job/file-flume-avro.conf -n a1 &

  • 10
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flume 是一种用于数据采集、聚合和移动的工具,它可以将多种来源的数据收集到 HDFS(Hadoop分布式文件系统)中。通过 Flume,用户可以轻松地配置和管理数据流,确保数据的可靠性和一致性。 首先,用户需要在 Flume 的配置文件中定义数据源,例如日志文件、网络源或其他存储位置。接着,用户需要定义数据的处理流程,包括数据的过滤、转换和路由策略。然后,用户需要指定目的地为 HDFS,并设置 HDFS 的相关参数,包括数据的写入路径、文件格式和压缩方式等。 当 Flume 启动后,它会按照用户定义的规则和流程,从数据源收集数据,并将其经过处理后写入到 HDFS 中。Flume 可以确保数据的高效传输和存储,同时具有容错和重试机制,以保证数据的可靠性和完整性。 在数据采集HDFS 后,用户可以通过 Hadoop 生态系统中的其他工具和框架,如 MapReduce、Spark 等进行数据处理和分析。同时,用户也可以通过 HDFS 提供的 API 和命令行工具,对数据进行管理和检索,以满足各种业务需求和分析任务。 总之,通过 Flume 将数据采集HDFS 中,用户可以实现大规模数据的收集、存储和分析,为企业决策和业务运营提供基础支持。同时,Flume 也为数据工程师和分析师提供了一个灵活、高效的数据采集和处理工具,助力他们更好地利用数据来推动业务发展。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值