如何将hazelcast节点绑定到特定的IP地址?

时间:2019-04-15 18:51:32

标签: java scala hazelcast vert.x

我尝试运行此代码,但它给了我一个错误。看来我无法绑定到特定的IP地址;而是我需要绑定到网络接口。有什么办法解决这个问题?

import io.vertx.core.VertxOptions
import io.vertx.reactivex.core.Vertx
import io.vertx.spi.cluster.hazelcast.{ ConfigUtil, HazelcastClusterManager }

object Test extends App {
  val host = "127.0.0.2"
  def getConfig(): Config = {
    import scala.collection.JavaConverters._
    val config = ConfigUtil.loadConfig()
    config.setProperty("hazelcast.socket.bind.any", "false")
    config
      .getNetworkConfig
      .setPortAutoIncrement(false)
      .getInterfaces
      .setEnabled(true)
      .setInterfaces(List(s"127.0.0.2").asJava)
    val joinConfig = config.getNetworkConfig.getJoin

    joinConfig
      .getMulticastConfig
      .setEnabled(false)

    config
  }
  def run(): Unit = {
    val mgr = new HazelcastClusterManager(getConfig())
    val options = new VertxOptions().setClusterManager(mgr)
    options.getEventBusOptions.setHost(host)
    val vrtx = Vertx.rxClusteredVertx(options).blockingGet()
  }
  run()
}

我得到java.lang.RuntimeException: Hazelcast CANNOT start on this node. No matching network interface found.

1 个答案:

答案 0 :(得分:0)

查看文档的此部分以及文档中的链接:https://docs.hazelcast.org/docs/latest/manual/html-single/index.html#discovering-members-by-tcp

您需要的是通过将hazelcast.socket.bind.any设置为false来禁用Hazelcast绑定所有接口。然后,您可以按照此处所述使用接口:https://docs.hazelcast.org/docs/latest/manual/html-single/index.html#interfaces

寻找你感兴趣的贴纸↓↓↓
豫ICP备18024241号-1