无法连接到使用 nat 和 hostonly vagrant 和 virtualbox 设置的来宾节点
Can't connect to guest node set up with nat and hostonly vagrant and virtualbox
我一直在尝试用 vagrant 替换手动 vitualbox 设置。我通常创建一个带有 2 个网络适配器的来宾节点,一个用于来宾 (ubuntu) 的 NAT 以使用主机互联网进行所有 apt-get 操作,以及一个 hostonly 供我的主机连接到来宾。我一直工作得很好。
下面是我的 vagrant 文件
Vagrant.configure("1") do |config|
config.vm.boot_mode = :gui
end
Vagrant.configure("2") do |config|
config.vm.define "web" do |web|
web.vm.box = "ubuntu/trusty64"
web.vm.network "forwarded_port", guest:22, host:2222, id:"ssh", disabled:true
web.vm.network "private_network", ip:"192.168.56.103", :adapter =>2
end
end
下面是输出:
Bringing machine 'web' up with 'virtualbox' provider...
==> web: Importing base box 'ubuntu/trusty64'...
==> web: Matching MAC address for NAT networking...
==> web: Checking if box 'ubuntu/trusty64' is up to date...
==> web: A newer version of the box 'ubuntu/trusty64' is available! You currently
==> web: have version '14.04'. The latest is version '20150430.0.0'. Run
==> web: `vagrant box update` to update.
==> web: Setting the name of the VM: ansible_web_1431424632866_64634
==> web: Clearing any previously set forwarded ports...
==> web: Clearing any previously set network interfaces...
==> web: Preparing network interfaces based on configuration...
web: Adapter 1: nat
web: Adapter 2: hostonly
==> web: Forwarding ports...
==> web: Booting VM...
==> web: Waiting for machine to boot. This may take a few minutes...
web: SSH address: 127.0.0.1:22
web: SSH username: vagrant
web: SSH auth method: private key
web: Warning: Authentication failure. Retrying...
web: Warning: Authentication failure. Retrying...
web: Warning: Authentication failure. Retrying...
现在在 vagrant 上它几乎可以工作,但我无法弄清楚一些事情:
问题1vagrant连接guest需要端口转发吗?
问题 2 当 vagrant 说:==> web: Preparing network interfaces based on configuration...
web: Adapter 1: nat
web: Adapter 2: hostonly
我认为 eth1 应该启动,但事实并非如此。 ifconfig -a
显示没有任何 IP 的接口 eth1 sudo ifup eth1
显示 Ignoring unknown interface eth1=eth1
。这里发生了什么,我该如何解决?
感谢您的帮助
没关系,我修好了。这在很大程度上取决于所使用的 vagrant 版本。这适用于任何支持转发端口自动更正功能的版本。
删除行后:
web.vm.network "forwarded_port", guest:22, host:2222, id:"ssh", disabled:true
它开始工作得很好,我可以添加其他节点。为了共享,请参阅下面的配置
Vagrant.configure("1") do |config|
config.vm.boot_mode = :gui
end
Vagrant.configure("2") do |config|
auto_config= false
config.vm.define "web" do |web|
web.vm.box = "ubuntu/trusty64"
web.vm.network "private_network", ip:"192.168.56.103", :adapter =>2
end
(1..3).each do |i|
config.vm.define "mongo-#{i}" do |mongo|
mongo.vm.box = "ubuntu/trusty64"
mongo.vm.network "private_network" , ip:"192.168.56.11#{i}", :adapter =>2
end
end
(1..2).each do |i|
config.vm.define "tomcat-#{i}" do |tomcat|
tomcat.vm.box = "ubuntu/trusty64"
tomcat.vm.network "private_network" , ip:"192.168.56.12#{i}", :adapter =>2
end
end
(1..2).each do |i|
config.vm.define "mysql-#{i}" do |mysql|
mysql.vm.box = "ubuntu/trusty64"
mysql.vm.network "private_network" , ip:"192.168.56.13#{i}", :adapter =>2
end
end
end
我一直在尝试用 vagrant 替换手动 vitualbox 设置。我通常创建一个带有 2 个网络适配器的来宾节点,一个用于来宾 (ubuntu) 的 NAT 以使用主机互联网进行所有 apt-get 操作,以及一个 hostonly 供我的主机连接到来宾。我一直工作得很好。
下面是我的 vagrant 文件
Vagrant.configure("1") do |config|
config.vm.boot_mode = :gui
end
Vagrant.configure("2") do |config|
config.vm.define "web" do |web|
web.vm.box = "ubuntu/trusty64"
web.vm.network "forwarded_port", guest:22, host:2222, id:"ssh", disabled:true
web.vm.network "private_network", ip:"192.168.56.103", :adapter =>2
end
end
下面是输出:
Bringing machine 'web' up with 'virtualbox' provider...
==> web: Importing base box 'ubuntu/trusty64'...
==> web: Matching MAC address for NAT networking...
==> web: Checking if box 'ubuntu/trusty64' is up to date...
==> web: A newer version of the box 'ubuntu/trusty64' is available! You currently
==> web: have version '14.04'. The latest is version '20150430.0.0'. Run
==> web: `vagrant box update` to update.
==> web: Setting the name of the VM: ansible_web_1431424632866_64634
==> web: Clearing any previously set forwarded ports...
==> web: Clearing any previously set network interfaces...
==> web: Preparing network interfaces based on configuration...
web: Adapter 1: nat
web: Adapter 2: hostonly
==> web: Forwarding ports...
==> web: Booting VM...
==> web: Waiting for machine to boot. This may take a few minutes...
web: SSH address: 127.0.0.1:22
web: SSH username: vagrant
web: SSH auth method: private key
web: Warning: Authentication failure. Retrying...
web: Warning: Authentication failure. Retrying...
web: Warning: Authentication failure. Retrying...
现在在 vagrant 上它几乎可以工作,但我无法弄清楚一些事情:
问题1vagrant连接guest需要端口转发吗?
问题 2 当 vagrant 说:==> web: Preparing network interfaces based on configuration...
web: Adapter 1: nat
web: Adapter 2: hostonly
我认为 eth1 应该启动,但事实并非如此。 ifconfig -a
显示没有任何 IP 的接口 eth1 sudo ifup eth1
显示 Ignoring unknown interface eth1=eth1
。这里发生了什么,我该如何解决?
感谢您的帮助
没关系,我修好了。这在很大程度上取决于所使用的 vagrant 版本。这适用于任何支持转发端口自动更正功能的版本。
删除行后:
web.vm.network "forwarded_port", guest:22, host:2222, id:"ssh", disabled:true
它开始工作得很好,我可以添加其他节点。为了共享,请参阅下面的配置
Vagrant.configure("1") do |config|
config.vm.boot_mode = :gui
end
Vagrant.configure("2") do |config|
auto_config= false
config.vm.define "web" do |web|
web.vm.box = "ubuntu/trusty64"
web.vm.network "private_network", ip:"192.168.56.103", :adapter =>2
end
(1..3).each do |i|
config.vm.define "mongo-#{i}" do |mongo|
mongo.vm.box = "ubuntu/trusty64"
mongo.vm.network "private_network" , ip:"192.168.56.11#{i}", :adapter =>2
end
end
(1..2).each do |i|
config.vm.define "tomcat-#{i}" do |tomcat|
tomcat.vm.box = "ubuntu/trusty64"
tomcat.vm.network "private_network" , ip:"192.168.56.12#{i}", :adapter =>2
end
end
(1..2).each do |i|
config.vm.define "mysql-#{i}" do |mysql|
mysql.vm.box = "ubuntu/trusty64"
mysql.vm.network "private_network" , ip:"192.168.56.13#{i}", :adapter =>2
end
end
end