这里演示在单机fulume环境下,kafka作为source ,chanel , sink时三种情况

下面的测试都是基于下面的基本的配置文件进行修改的

a1.sources = r1
a1.sinks = k1
a1.channels = c1
# For each one of the sources, the type is defined
#agent.sources.seqGenSrc.type = seq
a1.sources.r1.type = netcat
a1.sources.r1.bind=mini1
a1.sources.r1.port= # The channel can be defined as follows.
#agent.sources.seqGenSrc.channels = memoryChannel
a1.channels.c1.type=memory
a1.channels.c1.capacity=
a1.channels.c1.transactionCapacity = # Each sink's type must be defined
#agent.sinks.loggerSink.type = logger
a1.sinks.k1.type = logger
#Specify the channel the sink should use
#agent.sinks.loggerSink.channel = memoryChannel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1
# Each channel's type is defined.
#agent.channels.memoryChannel.type = memory # In this case, it specifies the capacity of the memory channel
#agent.channels.memoryChannel.capacity =

kafka作为source时的配置和produce程序

a1.sources.r1.type = org.apache.flume.source.kafka.KafkaSource
a1.sources.r1.channels = c1
a1.sources.r1.batchSize =
a1.sources.r1.batchDurationMillis =
a1.sources.r1.kafka.bootstrap.servers = mini1:
a1.sources.r1.kafka.topics = Operator
a1.sources.r1.kafka.consumer.group.id = custom.g.id
public static void main(String[] args) throws IOException {
Properties props = new Properties();
props.load(TestConsumer.class.getClass().getResourceAsStream("/kafkaProduce.properties"));
Producer<Integer, String> producer = new KafkaProducer<>(props);
for (int i = ; i <; i++)
producer.send(new ProducerRecord<Integer, String>("Operator", i, getRandomPhoneNum()));
producer.close();
// System.out.println(getRandomPhoneNum());
} public static String getRandomPhoneNum(){
String[] basePrefix=new String[]{"","","","","",""};
return basePrefix[new Random().nextInt(basePrefix.length)]+ RandomUtils.nextInt(,);
}

kafka作为channel时 ,topic必须是一个新的topic如果topic中存在数据那么在启动时会报错

a1.channels.c1.type = org.apache.flume.channel.kafka.KafkaChannel
a1.channels.c1.kafka.bootstrap.servers = mini1:,mini2:,mini3:
a1.channels.c1.kafka.topic = flumedat
a1.channels.c1.kafka.consumer.group.id = flume-consumer #修改source
a1.sources.r1.type = exec
a1.sources.r1.command = tail -F /home/hadoop/flume/test/logs/flume.dat
a1.sources.r1.channels = c1

按照官网的说明,当kafka作为channel时可以不需要sink或者source

The Kafka channel can be used for multiple scenarios:

  1. With Flume source and sink - it provides a reliable and highly available channel for events
  2. With Flume source and interceptor but no sink - it allows writing Flume events into a Kafka topic, for use by other apps
  3. With Flume sink, but no source - it is a low-latency, fault tolerant way to send events from Kafka to Flume sinks such as HDFS, HBase or Solr

kafka作为sink时

a1.sources.r1.type = spooldir
a1.sources.r1.channels = c1
a1.sources.r1.spoolDir = /home/hadoop/flume/test/logs/kfksink
a1.sources.r1.deletePolicy = immediate
a1.sources.r1.fileHeader = true a1.sinks.k1.type = org.apache.flume.sink.kafka.KafkaSink
a1.sinks.k1.kafka.topic = flumesink
a1.sinks.k1.kafka.bootstrap.servers = mini1:
a1.sinks.k1.kafka.flumeBatchSize =
a1.sinks.k1.kafka.producer.acks =
a1.sinks.k1.kafka.producer.linger.ms =
#压缩
a1.sinks.ki.kafka.producer.compression.type = snappy

此时打开kafka消费程序

        Properties props = new Properties();
props.load(TestConsumer.class.getClass().getResourceAsStream("/kfkConsumer.properties"));
KafkaConsumer<Integer, String> consumer = new KafkaConsumer<>(props);
consumer.subscribe(Arrays.asList("flumesink"));
while (true) {
ConsumerRecords<Integer, String> records = consumer.poll();
for (ConsumerRecord<Integer, String> record : records) {
System.out.print("Thread : " + Thread.currentThread().getName());
System.out.printf(" offset = %d, key = %s, value = %s, partition = %d %n", record.offset(), record.key(), record.value(), record.partition());
}
consumer.commitSync();
} }

配置文件来源于http://flume.apache.org/FlumeUserGuide.html

