1.檢查阿里雲服務器的防火牆,及訪問策略。釋放相關端口,否則將訪問不到服務。
2.要配置vi /etc/hosts
外網ip : 主機名
比如 114.113.112.111 :kafka-test
3.配置kafka的config/server.properties
# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
port=9092
host.name=阿里雲內網地址
advertised.host.name=阿里雲外網映射地址
注意:版本不同此處的配置也不盡相同。有的版本需要的配置如下
broker.id=0
port=9092
listeners=PLAINTEXT://:9092 (這個才是真正綁定的ip,寫內網ip即可)
advertised.listeners=PLAINTEXT://your.host.name:9092 (要暴露給外部訪問的ip,寫外網ip)
至此,重啟kafka即可。
小提示:
如果在使用過的過程中遇見
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
一定要檢查listeners的配置
將kafka的config/server.properties文件中的listeners配置成下方,
listeners=PLAINTEXT://你的ip地址:9092
不要用localhost,或者127.0.0.1