下面是我的 Vagrantfile。但是,它沒有創建 1 個 RedHat VM 和 2 個 Ubuntu VM,而是「流浪」了 3 個 Ubuntu VM。
有人可以告訴我為什麼嗎?先感謝您!
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider :virtualbox do |v|
v.memory = 4000
v.linked_clone = false
end
# App server 1
config.vm.box = "geerlingguy/centos7"
config.vm.define "app1" do |app|
app.vm.hostname = "orc-app1.test"
app.vm.network :private_network, ip: "192.168.60.4"
end
# App server 2
config.vm.box = "geerlingguy/ubuntu2004"
config.vm.define "app2" do |app|
app.vm.hostname = "orc-app2.test"
app.vm.network :private_network, ip: "192.168.60.5"
end
# DB server
config.vm.box = "geerlingguy/ubuntu2004"
config.vm.define "db" do |db|
db.vm.hostname = "orc-db.test"
db.vm.network :private_network, ip: "192.168.60.6"
end
end
答案1
您在錯誤的位置配置了該框,並多次覆寫了任何實例使用的預設框。以下應該可以解決您的問題並滿足您的要求:
Vagrant.configure("2") do |config|
config.ssh.insert_key = false
# These are the defaults applied to all VMs unless overridden
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.box = "geerlingguy/ubuntu2004" # Set as a default box since reused.
config.vm.provider :virtualbox do |v|
v.memory = 4000
v.linked_clone = false
end
# Specific config for App server 1
config.vm.define "app1" do |app|
# Override box for this specific vm
app.vm.box = "geerlingguy/centos7"
app.vm.hostname = "orc-app1.test"
app.vm.network :private_network, ip: "192.168.60.4"
end
# Specific config for App server 2
config.vm.define "app2" do |app|
app.vm.hostname = "orc-app2.test"
app.vm.network :private_network, ip: "192.168.60.5"
end
# Specific config for DB server
config.vm.define "db" do |db|
db.vm.hostname = "orc-db.test"
db.vm.network :private_network, ip: "192.168.60.6"
end
end
邊註:由於您至少有兩個基於相同映像的虛擬機,因此您可能會從使用v.linked_clone = true
.這很可能會加速虛擬機器的首次建立以及隨後的銷毀/重新建立。