为什么 VirtualBox 在仅主机适配器上创建 2 个接口?

Why does VirtualBox create 2 interfaces on host-only adapter?

我正在使用 NAT 适配器host-only 适配器 使用 VirtualBox 作为 VM 驱动程序设置 minikube。创建 VM 后,我 运行 几个 pods 其中一个是 Kafka(消息队列)。我在正确使用 Kafka 时遇到问题,因为 VM 创建了 2 个网络接口 eth0 指向 10.0.2.15eth1 指向 192.168.99.100 这是仅主机适配器的 IP设置。

我运行在 Mac 上使用它,所以我尝试使用 HyperKit,但它的工作方式似乎不同。因此,当使用 HyperKit 时,我得到一个指向 192.168.99.100 的接口 eth0,并且一切正常。

为什么VirtualBox创建2个接口,即eth0eth1

|           Host           |   |          VM           |
|--------------------------|   |-----------------------|
| vboxnet0 (192.168.99.100)|   | eth0 (10.0.2.15)      | <--- why is this created?
|           ...            |   | eth1 (192.168.99.100) |

附带说明一下,Kafka 在侦听器设置中使用 PLAINTEXT://:9092,这使得它使用 eth0 启动服务器,结果是 10.0.2.15。此 IP 稍后会通告给连接到它的任何消费者。该 IP 似乎只能在 VM 内访问,这使得无法从外部连接,例如主人。准确地说,消费者连接到 Kafka,然后 Kafka 发送通告的侦听器,即 10.0.2.15 然后它无法发送任何消息,因为它尝试连接到 10.0.2.15.

| eth0 (10.0.2.15) | <--- why is this created?

基本上,VirtualBox 需要 2 个接口,因为它使用 vboxnet0 eth0 接口通过 NAT 和 192.168.99.x 网络上的另一个接口 eth1 与外界通信,以便您的机器可以和虚拟机对话。 192.168.99.100minikube ssh 使用。你可以直接通过 运行 ssh -i private_key docker@192.168.99.100 并从 运行 minikube ssh-key

获取私钥来尝试

HyperKit doesn't need two interfaces because as you noticed it has 192.168.99.100 which minikube also uses to connect through ssh. HyperKit VMs don't necessarily need an interface to connect to the outside. For that, it generally uses a different mechanism based on VPNKit.

我的建议是使用 advertised.host.name option in your Kafka configs. Another alternative is to upstream an option in minikube,它允许您更改 VirtualBox 上以太网接口的顺序,但那样会更麻烦。

我一直在使用默认配置,因此在启动 Kafka 时我覆盖了以下属性。这工作得很好。

bin/kafka-server-start.sh config/server.properties \
     --override zookeeper.connect=zookeeper:2181 \
     --override advertised.listeners=PLAINTEXT://192.168.99.100:9092