开篇回顾:安装过程中,刚开始的时候安装只选择了一个节点,然后测试,使用终端界面生产者消费者,发现生产者发送的消息,消费者都没有收到,最终添加节点为3个之后,就可以消费了。定位原因,可能由于zookpeer是集群模式。部署单个kafka,造成配置存在问题,最终不能消费成功。(个人简介)
由于是CDH安装的,启动的脚本目录为: /opt/cloudera/parcels/CDH/lib/kafka
zookpeer安装节点为:testhadoop-01,testhadoop-02,testhadoop-03,testhadoop-04,testhadoop-05
//查看创建的topic(也可以指定一个zk)
bin/kafka-topics.sh --list --zookeeper testhadoop-01:2181,testhadoop-02:2181,testhadoop-03:2181,testhadoop-04:2181,testhadoop-05:2181
//创建topic
bin/kafka-topics.sh --create --zookeeper testhadoop-01:2181,testhadoop-02:2181,testhadoop-03:2181,testhadoop-04:2181,testhadoop-05:2181 --replication-factor 3 --partitions 3 --topic test_sensen
//创建topic生产者
bin/kafka-console-producer.sh --broker-list testhadoop-02:9092,testhadoop-03:9092,testhadoop-04:9092 --topic test_sensen
创建topic消费者:
bin/kafka-console-consumer.sh --bootstrap-server testhadoop-01:9092,testhadoop-02:9092,testhadoop-03:9092,testhadoop-04:9092,testhadoop-05:9092 --topic test_sensen --from-beginning
然后在生产者的页面写内容,消费者这边就可以收到。
//删除创建的topic
bin/kafka-topics.sh --zookeeper testhadoop-01:2181,testhadoop-02:2181,testhadoop-03:2181,testhadoop-04:2181,testhadoop-05:2181 --delete --topic test_sensen