现有服务器3台组集群,均在内网,端口都是9092
A:10.100.234.201
B: 10.100.234.202
C: 10.100.234.203
A服务器kafka的配置
listeners=PLAINTEXT://10.100.234.201:9092
advertised.listeners=PLAINTEXT://localdomain01:9092
A服务器hosts文件添加
10.100.234.201 localdomain01
10.100.234.202 localdomain02
10.100.234.203 localdomain03
B,C两台服务器配置类似
整个集群通过端口映射到外网
10.100.234.201 : 9092 -> 1.2.3.4 : 9092
10.100.234.202 : 9092 -> 1.2.3.4 : 9093
10.100.234.203 : 9092 -> 1.2.3.4 : 9094
以上外网IP端口均能telnet通
尝试:
一台阿里云主机作为生产者访问这个集群,阿里云服务器hosts文件添加 【1.2.3.4 localdomain01 localdomain02 localdomain03】
执行
./kafka-topics.sh --list --zookeeper localdomain01:2181 可以得到结果,列出了所有topic
执行
./kafka-consoleconsole-producer.sh --broker-list localdomain01list localdomain01:9092 --topic remoteTopic
[2018-01-09 10:48:44,925] WARN Got error produce response with correlation id 14 on topic-partition remoteTopic-0, retrying (2
attempts left). Error: NOT_LEADER_FOR_PARTITION (org.apache.kafka.clients.producer.internals.Sender)
[2018-01-09 10:48:45,069] WARN Got error produce response with correlation id 16 on topic-partition remoteTopic-0, retrying (1
attempts left). Error: NOT_LEADER_FOR_PARTITION (org.apache.kafka.clients.producer.internals.Sender)
[2018-01-09 10:48:45,213] WARN Got error produce response with correlation id 18 on topic-partition remoteTopic-0, retrying (0
attempts left). Error: NOT_LEADER_FOR_PARTITION (org.apache.kafka.clients.producer.internals.Sender)
[2018-01-09 10:48:45,358] ERROR Error when sending message to topic remoteTopic with key: null, value: 3 bytes with error: (org
.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.NotLeaderForPartitionException: This server is not the leader for that topic-partition.
请教大家这样配置有什么问题,需要怎样配置?