Vagrant官网:https://www.vagrantup.com/
一、安装
- 进入官网,点击Download 进入下载页,选择Windows 平台进行下载
- 点击运行安装包进行安装即可
二、添加中科大Centos7镜像box
- 进入项目文件夹的命令行环境,输入
vagrant init centos7 https://mirrors.ustc.edu.cn/centos-cloud/centos/7/vagrant/x86_64/images/CentOS-7.box - 此时在项目文件夹内会创建一个Vagrantfile 配置文件,提供一个模板
# -*- mode: ruby -*- # vi: set ft=ruby : Vagrant.configure("2") do |config| config.vm.box = "centos7" config.vm.box_url = "https://mirrors.ustc.edu.cn/centos-cloud/centos/7/vagrant/x86_64/images/CentOS-7.box" config.vm.provider "virtualbox" do |vb| vb.memory = "2048" end (2..4).each do |i| config.vm.define "hadoop10#{i}" do |node| node.vm.network "private_network", ip: "192.168.56.10#{i}" node.vm.hostname = "hadoop10#{i}" end end end - 在项目文件夹内运行
vagrant up命令就会根据此配置文件创建虚拟机。
三、自定义Box以及Vagrantfile 配置文件
- 首先需要在VirtualBox 中创建一个虚拟机,可以直接使用默认的Vagrantfile 创建
- 进入创建的虚拟机中,自定义设置以及安装的软件,然后准备打包
- 进入到VirtualBox 安装目录,运行以下命令获取虚拟机的名字
./VBoxManage.exe list vms - Vagrant 打包命令为
vagrant package --help Usage: vagrant package [options] [name|id] Options: --base NAME Name of a VM in VirtualBox to package as a base box (VirtualBox Only) --output NAME Name of the file to output --include FILE,FILE.. Comma separated additional files to package with the box --info FILE Path to a custom info.json file containing additional box information --vagrantfile FILE Vagrantfile to package with the box --[no-]color Enable or disable color output --machine-readable Enable machine readable output -v, --version Display Vagrant version --debug Enable debug output --timestamp Enable timestamps on log output --debug-timestamp Enable debug output with timestamps --no-tty Enable non-interactive output -h, --help Print this help