您好,登錄后才能下訂單哦!
1.在進(jìn)入多個broker設(shè)置之前,首先啟動ZooKeeper服務(wù)器
/usr/local/zookeeper/bin/zkServer.sh start
2.復(fù)制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.創(chuàng)建topic
(1)為此topic的復(fù)制因子值(replication-factor)指定為3個,因為我們有三個不同的broker運行
(2)如果有兩個broker,那么分配的復(fù)制因子值也得是2個
cd /usr/local/kafka bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 3 -partitions 1 --topic Three
5.檢查哪個broker正在偵聽當(dāng)前創(chuàng)建的主題
cd /usr/local/kafka bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic Three ------------ Topic: Three PartitionCount:1 ReplicationFactor:3 Configs: # 分區(qū)摘要信息,topic名,分區(qū)數(shù)量,復(fù)制因子 Topic: Three Partition: 0 Leader: 0 Replicas: 0,1,2 Isr: 0,1,2 # broker 0是領(lǐng)導(dǎo)者 ------------
6.生產(chǎn)和消費(注意ip和port)
# 生產(chǎn) /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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。