这就是我想要实现的目标
- 适配器 1 在通常的 NAT 上运行
- 使用我在虚拟盒中创建的 vboxnet0 主机专用网络添加一个附加适配器,该适配器使用 DHCP 服务器
我需要 dhcp 服务器的原因是因为在同一台主机上的 vagrant box 上运行着一个 logstash 服务器,而且我使用 vagrant 启动的所有其他 box 都应该发送到这个 logstash 实例,因此我必须logstash.agilityroots.com
在每个 box 中使用主机名,而不是依赖于每个 box 的硬编码 IP。
Virtualbox 上的 Host Only 网络和 DHCP 设置如下
Anadis-MacBook-Pro:bin anadi$ VBoxManage list -l hostonlyifs
Name: vboxnet0
GUID: 786f6276-656e-4074-8000-0a0027000000
DHCP: Disabled
IPAddress: 192.168.10.1
NetworkMask: 255.255.255.0
IPV6Address:
IPV6NetworkMaskPrefixLength: 0
HardwareAddress: 0a:00:27:00:00:00
MediumType: Ethernet
Status: Up
VBoxNetworkName: HostInterfaceNetworking-vboxnet0
Anadis-MacBook-Pro:bin anadi$ VBoxManage list -l dhcpservers
NetworkName: HostInterfaceNetworking-vboxnet0
IP: 192.168.56.100
NetworkMask: 255.255.255.0
lowerIPAddress: 192.168.56.101
upperIPAddress: 192.168.56.254
Enabled: Yes
这是流浪者的文件
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "full-stack-env" do |dev|
dev.vm.box = "devops-vm"
dev.vm.hostname = "full-stack-env.agilityroots.com"
dev.vm.synced_folder "../../shared-data/yum", "/yum"
dev.vm.synced_folder "../../puppet-manifests/files", "/etc/puppet/files"
# add additional adapter for inter machine networking
dev.vm.network "private_network", type: "dhcp"
#dev.vm.network :private_network, :type => "dhcp", :adapter => "2"
dev.vm.network :forwarded_port, guest: 22,host: 4223, id: "ssh", auto_correct: true
#setting port forward for tomcat
dev.vm.network :forwarded_port, guest: 8080, host: 8090
#setting port forward for elasticsearch
dev.vm.network :forwarded_port, guest: 9200, host: 9200
dev.vm.provider :virtualbox do |vbox|
vbox.name = "full-stack-env"
end
dev.vm.provision :puppet do |puppet|
puppet.options = "--verbose --fileserverconfig=/vagrant/fileserver.conf"
puppet.module_path = "../../puppet-manifests/modules"
puppet.manifests_path = "../../puppet-manifests/dev-env"
puppet.manifest_file = "site.pp"
end
end
end
这会引发错误
Anadis-MacBook-Pro:full-stack-env anadi$ vagrant up
Bringing machine 'full-stack-env' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:
vm:
* An IP is required for a private network.
有没有办法让 vagrant 使用启用了 DHCP 的主机专用网络?
答案1
此问题应已在 Vagrant 1.5.2 中修复(问题)。因此,您可以升级或使用符号:
dev.vm.network "private_network", type: :dhcp