Vagrant是一种开源软件,它为跨众多操作系统构建可重复的开发环境提供了一种方法。Vagrant使用提供者(provider)来启动隔离的虚拟环境。默认的提供者是Virtualbox

Vagrant ( http://www.vagrantup.com/ ) is a powerful development tool, which

lets you manage and support the virtualization of your development environment.

Instead of running all your projects locally on your own computer, having to juggle

the different requirements and dependencies of each project, Vagrant lets you run

each project in its own dedicated virtual environment.

Vagrant uses Providers to integrate with the third-party virtualization software,

which provides the virtualized machines for our development environment. The

default provider is for Oracle's VirtualBox however, there are providers to work

with Amazon Web Services and VMware Fusion. The entire configuration is stored

in simple plain text files. The Vagrant configuration (Vagrantfile), Puppet, and Chef

manifests are simply written in text files in a Ruby Domain Specific Language. This

means we can easily share the configurations and projects with colleagues, using

Version Control Systems such as Git or Subversion.

Docker vs Vagrant

http://stackoverflow.com/questions/16647069/should-i-use-vagrant-or-docker-for-creating-an-isolated-environment

http://ju.outofmemory.cn/entry/52470

vagrant可以帮助用户管理/部署虚拟机的程序。docker是一个帮助用户创建/运行/管理基于lxc的linux container的程序。coreos是一个专门为运行linux container而设计的发行版。

安装和使用

https://atlas.hashicorp.com/boxes/search

https://docs.vagrantup.com/v2/providers/ VMWare和Virtualbox等各种提供者

Vagrant can be installed on Linux, Windows, and Mac OS X, and although it

uses Ruby, the package includes an embedded Ruby interpreter. The only other

requirement is a virtualization tool such as Oracle's VirtualBox. The Oracle's

VirtualBox provider is available for free, and is included built-in with Vagrant

https://www.virtualbox.org/

http://downloads.vagrantup.com

Each virtual machine starts with what Vagrant calls a base box. This is a specially

packaged version of an operating system with some specific configurations in

place. The number of configurations and packages installed on this packaged

operating system is typically minimal (containing only a few tools which allow it

to communicate with Vagrant).

初始化

Ubuntu的几个box

Ubuntu10

•  Lucid32 is available at  http://files.vagrantup.com/lucid32.box

•  Lucid64 is available at  http://files.vagrantup.com/lucid64.box

Ubuntu12

•  Precise32 is available at  http://files.vagrantup.com/precise32.box

•  Precise64 is available at  http://files.vagrantup.com/precise64.box

Ubutnu14

vagrant init ubuntu/trusty64; vagrant up --provider virtualbox

vagrant init precise64 http://files.vagrantup.com/precise64.box

Vagrantfile生成[ruby]

vagrant init base64

vagrant init

vagrant box add <name> <url> [--provider provider] [--force]

Powering up

vagrant up

Vagrant will then perform the following:

•  Copy the base box

•  Create a new virtual machine with the relevant provider (the default

being VirtualBox)

•  Forward any configured ports; by default, it will forward port 22 (SSH) on

the VM to port 2222 on the host; this will allow us to connect to the VM

•  Boot (power up) the VM

•  Configure and enable networking, so that we can communicate with the VM

•  Map shared folders between the host and the guest (by default, it will map

the folder containing the Vagrant project to  /vagrant on the guest machine)

•  Run any provisioning tools that are set up such as Puppet, Chef, or

SSH provisioning

vagrant suspend

vagrant resume

vagrant halt

vagrant destroy

vagrant ssh

和HOST机器共享

Port forwarding

Vagrantfile 文件中进行端口映射

config.vm.network :forwarded_port, guest: 80, host: 8888

Synced folders

config.vm.synced_folder "/Users/michael/assets/" "/var/www/assets"

The first parameter is the path to the folder on our machine, the second being the

mount point on the VM.

Networking

config.vm.network :private_network, ip: "192.168.1.100"

Auto-running commands

config.vm.provision :shell, :inline => "sudo apt-get update"

config.vm.provision :shell, :path => "provision.sh"  (the location of the

script specified is relative to our project root, that is, /vagrant )

Provisioning

Puppet modules

http://docs.puppetlabs.com/references/latest/type.html

http://forge.puppetlabs.com/

puppet apply --modulepath=/home/michael/provision/modules /home/michael/provision/manifests/default.pp

独立运行模式

config.vm.provision :puppet do |puppet|

puppet.manifests_path = "provision/manifests"

puppet.manifest_file = "default.pp"

puppet.module_path = "provision/modules"

end

client/server模式

config.vm.provision :puppet_server do |puppet|

puppet.puppet_server = "puppet.internal.michaelpeacock.co.uk"

puppet.puppet_node = "vm.internal.michaelpeacock.co.uk"

end

SSH

config.vm.provision :shell, :path => "provision/setup.sh"

config.vm.provision :shell, :inline => "apt-get install apache2"

vagrant provision 命令可以重新进行provisioning

multiple virtual machines

Vagrantfile的配置

# -*- mode: ruby -*-

# vi: set ft=ruby :

Vagrant.configure("2") do |config|

config.vm.define :server1 do |server1|

server1.vm.box = "precise64"

server1.vm.network :private_network, ip: "10.11.1.100"

end

config.vm.define :server2 do |server2|

server2.vm.box = "precise64"

server2.vm.network :private_network, ip: "10.11.1.101"

end

end

1. Power up the project ( vagrant up )

2. Connect to  server1 ( vagrant ssh server1 )

3. Ping  server2 from  server1 ( ping 10.11.1.101

不同的配置

# -*- mode: ruby -*-

# vi: set ft=ruby :

Vagrant.configure("2") do |config|

config.vm.define :server1 do |server1|

server1.vm.box = "precise64"

server1.vm.network :private_network, ip: "10.11.1.100"

server1.vm.provision :puppet do |puppet|

puppet.manifests_path = "provision/manifests"

puppet.manifest_file = "server1.pp"

puppet.module_path = "provision/modules"

end

end

config.vm.define :server2 do |server2|

server2.vm.box = "precise64"

server2.vm.network :private_network, ip: "10.11.1.101"

server2.vm.provision :puppet do |puppet|

puppet.manifests_path = "provision/manifests"

puppet.manifest_file = "server2.pp"

puppet.module_path = "provision/modules"

end

end

end

LAMP

|-- provision

| |-- manifests

| | -- init.pp

| -- modules

-- Vagrantfile

根下的Vagrantfile文件内容

# -*- mode: ruby -*-

# vi: set ft=ruby :

Vagrant.configure("2") do |config|

config.vm.provision :shell, :inline => "apt-get update"

config.vm.box = "precise64"

config.vm.network :forwarded_port, guest: 80, host: 8080

config.vm.provision :puppet do |puppet|

puppet.manifests_path = "provision/manifests"

puppet.module_path = "provision/modules"

puppet.manifest_file  = "default.pp"

end

end

目录provision下是Puppet使用的各模块的安装和配置文件

http://pan.baidu.com/s/1ntKFSVn#path=%252Fshare vagrant_lamp_stack.zip

建立自己的Box

1.安装VirtualBox虚拟机

a) 网络需要设置为NAT

b) 虚拟机名字:vagrant-ubuntu-raring

