(1)、启动Zookeeper服务
和Single node – single broker集群的部署一样,这种模式的集群部署也是需要启用Zookeeper。请参见《Kafka分布式集群部署手册(一)》
(2)、启动Kafka broker服务
如果需要在单个node上面启动多个brokers,我们需要复制$KAFKA_HOME/config/server.properties文件。如下:
$ cp server.properties server1.properties $ cp server.properties server2.properties
并最少修改文件 server.properties、server1.properties和 server2.properties里面的以下几个属性:brokerid、port和log.dir。比如:
$ vim server.properties brokerid = 0 port = 1234 log.dir = /tmp/wyp/kafka_log $ vim server1.properties brokerid = 1 port = 1235 log.dir = /tmp/wyp/kafka_log1 $ vim server2.properties brokerid = 2 port = 1236 log.dir = /tmp/wyp/kafka_log2
不同的配置文件中其中这三个属性的值不要一样,否则会出现问题。在该结点上启动三个broker:
$ bin/kafka-server-start.sh config/server.properties $ bin/kafka-server-start.sh config/server1.properties $ bin/kafka-server-start.sh config/server2.properties
(3)、如何测试?
创建一个topic
$ bin/kafka-topics.sh --create --zookeeper master:2181,node:2181,node1:2181 \ --replication-factor 2 --partitions 2 --topic wyp Created topic "wyp".
往wyp中发送消息:
$ bin/kafka-console-producer.sh \ --broker-list localhost:1234,localhost:1235,localhost:1236 --topic wyp SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J:See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Hello Kafka My name is wyp This is Guowangjiyi blog
注意--broker-list localhost:1234,localhost:1235,localhost:1236和Single node – single broker集群的--broker-list不同。
向wyp中拉取消息:
<!--------------------------------------------------------------------- User: 过往记忆 Date: 14-6-25 Time: 15:37 bolg: 本文地址:/archives/1049 过往记忆博客,专注于hadoop、hive、spark、shark、flume的技术博客,大量的干货 过往记忆博客微信公共帐号:iteblog_hadoop ---------------------------------------------------------------------> $ bin/kafka-console-consumer.sh --zookeeper master:2181,node:2181,node1:2181 \ --topic wyp --from-beginning SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J:See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Hello Kafka My name is wyp This is Guowangjiyi blog Consumed 3 messages
Multiple node – multiple broker集群的部署和Single node – multiple broker集群很类似,只不过多个broker在不同的node上面,它的体系结构图如下:
所以关于Multiple node – multiple broker集群的部署我就不再介绍了。(完)
本博客文章除特别声明,全部都是原创!