flume+kafka的更多相关文章

  1. 简单测试flume+kafka+storm的集成

    集成 Flume/kafka/storm 是为了收集日志文件而引入的方法,最终将日志转到storm中进行分析.storm的分析方法见后面文章,这里只讨论集成方法. 以下为具体步骤及测试方法: 1.分别 ...

  2. 【转】flume+kafka+zookeeper 日志收集平台的搭建

    from:https://my.oschina.net/jastme/blog/600573 flume+kafka+zookeeper 日志收集平台的搭建 收藏 jastme 发表于 10个月前 阅 ...

  3. hadoop 之 kafka 安装与 flume -> kafka 整合

    62-kafka 安装 : flume 整合 kafka 一.kafka 安装 1.下载 http://kafka.apache.org/downloads.html 2. 解压 tar -zxvf ...

  4. Flume+Kafka+Strom基于伪分布式环境的结合使用

    目录: 一.Flume.Kafka.Storm是什么,如何安装? 二.Flume.Kafka.Storm如何结合使用? 1) 原理是什么? 2) Flume和Kafka的整合  3) Kafka和St ...

  5. flume+kafka (分区实现 默认单分区)

    这篇文章主要是log4j+flume+kafka的内容 首先从从下面的地址下载flume+kafka的插件包 https://github.com/beyondj2ee/flumeng-kafka-p ...

  6. Flume - Kafka日志平台整合

    1. Flume介绍 Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于收集数据:同时,Flume提供 ...

  7. Flume+Kafka+Storm+Hbase+HDSF+Poi整合

    Flume+Kafka+Storm+Hbase+HDSF+Poi整合 需求: 针对一个网站,我们需要根据用户的行为记录日志信息,分析对我们有用的数据. 举例:这个网站www.hongten.com(当 ...

  8. Flume+Kafka+Storm整合

    Flume+Kafka+Storm整合 1. 需求: 有一个客户端Client可以产生日志信息,我们需要通过Flume获取日志信息,再把该日志信息放入到Kafka的一个Topic:flume-to-k ...

  9. 大数据处理框架之Strom:Flume+Kafka+Storm整合

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk1.8 storm-0.9 apache-flume-1.6.0 ...

  10. Flume+Kafka整合

    脚本生产数据---->flume采集数据----->kafka消费数据------->storm集群处理数据 日志文件使用log4j生成,滚动生成! 当前正在写入的文件在满足一定的数 ...

随机推荐

  1. sscanf %*s

    一次在源码里看到 %*s 的格式,从未见过百思不得其解,今天用google的code搜索,搜到一些使用范例,猜测%*s 是说这里有一些字符,长度不一定,按正则表达式的习惯,*代办任意非负整数.例如: ...

  2. java学习笔记7--抽象类与抽象方法

    接着前面的学习: java学习笔记6--类的继承.Object类 java学习笔记5--类的方法 java学习笔记4--类与对象的基本概念(2) java学习笔记3--类与对象的基本概念(1) jav ...

  3. java实现双向循环链表

    java实现循环链表:http://www.cnblogs.com/lixiaolun/p/4643911.html 在单链表中,查询下一个元素的时间是O(1).查询上一个元素的时间却是O(n). 为 ...

  4. Jquery重新学习之四[核心属性与文档处理属性]

    1:核心.each(callback),size(),length(),get([index]) 1.1 .each(callback)通过它可以遍历对象.数组的属性值并进行处理 <form i ...

  5. Python 对字符串切片

    对字符串切片字符串 'xxx'和 Unicode字符串 u'xxx'也可以看成是一种list,每个元素就是一个字符.因此,字符串也可以用切片操作,只是操作结果仍是字符串:>>> 'A ...

  6. Python 换行符

    raw字符串与多行字符串如果一个字符串包含很多需要转义的字符,对每一个字符都进行转义会很麻烦.为了避免这种情况,我们可以在字符串前面加个前缀 r ,表示这是一个 raw 字符串,里面的字符就不需要转义 ...

  7. oracle查询表数据并重新插入到本表

      oracle查询表数据并重新插入到本表 CreateTime--2018年5月17日10:30:10 Author:Marydon 1.情景描述 --查询表中数据 SELECT * FROM at ...

  8. 查看 apache、nginx、php、mysql 的编译参数

    查看nginx编译参数:/usr/local/nginx/sbin/nginx -V 查看apache编译参数:cat /usr/local/apache2/build/config.nice 查看m ...

  9. redhat6.2 系统中文环境改成英文环境

    暂时变为英文:export LANG=en_US.UTF-8 可以保证你暂时安装oracle没有问题,不出现框框.但是,要说彻底改为英语环境下的时候,用下面: export LANG=en_US就是改 ...

  10. Linux配置 xampp下的https证书(腾讯云申请)

    准备 从腾讯云后台SSL证书管理里下载证书 一.上传文件 解压出来以后有三个文件: 1_root_bundle.crt 2_www.xxxxx.com.crt 3_www.xxxxx.com.key ...