kafka的启动与测试

kafka 相关的知识
进入 /usr/local/kafka 目录下
查看端口
vim zookeeper.properties
#文件中dataDir=/tmp/zookeeper代表zookeeper数据存储路径,clientPort=2182代表zookeeper的端口号为:2182,消费者需要监听的端口
vim server.properties
#倒数第三行 ‘zookeeper.connect=localhost:2182’ 代表连接zookeeper, port是端口9091

启动zookeeper命令
nohup /usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties &
启动server命令
nohup /usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties &

创建topic
bin/kafktopics.sh --create --zookeeper localhost:2182 --replication-factor 1 --partitions 1 --topic test
查看topic
bin/kafka-topics.sh --list --zookeeper localhost:2182
创建生产者(在A窗口)(可能由于kafka版本不同,命令参数可能不同,可以使用bin/kafka-console-producer.sh --topic test 看下)
bin/kafka-console-producer.sh --broker-list 192.168.90.123:9093 --topic test
然后就可输入测试的内容了,回车发送
创建消费者(在B窗口)(可能由于kafka版本不同,命令参数可能不同,可以使用bin/kafka-console-consumer.sh --topic test 看下)
bin/kafka-console-consumer.sh --zookeeper localhost:2182 --topic test --from-beginning
启动完就可以接受生产者发过来的内容了
删除topic
bin/kafka-topics.sh --delete --zookeeper localhost:2182 --topic test

猜你喜欢

转载自www.cnblogs.com/patrick-king/p/12188907.html