注意:这不是教程,是笔记。
规划:
机房公网防火墙配置NAT转发到内网kafka端口
安全:
NAT转发后的端口修改,kafka端口修改,两方端口相同
指定云服务器IP访问NAT端口
配置:
kafka配置:
advertised.listeners=PLAINTEXT://kfk1:9098
listeners=PLAINTEXT://:9092
公网防火墙规则配置为:NAT映射端口为9098,指定云服务器能访问端口,云服务器访问"NAT-IP:9098"转发到"kafka-IP:9098"
总结:
发现advertised.listeners和listeners配置的端口必须一样,
原来配置advertised.listeners=PLAINTEXT://kfk1:9098和listeners=PLAINTEXT://:9092,出现不能发现集群错误↓
tail -f logs/server.log
WARN [Controller id=2, targetBrokerId=2] Connection to node 1 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
WARN [Controller id=2, targetBrokerId=2] Connection to node 2 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
WARN [Controller id=2, targetBrokerId=2] Connection to node 2 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)
原因:查询kafka注册到zookeeper的信息,发现是9098,但是advertised.listeners并不用于集群连接
修改配置为同一个端口
advertised.listeners=PLAINTEXT://kfk1:9098
listeners=PLAINTEXT://:9098