c) hostname : vagrant-ubuntu-raring

d) Domain:  vagrantup.com

e) Root password:  vagrant

f) Main account username:  vagrant

g) Main account password:  vagrant

h) install  openssh-server

2.Install Guest Additions

a) sudo apt-get install linux-headers-$(uname -r) build-essential

b) sudo mount /dev/cdrom /media/cdrom

c) sudo sh /media/cdrom/VBoxLinuxAdditions.run

3.Vagrant authentication

a) sudo groupadd admin

b) sudo usermod -a -G admin vagrant

4.vi sudo 修改

a) %admin ALL=(ALL) NOPASSWD: ALL

b) Defaults env_keep="SSH_AUTH_SOCK"

c) #Default requiretty

5.ssh无秘码登陆

a) wget https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub –o ~/.ssh/authorized_hosts

b) chmod 0644 ~/.ssh/authorized_keys

6.Provisioners

a) sudo apt-get install puppet

b) Chef

  1. sudo apt-get install ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert curl
  2. cd /tmp
  3. curl -O http://production.cf.rubygems.org/rubygems/rubygems-1.8.10.tgz
  4. tar zxf rubygems-1.8.10.tgz
  5. cd rubygems-1.8.10
  6. sudo ruby setup.rb --no-format-executable
  7. sudo gem install chef --no-ri --no-rdoc

7.Cleanup

