kafka环境搭建及librdkafka测试

(2016-04-05 10:18:25)

 
一、kafka环境搭建(转自http://kafka.apache.org/documentation.html#gettingStarted)

Step 1: Download the code

Download the 0.9.0.0 release and un-tar it.

tar -xzf kafka_2.11-0.9.0.0.tgz > cd kafka_2.11-0.9.0.0

Step 2: Start the server

Kafka uses ZooKeeper so you need to first start a ZooKeeper server if you don't already have one. You can use the convenience script packaged with kafka to get a quick-and-dirty single-node ZooKeeper instance.

bin/zookeeper-server-start.sh config/zookeeper.properties [2013-04-22 15:01:37,495] INFO Reading configuration from:config/zookeeper.properties (org.apache.zookeeper.server.quorum.QuorumPeerConfig) ...

Now start the Kafka server:

bin/kafka-server-start.sh config/server.properties [2013-04-22 15:01:47,028] INFO Verifying properties (kafka.utils.VerifiableProperties) [2013-04-22 15:01:47,051] INFO Property socket.send.buffer.bytes is overridden to 1048576 (kafka.utils.VerifiableProperties) ...

Step 3: Create a topic

Let's create a topic named "test" with a single partition and only one replica:

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

We can now see that topic if we run the list topic command:

bin/kafka-topics.sh --list --zookeeper localhost:2181 test

Alternatively, instead of manually creating topics you can also configure your brokers to auto-create topics when a non-existent topic is published to.

Step 4: Send some messages

Kafka comes with a command line client that will take input from a file or from standard input and send it out as messages to the Kafka cluster. By default each line will be sent as a separate message.

Run the producer and then type a few messages into the console to send to the server.

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test This is a message This is another message

Step 5: Start a consumer

Kafka also has a command line consumer that will dump out messages to standard output.

bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning This is a message This is another message

If you have each of the above commands running in a different terminal then you should now be able to type messages into the producer terminal and see them appear in the consumer terminal.

All of the command line tools have additional options; running the command with no arguments will display usage information documenting them in more detail.

二、kafka环境配置(若省略此步,其他主机上的客户端访问时会报错)

修改 conf/server.properties
 
zookeeper.connect=192.168.197.170:2181,192.168.197.171:2181,192.168.197.172:2181(换成你自己的IP)
 
broker.id分别改成
broker.id=170
broker.id=171
broker.id=172
host.name分别改成(如果不改,client访问集群时,如果没在hosts配置对应机器的 hostname,访问将会报错)
host.name=192.168.197.170(换成你自己的IP)
host.name=192.168.197.171
host.name=192.168.197.172
可根据需求修改

port: broker节点使用端口号 默认 9092
log.dir: 消息目录位置

3,执行librdkafka的例程

修改kafka的配置文件后再重启kafka服务以及消费者程序

此时在客户端主机执行

examples/rdkafka_example -P -b 128.1.0.149:9092 -t test    (128.1.0.149换成你自己的IP)

后,会在服务端的消费者执行窗口看到客户端你输入的字符

对于初学者可能参数都不知道该怎么加,可以通过三个地方学习

a,第一步中的kafka生产者测试实例,

b,第三步中的librdkafka生产者实例,

c,执行rdkafka_example时不加参数会提示帮助。

最重要的一点还是要了解kafka的框架。

kafka环境搭建及librdkafka测试的更多相关文章

  1. kafka环境搭建

    kafka环境搭建 for mac 对应qq群号:616961231 在之前的文章中, 有学习能力和兴趣爱好的同学,自己动手维护测试环境,丰衣足食是最好的办法,今天我们来讲讲kafka在mac上的安装 ...

  2. windows下golang实现Kfaka消息发送及kafka环境搭建

    kafka环境搭建: 一.安装配置java-jdk (1)kafka需要java环境,安装java-jdk,下载地址:https://www.oracle.com/technetwork/java/j ...

  3. windows kafka 环境搭建踩坑记

    版本介绍(64位): Windows 10 JDK1.8.0_171 zookeeper-3.4.8/ kafka_2.11-0.10.0.1.tgz 点击链接进行下载 1. JDK安装和环境搭建 自 ...

  4. 【入门教程】kafka环境搭建以及基础教程

    问题导读 1.Kafka独特设计在什么地方?2.Kafka如何搭建及创建topic.发送消息.消费消息?3.如何书写Kafka程序?4.数据传输的事务定义有哪三种?5.Kafka判断一个节点是否活着有 ...

  5. Kafka - 环境搭建

    一.概述 Kafka(官网地址)专为分布式高吞吐量系统而设计. Kafka往往工作得很好,作为一个更传统的消息代理的替代品. 与其他消息传递系统相比,Kafka具有更好的吞吐量,内置分区,复制和固有的 ...

  6. kafka环境搭建和使用(python API)

    引言 上一篇文章了解了kafka的重要组件zookeeper,用来保存broker.consumer等相关信息,做到平滑扩展.这篇文章就实际操作部署下kafka,用几个简单的例子加深对kafka的理解 ...

  7. windows环境下mosquitto环境搭建与mqtt测试

    https://blog.csdn.net/pgpanda/article/details/51800865 工作需求,自己在windows下搭建了一个mosquitto环境测试mqtt 话不多说,直 ...

  8. 转:(WIN)S04-CH01 PCIE XDMA开发环境搭建以及环路测试

    摘要: 这一章开始主要介绍 XILINX FPGA PICE IP XDMA IP的使用.XDMA IP使用部分教程分LINUX 篇和WINDOWS篇两个部分.通过实战,面向应用,提供给大家 XILI ...

  9. Redis环境搭建和代码测试及与GIS结合的GEO数据类型预研

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 1.1传统MySQL+ Memcached架构遇到的问题 My ...

随机推荐

  1. nhibernate 配置nvarchar(max)

     若你真的需要一个nvarchar(max)的sql存储空间时,记得增加 .CustomType("StringClob") Demo:Map(x => x.ContentM ...

  2. Leetcode 131. Palindrome Partitioning

    Given a string s, partition s such that every substring of the partition is a palindrome. Return all ...

  3. 为什么你不应该用angularjs?

    AngularJS的问题 为什么你不该用angularjs,https://medium.com/@mnemon1ck/why-you-should-not-use-angularjs-1df5ddf ...

  4. 【GCJ2008E】日程表 最小割

    Google Code Jam 2008 E 日程表 [题目描述] 热情的选手Sphinny正在看新一年的日程表,并发现已经安排了很多编 程竞赛.她将这一年的每一天都用以下三种方式之一在日程表上打标记 ...

  5. angularjs 手动加载

    利用ng-app可以完成自动加载,如果不利用ng-app.那么使用bootstrarp实现手动加载模块 <html> <head> <script src="a ...

  6. 文件属性之setuid位

    setuid位是可执行文件的一个属性,ls -l /bin/ping 或mount等可以看到权限为-rwsr-xr-x 1 root root 含有s位,所属用户为root表明该文件可以被其他用户以该 ...

  7. POJ2001 Shortest Prefixes

    Description A prefix of a string is a substring starting at the beginning of the given string. The p ...

  8. nginx添加proxy_cache模块做缓存服务器

    业务需求nginx对后端tomcat(静态文件)做缓存 减轻后端服务器的压力 # nginx-1.6.2.tar.gz  ngx_cache_purge-2.3.tar.gz #编译安装 ./conf ...

  9. 判断请求是不是ajax

    public static bool IsAjaxRequest(HttpRequest request) { if (request == null) { throw new ArgumentNul ...

  10. Android中如何像 360 一样优雅的杀死后台Service而不启动

    http://my.oschina.net/mopidick/blog/277813 目录[-] 一.已知的 kill 后台应用程序的方法 方法: kill -9 pid 二.终极方法,杀死后台ser ...