win7+vagrant2.0+vbox5.2安装
vagrant可以, 一键启动多个vm.通过写脚本方式来启动多个vm
定义ip 主机名 安装的软件.
1、Vagrant2.0不支持Windows7
Vagrant2.0版本使用了新版PowerShell中特有的命令,Windows7默认安装的PowerShell2.0不包含这些命令,需要升级PowerShell。笔者升级PowerShell到4.0版本,下载地址:Windows Management Framework 4 0。
安装操作系统对应的版本重启即可。
2、Vagrant执行vagrant up提示不支持的VirtualBox版本
Vagrant支持的VirtualBox最高版本为5.1,可通过修改provider让Vagrant支持VirtualBox 5.2
修改点如下:
a. 复制version_5.1.rb为version_5.2.rb
路径为:Vagrant/embedded/gems/gems/vagrant-2.0.0/plugins/providers/virtualbox/driver/version_5.1.rb
b. 修改version_5.2.rb中的5.1为5.2,5.0为5.1
require File.expand_path("../version_5_1", __FILE__)
module VagrantPlugins
module ProviderVirtualBox
module Driver
# Driver for VirtualBox 5.2.x
class Version_5_2 < Version_5_1
def initialize(uuid)
super
@logger = Log4r::Logger.new("vagrant::provider::virtualbox_5_2")
end
end
end
end
end
c.修改meta.rb,增加5.2相关配置
路径为:Vagrant/embedded/gems/gems/vagrant-2.0.0/plugins/providers/virtualbox/driver/meta.rb
driver_map = {
"4.0" => Version_4_0,
"4.1" => Version_4_1,
"4.2" => Version_4_2,
"4.3" => Version_4_3,
"5.0" => Version_5_0,
"5.1" => Version_5_1,
"5.2" => Version_5_2,
}
d.修改plugins.rb,增加5.2相关配置
路径为:Vagrant/embedded/gems/gems/vagrant-2.0.0/plugins/providers/virtualbox/plugin.rb
module Driver
autoload :Meta, File.expand_path("../driver/meta", __FILE__)
autoload :Version_4_0, File.expand_path("../driver/version_4_0", __FILE__)
autoload :Version_4_1, File.expand_path("../driver/version_4_1", __FILE__)
autoload :Version_4_2, File.expand_path("../driver/version_4_2", __FILE__)
autoload :Version_4_3, File.expand_path("../driver/version_4_3", __FILE__)
autoload :Version_5_0, File.expand_path("../driver/version_5_0", __FILE__)
autoload :Version_5_1, File.expand_path("../driver/version_5_1", __FILE__)
autoload :Version_5_2, File.expand_path("../driver/version_5_2", __FILE__)
end
启动一个vm
启动多个vm作为集群
$script = <<SCRIPT
echo 开始安装lrzsz
apt-get install lrzsz -y
SCRIPT
Vagrant.configure(2) do |config|
# config.vm.provision "shell", inline: $script
config.vm.define :master do |master|
master.vm.box = "ubuntu14"
master.vm.hostname="dp1"
master.vm.network "private_network", ip: "192.168.40.10"
master.vm.provider "virtualbox" do |v|
v.memory = "512"
v.name = "dp1"
end
#master.vm.provision :shell, :inline => $master_script
end
config.vm.define :slave1 do |slave1|
slave1.vm.box = "ubuntu14"
slave1.vm.hostname="dp2"
slave1.vm.network "private_network", ip: "192.168.40.20"
slave1.vm.provider "virtualbox" do |v|
v.memory = "512"
v.name = "dp2"
end
#master.vm.provision :shell, :inline => $master_script
end
config.vm.define :slave2 do |slave2|
slave2.vm.box = "ubuntu14"
slave2.vm.hostname="dp3"
slave2.vm.network "private_network", ip: "192.168.40.30"
slave2.vm.provider "virtualbox" do |v|
v.memory = "512"
v.name = "dp3"
end
#master.vm.provision :shell, :inline => $master_script
end
end
执行脚本预安装软件
vagrant up --provision
==> local: Running provisioner: shell...
local: Running: inline script
==> local: 开始安装lrzsz ...