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

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 

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

 

posted @ 2022-08-17 09:38  imok  阅读(519)  评论(0编辑  收藏  举报