I have a multi-machine Vagrant setup. Using NFS and private_network
I can get everything to work that I need (Drupal, PHP, etc) EXCEPT allowing someone down the hall to visit a web app running on my VM. I understand that private_network
makes it impossible to connect to the VMs from the outside world.
Is there a way to create both a private AND public network so that all VMS EXCEPT the load balancer are private and the load balancer is accessible via the host's ip?
hosts = {
"wloadlocal" => "192.168.33.10",
"wweblocal1" => "192.168.33.11",
"wweblocal2" => "192.168.33.12",
"wwhlocal" => "192.168.33.13",
}
Vagrant.configure("2") do |config|
hosts.each do |name, ip|
config.vm.define name do |machine|
machine.vm.box = "precise32"
machine.vm.box_url = "http://files.vagrantup.com/precise32.box"
machine.vm.hostname = "%s.example.org" % name
machine.vm.network :private_network, ip: ip
machine.vm.network "public_network"
machine.vm.provider "virtualbox" do |v|
v.name = name
v.customize ["modifyvm", :id, "--memory", 200]
end
if name == "wloadlocal"
machine.vm.network "forwarded_port", guest: 80, host: 8880
end
end
#sync folders
config.vm.synced_folder "~/data", "/data", type: "nfs"
end
end
Edit #1
On Vagrant's NFS doc page it states that when using VirtualBox and NFS you must use private_network:
If you're using the VirtualBox provider, you'll also need to make sure you have a private network set up. This is due to a limitation of VirtualBox's built-in networking. With VMware, you do not need this.
I need to use NFS for performance reasons but I also would like to be able to share apps running in the VMs over a local network when needed. Is this possible?
Simplest way I could find around this was to use multiple networks as mentioned in one of the comments. So my config ends up looking like this:
config.vm.define :host01 do |host01|
postgres01.vm.network :private_network, ip: '192.168.37.2'
config.vm.network "public_network"
host01.vm.hostname = 'host01'
configure_vm(host01)
end
Then I did vagrant ssh host01
to look up the public ip which ended up being 192.168.0.102
on my network. Now I can access that ip from my host. Note there are some caveats to using the public network feature.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.