使用flume读取数据,sink到kafka中及hdfs中

案例一:使用flume读取数据,sink到kafka中

users.sources = usersSource
users.channels = usersChannel
users.sinks = usersSink

users.sources.usersSource.type = spooldir
users.sources.usersSource.spoolDir = /data/flumeFile/users
users.sources.usersSource.deserializer = LINE
users.sources.usersSource.deserializer.maxLineLength = 3000
users.sources.usersSource.includePattern = users_[0-9]{4}-[0-9]{2}-[0-9]{2}.csv
# 过滤第一行的脏数据
# 定义一个过滤器,名字叫 head_filter
users.sources.usersSource.interceptors = head_filter
# 使用正则过滤器 regex_filter
users.sources.usersSource.interceptors.head_filter.type = regex_filter
# 以user_id开头的数据过滤掉
users.sources.usersSource.interceptors.head_filter.regex = ^user_id*
# 开启过滤数据
users.sources.usersSource.interceptors.head_filter.excludeEvents = true

users.channels.usersChannel.type = file
users.channels.usersChannel.checkpointDor = /data/flumeFile/checkpoint/users
users.channels.usersChannel.dataDir = /data/flumeFile/data/users

#sink类型为 org.apache.flume.sink.kafka.KafkaSink 读到kafka中
users.sinks.usersSink.type = org.apache.flume.sink.kafka.KafkaSink
# 批处理大小
users.sinks.usersSink.batchSize = 640
# broker的地址
users.sinks.usersSink.brokerList = 192.168.108.181:9092
# topic的名字
users.sinks.usersSink.topic = users

users.sources.usersSource.channels = usersChannel
users.sinks.usersSink.channel = usersChannel

案例二:使用flume读取数据,sink到hdfs中和kafka中,分两个channel传输

train.sources = trainSource
# 创建两个channel
train.channels = kafkaChannel hdfsChannel
# 创建两个sink
train.sinks = kafkaSink hdfsSink

train.sources.trainSource.type = spooldir
train.sources.trainSource.spoolDir = /data/flumeFile/train
train.sources.trainSource.deserializer = LINE
train.sources.trainSource.deserializer.maxLineLength = 3000
train.sources.trainSource.includePattern = train_[0-9]{4}-[0-9]{2}-[0-9]{2}.csv
train.sources.trainSource.interceptors = head_filter
train.sources.trainSource.interceptors.head_filter.type = regex_filter
train.sources.trainSource.interceptors.head_filter.regex = ^user*
train.sources.trainSource.interceptors.head_filter.excludeEvents = true

train.channels.kafkaChannel.type = file
train.channels.kafkaChannel.checkpointDir = /data/flumeFile/checkpoint/train
train.channels.kafkaChannel.dataDirs = /data/flumeFile/data/train

# 使用memory内存当作channel
train.channels.hdfsChannel.type = memory
train.channels.hdfsChannel.capacity  = 64000
train.channels.hdfsChannel.transactionCapacity = 16000

train.sinks.kafkaSink.type = org.apache.flume.sink.kafka.KafkaSink
train.sinks.kafkaSink.batchSize = 640
train.sinks.kafkaSink.brokerList = hadoop1:9092
train.sinks.kafkaSink.topic = train

train.sinks.hdfsSink.type = hdfs
train.sinks.hdfsSink.hdfs.fileType = DataStream
train.sinks.hdfsSink.hdfs.filePrefix = train
train.sinks.hdfsSink.hdfs.fileSuffix = .csv
train.sinks.hdfsSink.hdfs.path = hdfs://hadoop1:9000/user/events/train/%Y-%m-%d
# 必须开启useLocalTimeStamp 才能使用日期当作目录
train.sinks.hdfsSink.hdfs.useLocalTimeStamp = true
train.sinks.hdfsSink.hdfs.batchSize = 6400
train.sinks.hdfsSink.hdfs.rollCount = 0
train.sinks.hdfsSink.hdfs.rollSize = 64000000
train.sinks.hdfsSink.hdfs.rollInterval = 10

train.sources.trainSource.channels =  kafkaChannel hdfsChannel
train.sinks.hdfsSink.channel = hdfsChannel
train.sinks.kafkaSink.channel = kafkaChannel

好的,我可以回答这个问题。您可以按照以下步骤来使用Flume采集Kafka数据到HDFSHive中: 1. 首先,确保您已经安装了FlumeKafkaHDFSHive等必要的软件。 2. 然后,在Flume配置文件中添加Kafka作为SourceHDFS/Hive作为Sink。例如,以下是一个简单的配置文件示例: ``` agent.sources = kafka-source agent.channels = hdfs-channel agent.sinks = hdfs-sink hive-sink agent.sources.kafka-source.type = org.apache.flume.source.kafka.KafkaSource agent.sources.kafka-source.batchSize = 1000 agent.sources.kafka-source.kafka.bootstrap.servers = localhost:9092 agent.sources.kafka-source.kafka.topics = my-topic agent.sources.kafka-source.kafka.consumer.group.id = my-group agent.channels.hdfs-channel.type = memory agent.channels.hdfs-channel.capacity = 10000 agent.channels.hdfs-channel.transactionCapacity = 100 agent.sinks.hdfs-sink.type = hdfs agent.sinks.hdfs-sink.hdfs.path = hdfs://localhost:9000/flume/kafka agent.sinks.hdfs-sink.hdfs.fileType = DataStream agent.sinks.hdfs-sink.hdfs.writeFormat = Text agent.sinks.hdfs-sink.channel = hdfs-channel agent.sinks.hive-sink.type = hive agent.sinks.hive-sink.hive.metastore = thrift://localhost:9083 agent.sinks.hive-sink.hive.database = my-db agent.sinks.hive-sink.hive.table = my-table agent.sinks.hive-sink.hive.partition = dt=%Y-%m-%d agent.sinks.hive-sink.channel = hdfs-channel ``` 在上面的配置文件中,我们使用Kafka作为Source,将数据写入到HDFSHive中。我们使用Memory Channel将数据缓存在内存中,然后将其写入到HDFSHive中。在Hive Sink中,我们还定义了一个分区,以便按日期对数据进行分区。 3. 最后,运行Flume代理以开始从Kafka读取数据并将其写入到HDFSHive中。您可以使用以下命令来启动Flume代理: ``` $ bin/flume-ng agent -n agent -c conf -f conf/flume-kafka-hdfs-hive.conf ``` 这样,Flume代理就会开始从Kafka读取数据,并将其写入到HDFSHive中。 希望这些信息能够帮助您采集Kafka数据到HDFSHive中。如果您有任何其他问题,请随时问我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值