a) rm –rf /tmp/*

b) sudo apt-get clean

8.Export

a) vagrant package --base vagrant-ubuntu-raring

b) website: http://docs.vagrantup.com/v2/cli/package.html

测试自己的box

$vagrant box add /../../my.box

$vagrant init my

$vagrant up

如上的过程就可建立自己的box

https://atlas.hashicorp.com/boxes/search 这里有很多开放的box

Vagrant基础简要记录的更多相关文章

  1. C#基础知识记录一

    C#基础知识记录一 static void Main(string[] args) { #region 合并运算符的使用(合并运算符??) 更多运算符请参考:https://msdn.microsof ...

  2. DataBase MongoDB基础知识记录

    MongoDB基础知识记录 一.概念: 讲mongdb就必须提一下nosql,因为mongdb是nosql的代表作: NoSQL(Not Only SQL ),意即“不仅仅是SQL” ,指的是非关系型 ...

  3. MarkDown基础语法记录

    基础语法记录,其中有一些博客园暂不支持 <!--标题--> # 一级标题 # ## 二级标题 ### 三级标题 #### 四级标题 ##### 五级标题 ###### 六级标题 一级标题 ...

  4. 【原】【BG】-一次虚拟化环境实践简要记录

    部分涉及到Linux.Nginx.tomcat.MySQL等的点滴操作记录,时间长了,就忘掉了,偶尔整理一下操作的history,就此简要备份一下: [原][BG]-一次虚拟化环境实践简要记录: ht ...

  5. MongoDB基础知识记录

    MongoDB基础知识记录 一.概念: 讲mongdb就必须提一下nosql,因为mongdb是nosql的代表作: NoSQL(Not Only SQL ),意即“不仅仅是SQL” ,指的是非关系型 ...

  6. MVC+Ext.net零基础学习记录(五)

    继MVC+Ext.net零基础学习记录(四),在后面我在既有的项目上又添加了一个子项目,还用前面提到的方法,进行主项目中引用DLL,然后子项目中生成事件中使用mkdir 进行拷贝 发现一个下午就总是报 ...

  7. MVC+Ext.net零基础学习记录(四)

    在上一篇文章[MVC+Ext.net零基础学习记录(三)]中提到了利用MVC的Area可以做到项目分离,但是实际操作起来还是有很多问题的.比如,对于物理资源的访问,会报:没有相关资源 开始的时候,我在 ...

  8. pt-align的用法简要记录

    pt-align的用法简要记录 1.pt-align 功能:将其它工具的输出按列对齐用法:pt-align [FILES]如果没有指定文件,则默认读取标准输入的内容. 2.例如: [root@dbte ...

  9. java基础复习记录

    java基础复习记录(数组.对象.异常) 数组 数组的定义 数组是相同类型数据的有序集合.如:篮球队就是一个数组,队员球服上有号码,相当于索引.通过某一个的某一个号码来确认是某一个队员.数组中索引从0 ...

随机推荐

  1. Struts框架的核心业务

    Struts的核心业务 Struts核心业务有很多,这里主要介绍了比较简单一些的: 请求数据的处理,和数据自动封装,类型自动转换 1.Struts中数据处理 1.1.方式1:直接过去servletap ...

  2. 一个无限加载瀑布流jquery实现

    实现大概是下面的效果,写了比较详细的注释 <!DOCTYPE html><html> <head> <meta charset="UTF-8&quo ...

  3. 最新Linux部署.NET,Mono and DNX

    这几天一直在折腾在Linux下的ASP.NET 5,就下在看来在其它操作系统中ASP.NET 5或.NET应用,要想在完整的MS VM(CoreCLR)上运行还不远远达不到,应用的效果. 目前只能在M ...

  4. 跟Unity3D学代码优化

    今天我们来聊聊如何跟Unity学代码优化,准确地说,是通过学习Unity的IL2CPP技术的优化策略,应用到我们的日常逻辑开发中. 做过Unity开发的同学想必对IL2CPP都很清楚,简单地说,IL2 ...

  5. 《深入理解Java虚拟机》调优案例分析与实战

    上节学习回顾 在上一节当中,主要学习了Sun JDK的一些命令行和可视化性能监控工具的具体使用,但性能分析的重点还是在解决问题的思路上面,没有好的思路,再好的工具也无补于事. 本节学习重点 在书本上本 ...

  6. 我认为JS还可以改进的点

    曾经我一度在寻找JS的替代语言,尝试过CoffeeScript/TypeScript/Dart(都是浅尝).不为什么原因,而是当你写的越多的JS,越觉得JS很多时候显得很操蛋.好在ES2015和Bab ...

  7. Entity Framework 6 Recipes 2nd Edition(11-6)译 -> 从一个”模型定义”函数里返回一个复杂类型

    11-6.从一个”模型定义”函数里返回一个复杂类型 问题 想要从一个”模型定义”函数返回一个复杂类型 解决方案 假设我们有一个病人(patient)和他们访客(visit)的模型,如 Figure 1 ...

  8. 电容与EMC-电容不同功能时对整板EMC的作用

    一般我们的pcb板的器件有很多种类,但是值得特别关注的,很多人都会说是BGA.接口.IC.晶振之类,因为这些都是layout功能模块以及设计难点.然而数量上占绝对优势的器件却是阻容器件,之前围殴阻抗时 ...

  9. 如果没有Visual Studio 2015,我们如何创建.NET Core项目 ?

    对于.NET开发人员来说,我们已经习惯了VS这个世界上最强大的IDE,所以对他们来说,项目的创建直接利用安装到VS中相应的项目模板即可.当.NET Core跨出了Windows的围栏,正式拥抱其他平台 ...

  10. angular2系列教程(四)Attribute directives

    今天我们要讲的是ng2的Attribute directives.顾名思义,就是操作dom属性的指令.这算是指令的第二课了,因为上节课的components实质也是指令. 例子