Vagrant基础简要记录

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

 

 

时间: 2024-09-25 13:56:47

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

【探索PowerShell 】【六】脚本基础简要

在后续的教程中,我将主要介绍PowerShell的脚本是如何编写的.这一节,先做一个概览 和大体的介绍,今天是假日,就先不写太多,明天开始逐条讲解. PowerShell脚本基础知识概览: 常量.变量.数组.哈希 条件.逻辑 循环控制 模块化 WMI对象(各种设备) ADSI对象(活动目录) 常量.变量.数组.哈希 各种字符串操作 使用常量和变量 各种运算符和表达式 创建.修改.合并数组或哈希表 条件.逻辑 判断各种条件 "if"."switch"语句 使用运算符进

探索PowerShell(六) 脚本基础简要_PowerShell

PowerShell脚本基础知识概览: 常量.变量.数组.哈希 条件.逻辑 循环控制 模块化 WMI对象(各种设备) ADSI对象(活动目录) 常量.变量.数组.哈希 各种字符串操作 使用常量和变量 各种运算符和表达式 创建.修改.合并数组或哈希表 条件.逻辑 判断各种条件 "if"."switch"语句 使用运算符进行判断 循环控制 "while"."do while"."do until"."

简要记录一下压缩表在buffer pool中的相关结构体:

//////////////////////////////////////////////////////////// struct buf_pool_struct{ mutex_t     zip_mutex;   //用于保护压缩page(buf_page_t) mutex_t     zip_free_mutex; mutex_t     zip_hash_mutex;   //保护zip_hash hash_table_t*   zip_hash;  //hash table of b

JS基础--问题记录

1. {}var a={};{}是一个空的对象,是 new Object();的简写. 2.判断元素是存在 //jQuery 对象中元素的个数.当前匹配的元素个数. size 将返回相同的值. if ($("#resultDiv").length > 0) { $("#resultDiv").remove(); } 3.jquery里面如何跳出each循环 return false 跳出循环,return true 进入下一个循环 例: $("#Se

记录 IIS 6.0 中的工作者处理序回收事件

依预设,IIS 不会记录工作者处理序回收事件.不过,您可以启用指定的工作者处理序回收事件记录.不同于其他 IIS 活动是在您指定的位置及档桉进行记录,工作者处理序回收事件会写入系统事件日志. 记录工作者处理序回收事件有助于疑难排解 IIS.例如,当疑难排解执行新伺服器支援功能 REPORT_UNHEALTHY 的 ISAPI 延伸时,您可以指定 IIS 记录每个 ISAPI 自我报告为状态不良的例项事件. 下表描述您可记录的工作者处理序回收事件.如要记录事件,请将对应的 Metabase 属性设

vagrant学习笔记 - Vagrantfile

<vagrant学习笔记 - 入门>中的hello vagrant配置文件,只是最基本的配置,它使用缺省的box配置初始化了一个虚拟机.有时候,我希望对vm做更详尽的配置,比如配置一次创建一组vm,搭建一个mfs的测试环境,他需要一台服务器做mfsmaster,两台服务器做mfs chunk server,一台服务器做metalogger,还有一台服务器做mfs client进行测试. 下面是一组服务测试mfs的vagrant file范例: # -*- mode: ruby -*- # vi

Java版网络爬虫基础(转)

网络爬虫不仅仅可以爬取网站的网页,图片,甚至可以实现抢票功能,网上抢购,机票查询等.这几天看了点基础,记录下来.      网页的关系可以看做是一张很大的图,图的遍历可以分为深度优先和广度优先.网络爬虫采取的广度优先,概括的说来如下:      2个数组,一个记录已访问的网页(Al),一个记录未访问的网页(Un).假设网页A为爬取的起始点,分析A中的所有的超链接B,C,D,将B,C,D加入到Un,分析B中的所有的超链接E,F,将E,F加入到Un末尾,将B从Un除去并加入到AL.依次分析Un中的超

基础-windows系统下,搜索某个文件的问题

问题描述 windows系统下,搜索某个文件的问题 windows系统下,打开某个文件夹,搜索里面的某个文件的问题例如:文件名为"基础问题记录.pdf"搜索关键字为"记录"时,找出了这个文件,但是搜索"问题记录"时,文件反而搜索不到求大神指点,这是什么问题. 解决方案 试过,好使.能搜到.. 解决方案二: 看看你的文件名是不是繁体的,或者包含没有察觉的小的符号. 解决方案三: 不会呀,你确定搜索"问题记录"的前后没有空格?可能

数据仓库与企业应用集成(一)

数据 主要内容 一.  从系统和整体的角度来考虑数据仓库的开发二.  CIF的概念和内容三.CIF 的案例-SAP BW四.数据仓库与企业应用集成五.小结 References 摘要 本文的主要内容在于介绍企业信息工厂并探讨在建立数据仓库和企业应用时应考虑的系统性和整体性. 因此本文主要针数据仓库的最新发展,结合SAP BW的实际案例,本文讲述企业信息工厂(CIF)的构想.概念和内容,同时也阐述了在设计企业应用时应考采用的思维方式,我们将以一个新的角度来看待数据.   一.  从系统和整体的角度