1豹储、開啟zookeeper淘这、Kafka、kafka-manager服務(wù)(nohup …… &表示后臺執(zhí)行)
nohup bin/zkServer.sh start conf/zoo.cfg &
nohup bin/kafka-server-start.sh config/server.properties &
nohup ./kafka-manager-Dconfig.file=../conf/application.conf &
2. 創(chuàng)建topic(任意IP或localhost均可)
bin/kafka-topics.sh --create --zookeeper 192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181 --replication-factor 2 --partitions 3 --topic test
bin/kafka-topics.sh --create --zookeeper 192.168.43.209:2181 --replication-factor 2 --partitions 1 --topic test2
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 1 --topic test3
3. 查看topic列表(任意IP或localhost均可)
bin/kafka-topics.sh --list --zookeeper 192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181
bin/kafka-topics.sh --list --zookeeper 192.168.43.209:2181
bin/kafka-topics.sh --list --zookeeper localhost:2181
4. 查看topic詳情(任意IP或localhost均可)
bin/kafka-topics.sh --describe --zookeeper 192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181 --topic test1
bin/kafka-topics.sh --describe --zookeeper 192.168.43.209:2181 --topic test1
bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic test1
5. 發(fā)布者發(fā)布消息(任意IP均可钠怯,localhost不行)
bin/kafka-console-producer.sh --broker-list 192.168.43.209:9092,192.168.43.210:9092,192.168.43.211:9092 --topic test1
bin/kafka-console-producer.sh --broker-list 192.168.209:9092 --topic test1
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test1(不行)
6. 消費(fèi)者消費(fèi)消息(任意IP或localhost均可)
bin/kafka-console-consumer.sh --zookeeper 192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181 --topic test1 --from-beginning
bin/kafka-console-consumer.sh --zookeeper 192.168.43.209:2181 --topic test1 --from-beginning
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test1 --from-beginning
7. 刪除topic(delete.topic.enable=true)
bin/kafka-topics.sh --delete --zookeeper 192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181 --topic test
8. Kafka集群管理(網(wǎng)頁)
firefox命令打開瀏覽器曙聂,輸入如下網(wǎng)址:
192.168.43.209:9000
加權(quán)限控制之后:
9. 添加生產(chǎn)者權(quán)限
bin/kafka-acls.sh --add --authorizer-properties zookeeper.connect=192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181 --allow-principal User:sce --producer --topic=test
10. 添加消費(fèi)者權(quán)限
bin/kafka-acls.sh --add --authorizer-properties zookeeper.connect=192.168.43.209:2181,192.168.43.210:2181,192.168.43.211:2181? --allow-principal User:sce --consumer --group sce --topic=test15
11. 查看topic權(quán)限
bin/kafka-acls.sh --authorizer-properties zookeeper.connect=192.168.43.209:2181 --list --topic test2
12. 刪除權(quán)限
bin/kafka-acls.sh --authorizer-properties zookeeper.connect=192.168.43.209:2181 --operation Write --operation Read --operation Describe --allow-principal User:admin --allow-host * --remove --topic test2
13. 發(fā)布消息
bin/kafka-console-producer.sh --broker-list 192.168.43.209:9092,192.168.43.210:9092,192.168.43.211:9092 --producer-property security.protocol=SASL_PLAINTEXT --producer-property sasl.mechanism=PLAIN --topic test15
14. 訂閱消息
bin/kafka-console-consumer.sh --bootstrap-server 192.168.43.209:9092,192.168.43.210:9092,192.168.43.211:9092 --consumer-property security.protocol=SASL_PLAINTEXT --consumer-property sasl.mechanism=PLAIN --topic test3