Vagrant 是一款用来构建虚拟开发环境的工具,它底层支持VirtualBox、VMware甚至AWS做为虚拟机系统。 html
Vagrant能作什么? linux
避免重复搭建开发环境。新员工加入,不用浪费时间搭建开发环境,快速加入开发,减小时间成本的浪费; git
多个相互隔离开发环境。能够在不用box里跑不一样的语言,或者编译安装同一语言不一样版本,搭建多个相互隔离的开发环境,卸载清除时也很快捷轻松。 github
安装 和 配置? web
#提早下载好的box文件,~/box/precise64.box,咱们给这个box命名为ubuntu12.04 vagrant box add ubuntu12.04 ~/box/precise64.box #box文件也能够是远程地址 base 为默认名称 #vagrant box add base http://files.vagrantup.com/lucid64.box
#打开目录 #cd ~/vagrant/work #初始化 vagrant init #若是你添加的box名称不是base,那么须要在初始化的时候指定名称,例如 vagrant init ubuntu12.04
vagrant up
vagrant ssh
vagrant reload
vagrant package
vagrant -h
开发目录下有一个文件Vagrantfile,里面包含有大量的配置信息,主要包括三个方面的配置,虚拟机的配置、SSH配置、Vagrant的一些基础配置。
打开看一下,注释很全,因此不用担忧不会配置了,下面主要备忘几个经常使用配置: ubuntu
config.vm.box = "ubuntu12.04"
config.vm.hostname = "for_work"
#config.vm.network "private_network", ip: "192.168.33.10" config.vm.network "public_network"
config.vm.synced_folder "../data", "/vagrant_data"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provider "virtualbox" do |vb| #Display the VirtualBox GUI when booting the machine vb.gui = true #Customize the amount of memory on the VM: vb.memory = "1024" vb.cpus = 2 vb.name = "my_vm" end
使用 Apache/Nginx 时会出现诸如图片修改后但页面刷新仍然是旧文件的状况,是因为静态文件缓存形成的。须要对虚拟机里的 Apache/Nginx 配置文件进行修改: segmentfault
# Apache 配置添加: EnableSendfile off # Nginx 配置添加: sendfile off;
How to make Vagrant performance not suck ?
Vagrant NFS configration 缓存
具体配置操做,参考原文 和 vagrant文档。 网络
nfs权限问题 ssh
config.vm.synced_folder '.', '/vagrant', :nfs =>{ :linux__nfs_options => ["no_root_squash"], :map_uid => 0, :map_gid => 0 }
域名解析慢的问题
Vagrant: Slow internet connection in guest
config.vm.provider :virtualbox do |vb| #vb.gui = true vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] end
报错:
Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available. Please verify that the guest additions are properly installed in the guest and can work properly. The command attempted was:
尝试:
sudo apt-get install virtualbox-guest-dkms
参考: