首页 > 编程学习 > vagrant在配置文件里面配置多个虚拟机

vagrant在配置文件里面配置多个虚拟机

发布时间:2022/8/17 9:41:18

vagrant通过配置文件Vagrantfile可以一次性配置多个虚拟机,通过定义 config.vm.define 的方式

Vagrant.configure("2") do |config|

  config.vm.define "web" do |web|
    web.vm.box = "centos7"
	web.vm.network "private_network", ip: "192.168.56.10"
    web.vm.host_name = "web"
    web.vm.synced_folder "H:/vagrant/share_data", "/vagrant_data",
      type: "rsync",
      rsync__args: ["--verbose", "--rsync-path='sudo rsync'", "--archive", "--delete", "-z"]
    web.vm.provider "virtualbox" do |v|
		 v.memory = "4096"
		 v.cpus = 1
	 end
  end
 
  config.vm.define "db" do |db|
    db.vm.box = "centos7"
	db.vm.network "private_network", ip: "192.168.56.20"
    db.vm.host_name = "db"
    db.vm.synced_folder "H:/vagrant/share_data1", "/vagrant_data",
      type: "rsync",
      rsync__args: ["--verbose", "--rsync-path='sudo rsync'", "--archive", "--delete", "-z"]
    db.vm.provider "virtualbox" do |v|
		 v.memory = "4096"
		 v.cpus = 1
	 end
  end   
end 

上面的内容就是定义了两台虚拟机,使用的是同一个虚拟机镜像文件。

 

Copyright © 2010-2022 mfbz.cn 版权所有 |关于我们| 联系方式|豫ICP备15888888号