目前发现报错的原因有三个,主机localhost出错,端口出错,防火墙没关
1.显示的是连接localhost/172.0.0.1出错。
WARN [Consumer clientId=consumer-1, groupId=console-consumer-94437] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
将localhost换成自己主机的ip地址。
2.端口出错,例如:localhost/172.16.194.28:2181,将端口2181改为9092。
WARN [Consumer clientId=consumer-1, groupId=console-consumer-17082] Connection to node -1 (server08/172.16.194.28:2181) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
原因:
老版本使用的(consumer)消费数据命令:
kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
在新版本中--zookeeper已经被--bootstrap-server代替,端口也由之前的zookeeper通信端口2181,改为了kafka通信端口9092.
3.防火墙没关
查看防火墙状态
firewall-cmd --state
关闭防火墙
systemctl stop firewalld.service
启动消费(consumer)进程
kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning