在 Vagrant 中为多台环境机器创建两个磁盘 [英] Create two disks for multiple environment machines in Vagrant
问题描述
我将使用 Vagrant 创建多环境机器.这是我正在尝试配置的 VagrantFile.我想实例化通过专用网络连接它们的七台机器.每一个都应该有两个磁盘.我在 Vagrant 文档中找到了公开 createhd
命令的 VBoxManage.我不确定我应该把这个命令放在哪里.在每个机器块内还是在虚拟提供程序块配置内?
I'm going to create a multiple environments machines with Vagrant. Here is the VagrantFile I'm trying to configure. I would like to instantiate seven machines connected them across a private networks. Every of this one should have two disks. I have found in Vagrant documentation the VBoxManage that expose the createhd
command. I'm not sure where should I place this command. Inside every machine block or inside virtual provider block config?
Vagrant.configure(2) do |config|
config.vm.provision "shell", inline: "echo OpenStack"
config.vm.box = "ubuntu/trusty64"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048", "--cpus", "1"]
end
config.vm.define "machine1" do |machine1|
machine1.vm.hostname = "machine1"
machine1.vm.provider "virtualbox" do |vb|
vb.customize ["createhd", "--filename", "machine1_disk0", "--size", "4096"]
vb.customize ["createhd", "--filename", "machine1_disk1", "--size", "4096"]
vb.customize ["storagectl", :id, "--name", "SATA Controller", "--add", "sata"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "1", "--type", "hdd", "--medium", "machine1_disk0.vdi"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "2", "--type", "hdd", "--medium", "machine1_disk1.vdi"]
end
machine1.vm.network "private_network", ip: "192.168.10.10"
machine1.vm.network "private_network", ip: "192.168.10.15"
end
config.vm.define "machine2" do |machine2|
machine2.vm.hostname = "machine2"
machine2.vm.provider "virtualbox" do |vb|
vb.customize ["createhd", "--filename", "machine2_disk0", "--size", "4096"]
vb.customize ["createhd", "--filename", "machine2_disk1", "--size", "4096"]
vb.customize ["storagectl", :id, "--name", "SATA Controller", "--add", "sata"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "1", "--type", "hdd", "--medium", "machine2_disk0.vdi"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "2", "--type", "hdd", "--medium", "machine2_disk1.vdi"]
end
machine2.vm.network "private_network", ip: "192.168.10.20"
machine2.vm.network "private_network", ip: "192.168.10.25"
end
config.vm.define "machine3" do |machine3|
machine3.vm.hostname = "machine3"
machine3.vm.provider "virtualbox" do |vb|
vb.customize ["createhd", "--filename", "machine3_disk0", "--size", "4096"]
vb.customize ["createhd", "--filename", "machine3_disk1", "--size", "4096"]
vb.customize ["storagectl", :id, "--name", "SATA Controller", "--add", "sata"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "1", "--type", "hdd", "--medium", "machine3_disk0.vdi"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "2", "--type", "hdd", "--medium", "machine3_disk1.vdi"]
end
machine3.vm.network "private_network", ip: "192.168.10.30"
end
config.vm.define "machine4" do |machine4|
machine4.vm.hostname = "machine4"
machine4.vm.provider "virtualbox" do |vb|
vb.customize ["createhd", "--filename", "machine4_disk0", "--size", "4096"]
vb.customize ["createhd", "--filename", "machine4_disk1", "--size", "4096"]
vb.customize ["storagectl", :id, "--name", "SATA Controller", "--add", "sata"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "1", "--type", "hdd", "--medium", "machine4_disk0.vdi"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "2", "--type", "hdd", "--medium", "machine4_disk1.vdi"]
end
machine4.vm.network "private_network", ip: "192.168.10.40"
end
config.vm.define "machine5" do |machine5|
machine5.vm.hostname = "machine5"
machine5.vm.provider "virtualbox" do |vb|
vb.customize ["createhd", "--filename", "machine5_disk0", "--size", "4096"]
vb.customize ["createhd", "--filename", "machine5_disk1", "--size", "4096"]
vb.customize ["storagectl", :id, "--name", "SATA Controller", "--add", "sata"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "1", "--type", "hdd", "--medium", "machine5_disk0.vdi"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "2", "--type", "hdd", "--medium", "machine5_disk1.vdi"]
end
machine5.vm.network "private_network", ip: "192.168.10.50"
end
config.vm.define "machine6" do |machine6|
machine6.vm.hostname = "machine6"
machine6.vm.provider "virtualbox" do |vb|
vb.customize ["createhd", "--filename", "machine6_disk0", "--size", "4096"]
vb.customize ["createhd", "--filename", "machine6_disk1", "--size", "4096"]
vb.customize ["storagectl", :id, "--name", "SATA Controller", "--add", "sata"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "1", "--type", "hdd", "--medium", "machine6_disk0.vdi"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "2", "--type", "hdd", "--medium", "machine6_disk1.vdi"]
end
machine6.vm.network "private_network", ip: "192.168.10.60"
end
config.vm.define "machine7" do |machine7|
machine7.vm.hostname = "machine7"
machine7.vm.provider "virtualbox" do |vb|
vb.customize ["createhd", "--filename", "machine7_disk0", "--size", "4096"]
vb.customize ["createhd", "--filename", "machine7_disk1", "--size", "4096"]
vb.customize ["storagectl", :id, "--name", "SATA Controller", "--add", "sata"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "1", "--type", "hdd", "--medium", "machine7_disk0.vdi"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "2", "--type", "hdd", "--medium", "machine7_disk1.vdi"]
end
machine7.vm.network "private_network", ip: "192.168.10.70"
end
结束
推荐答案
首先,必须将所有自定义项(例如 createhd
)添加到提供程序中.如果您将其添加到配置提供程序
First of all customizations, like createhd
, must be added to provider.
If you add it to config provider
config.vm.provider "virtualbox" do |vb|
config.vm.customize ['createhd', '--filename', file_to_disk, '--size', some_size]
config.vm.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', file_to_disk]
end
会被全局定义,这些参数会被所有机器使用.(不确定) 结果只会创建一个磁盘,并在定义的机器之间共享.
It will be defined globally, and these parameters will be used by all machines. (Not sure) In result only one disk will be created, and will be shared among defined machines.
我认为您应该在每台机器中定义提供程序.例如
I think you should define provider in each machine. E.g
config.vm.define "machine4" do |machine4|
machine4.vm.network "private_network", ip: "192.168.10.40"
machine4.vm.provider :virtualbox do |vb|
vb.customize ["createhd", "--filename", "m4_disk0", "--size", "2048"]
vb.customize ["storageattach", :id, "--storagectl", "SATA Controller", "--port", "1", "--type", "hdd", "--medium", "m4_disk0.vdi"]
end
end
请将此Vagrantfile 作为参考.
这篇关于在 Vagrant 中为多台环境机器创建两个磁盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!