Apache Kafka学习 (二) - 多代理(broker)集群

1. 配置server.properties

> cp config/server.properties config/server-1.properties
> cp config/server.properties config/server-2.properties

 

2. 编辑server.properties

config/server-1.properties:

------------------------------------------------

broker.id=1
listeners=PLAINTEXT://:9093
log.dir=/tmp/kafka-logs-1

------------------------------------------------

 

config/server-2.properties:

------------------------------------------------

broker.id=2
listeners=PLAINTEXT://:9094
log.dir=/tmp/kafka-logs-2

------------------------------------------------

 

3. 我们如果已经启动了zookeeper和一个9092的单节点,那么只要再启动那两个新节点就好了

(We already have Zookeeper and our single node started, so we just need to start the two new nodes)

> bin/kafka-server-start.sh config/server-1.properties &
...
> bin/kafka-server-start.sh config/server-2.properties &
...

 

4. 新建一个有3个复制的主题

> bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 --partitions 1 --topic my-replicated-topic

 

5. 查看主题

> bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic my-replicated-topic

 

6. 发布主题的消息

> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic my-replicated-topic

 

7. 测试容错机制

> ps aux | grep server-1.properties

7564 ttys002 0:15.91 /System/Library/Frameworks/JavaVM.framework/Versions/1.8/Home/bin/java...
> kill -9 7564

 

8. 消费主题的消息

> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --from-beginning --topic my-replicated-topic

 

posted @ 2017-03-22 13:33  Master HaKu  阅读(1541)  评论(0编辑  收藏  举报