您好,登錄后才能下訂單哦!
1.在進入多個broker設置之前,首先啟動ZooKeeper服務器
/usr/local/zookeeper/bin/zkServer.sh start
2.復制kafka的server.properties文件
cd /usr/local/kafka/config/ cp -a server.properties server1.properties cp -a server.properties server2.properties vim server.properties ---------------------- # The id of the broker. This must be set to a unique integer for each broker. broker.id=0 # The port the socket server listens on listeners=PLAINTEXT://:9092 port=9092 # A comma seperated list of directories under which to store log files log.dirs=/tmp/kafka-logs vim server1.properties ---------------------- # The id of the broker. This must be set to a unique integer for each broker. broker.id=1 # The port the socket server listens on listeners=PLAINTEXT://:9093 port=9093 # A comma seperated list of directories under which to store log files log.dirs=/tmp/kafka-logs-1 vim server2.properties ---------------------- # The id of the broker. This must be set to a unique integer for each broker. broker.id=2 # The port the socket server listens on listeners=PLAINTEXT://:9094 port=9094 # A comma seperated list of directories under which to store log files log.dirs=/tmp/kafka-logs-2
3.啟動3個broker
# Broker1 cd /usr/local/kafka bin/kafka-server-start.sh config/server.properties & # Broker2 cd /usr/local/kafka bin/kafka-server-start.sh config/server1.properties & # Broker3 cd /usr/local/kafka bin/kafka-server-start.sh config/server2.properties & # jps 8274 Jps 8079 Kafka 8145 Kafka 8210 Kafka 2004 QuorumPeerMain
4.創建topic
(1)為此topic的復制因子值(replication-factor)指定為3個,因為我們有三個不同的broker運行
(2)如果有兩個broker,那么分配的復制因子值也得是2個
cd /usr/local/kafka bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 -partitions 1 --topic Three
5.檢查哪個broker正在偵聽當前創建的主題
cd /usr/local/kafka bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic Three ------------ Topic: Three PartitionCount:1 ReplicationFactor:3 Configs: # 分區摘要信息,topic名,分區數量,復制因子 Topic: Three Partition: 0 Leader: 0 Replicas: 0,1,2 Isr: 0,1,2 # broker 0是領導者 ------------
6.生產和消費(注意ip和port)
# 生產 /usr/local/kafka/bin/kafka-console-producer.sh --broker-list 10.1.44.188:9092 --topic Three /usr/local/kafka/bin/kafka-console-producer.sh --broker-list 10.1.44.188:9093 --topic Three /usr/local/kafka/bin/kafka-console-producer.sh --broker-list 10.1.44.188:9094 --topic Three # 消費 /usr/local/kafka/bin/kafka-console-consumer.sh --zookeeper 10.1.44.188:2181 --topic Three --from-beginning jps 2290 ConsoleConsumer 1974 Kafka 1946 QuorumPeerMain 2042 Kafka 2107 Kafka 2460 Jps 2364 ConsoleProducer 2414 ConsoleProducer 2239 ConsoleProducer
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。