騰訊雲服務器上部署Kafka,使用server.properties中公網IP配置:java
啓動時候報錯:服務器
ERROR [KafkaServer id=0] Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer) kafka.common.KafkaException: Socket server failed to bind to 配置IP:9092: Cannot assign requested address. at kafka.network.Acceptor.openServerSocket(SocketServer.scala:404) at kafka.network.Acceptor.<init>(SocketServer.scala:308) at kafka.network.SocketServer.$anonfun$createAcceptorAndProcessors$1(SocketServer.scala:126) at kafka.network.SocketServer.$anonfun$createAcceptorAndProcessors$1$adapted(SocketServer.scala:122) at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:59) at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:52) at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48) at kafka.network.SocketServer.createAcceptorAndProcessors(SocketServer.scala:122) at kafka.network.SocketServer.startup(SocketServer.scala:84) at kafka.server.KafkaServer.startup(KafkaServer.scala:247) at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:38) at kafka.Kafka$.main(Kafka.scala:92) at kafka.Kafka.main(Kafka.scala) Caused by: java.net.BindException: Cannot assign requested address at sun.nio.ch.Net.bind0(Native Method) at sun.nio.ch.Net.bind(Net.java:433) at sun.nio.ch.Net.bind(Net.java:425) at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:67) at kafka.network.Acceptor.openServerSocket(SocketServer.scala:400) ... 12 more
當把公網IP改成localhost時候,Kafka能夠啓動成功,可是沒法遠程訪問。後來參考https://blog.csdn.net/weixin_42583093/article/details/86511891和http://www.javashuo.com/article/p-rawczgqh-dq.html和https://blog.csdn.net/tengxing007/article/details/78276692瞭解到是因爲雲服務器中外網IP的端口要作內網的映射,通常是被佔用了的,因此配置改成:spa
Spring中配置:.net