天天看點

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

技術改變世界