错误:
Connection to node -1 (/你的ip:9092) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
WARN [Producer clientId=console-producer] Connection to node -1 (/你的ip:你的暴露端口) could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
分析:
kafka客户端连接错误, 连接不到kafka服务
解决方案:
方案一:(使用默认端口9092)
- 9092端口加到安全组
- 将ip改为外网ip
- 重启kafka
方案二:(修改默认端口)
- 添加一个对外端口,如50092
- 在config/server.properties文件中,修改外网映射
listeners=PLAINTEXT://:9092 //修改前 listeners=PLAINTEXT://:50092 //修改后
- 重启kafka
- 使用
${你的公网ip:50092}
即可