我尝试运行此代码,但它给了我一个错误。好像无法绑定到特定的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.
检查文档的这一部分以及文档中的链接: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
我使用 Hazelcast IMDG 开源版 3.12,或者简称为 hazelcast 3.12。我的配置是
hazelcast:
network:
interfaces:
enabled: true
interfaces: [127.0.0.11]
port:
auto-increment: false
join:
multicast:
enabled: false
tcp-ip:
enabled: true
interface: 127.0.0.11
并且它无法启动,并出现与OP报告的相同的错误:
Interfaces is enabled, trying to pick one address matching to one of: [127.0.0.11, 127.0.0.11]
...
Hazelcast CANNOT start on this node. No matching network interface found.
然后,我将
127.0.0.11
IP 地址添加到我的 lo0
界面,作为 OP 注释,瞧,它开始工作了。