March 08, 2014
vagrant 是一个基于业界成熟的虚拟化技术打造可配置,可重新生成和可移植的工作环境的工具,一个配置文件完成所有状态定义。
sudo apt-get install vagrant
注意 最新的版本要到其官网下载
vagrant box add name url
其中,name 为 box 的名字,url 为 box 的路径可远程可本地
vagrant init
生成默认的 Vagrantfile
详细的配置参考官方文档
Vagrant.configure("2") do |config|
config.vm.box = "base" #定义此虚拟机是从哪个box生成
config.vm.provision :shell, :path => "bootstrap.sh" #通过shell配置
config.vm.network :forwarded_port, host: 8080, guest: 80 #端口映射
config.vm.network "private_network", ip: "192.168.110.100" #私有网络配置
#awesome configuration goes here...
end
Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: "echo Hello"
config.vm.define "web" do |web|
web.vm.box = "apache"
#awesome configuration goes here...
end
config.vm.define "db" do |db|
db.vm.box = "mysql"
#awesome configuration goes here...
end
end
我是 xdays, 记录着我技术的成长,生活的点滴和感悟,能对你有所帮助那更好。