vagrant create a base box

Vagrant:创建一个 BASE BOX (粗译)

译者按:为什么要翻译

  1. 由于没有搜到简洁明快的 Vagrant basebox 中文资料,每次看英文原版容易头昏眼花,就拿出来翻译了下,原文位置在 http://docs.vagrantup.com/v2/boxes/base.html 
    实用为主,在不影响原意的情况下会作点自由发挥。 
  2. www.vagrantbox.es 上很多链接下载不下来,而且他们打包的其实也并不很好用。还是自己动手吧。

创建一个 BASE BOX

有一类特殊的box称为 "base boxes"  
这些 boxes 包含了 Vagrant 运作所需最少的开销,通常不是显现存 Vagrant 环境的重新打包。  
(所以这是 "base box" 里的 base) 

比如,Vagrant 项目提供了 Ubuntu box (比如"precise64"),是 base box。  
他们通过从 ISO 镜像安装了最小化的 Ubuntu,而不是对现有环境的重新打包。 

建立开发环境时,Base box 可以很有用得提供一个干净的起点。  
Vagrant 项目希望这个能够提供更多的操作系统,在此之前,你可以根据此页的文档创建你自己的 base box。 

高级话题:  
创建一个 Base box 会比较费时间,需要一些乏味的处理过程,不推荐新手创建。  
如果只是为了开始使用 Vagrant,我们首先推荐你去找些已经存在的 base box。 

BASE BOX 里有什么?

一个 base box 典型包括运行 Vagrant 所需最少的软件  
举个栗子,一个 Linux box 也许仅包含以下功能: 

Package manager  
SSH  
SSH 用户,这样 Vagrant 就可以连接了  
也许可以有 Chef, Puppet, 之类,但严格来讲不需要。 

为了装上这些,每个虚拟机提供方可能还需要装些其他必须的软件。  
比如制作的是 virtualBox 的 base box,还要包括 VirtualBox guest additions,就可以共享文件夹。  
但如果制作的是一个 AWS base box,这并不是必须的。 

创建 BASE BOX

实际上创建 base box 由虚拟机提供方特定的。  
这意味着取决于你使用的是 VirtualBox, VMware, AWS 或其他。  
创建 base box 的过程也不一样。因为此这个文档无法提供创建 base box 完整的指导。  
不过本页会提供创建 base box 通用的指导,并且会链接到虚拟机提供方。 

以下是虚拟机提供方:  
VirtualBox Base Boxes  http://docs.vagrantup.com/v2/virtualbox/boxes.html

磁盘空间

创建 base box 时确保用户有足够的磁盘空间来做有趣的事情,而无需为此烦恼。  
例如,在 VirtualBox 里,你应该使用较大的尺寸来创建动态调整空间占用的磁盘。  
这会导致磁盘初始化的时候实际尺寸比较小,但能够动态增长到所需最大尺寸,为使用者提供最大的灵活性。 

内存

类似磁盘空间,找到默认内存量的平衡很重要。  
对于大多数虚拟机提供方,用户可以自己修改 Vagrantfile,所以默认不需要设置太大。  
如果base box 一来就要求上 G 的内存,那会导致用户体验的降低(并略感震惊)。  
所以相反,选个类似 512MB 的值,对于用 Vagrant 玩一下并做些有意思的事情通常也足够了,并能够在需要的时候也很容易增加。 

外设(声音、USB 之类)

在 base box 里禁用任何非必须的硬件,例如声音和 USB 控制器。  
通常,这对 Vagrant 的使用并非必须,而且,再次的强调,大多数情况下可通过 Vagrantfile 很容易加进去。 

默认用户设置

Vagrant 每个地方都可以修改。不过,它也期待了几个默认设置,这样你的 base box 就可以开箱即用了。  
如果打算发布公开的 box,你就应该创建默认设置。  
如果仅仅是私用,则不需要按这些指示来,否则会有安全风险(已知的用户、密码、私钥等)。 

"VAGRANT" 用户

默认情况下,ssh 到机器的时候 Vagrant 期望有一个 "vagrant" 用户。  
Vagrant 用户尝试 SSH 的时候,以该用户默认的非安全密钥对来连接。  
虽然 Vagrant 默认基于密钥来连接,通常为 "vagrant" 用户设置一个 "vagrant" 也可以方便大家使用。  
这让用户在必要时能够手工登录。 

要配置非安全密钥对,把公钥 放在 "vagrant" 用户的 ~/.ssh/authorized_keys 里。  
注意 OpenSSH 对文件权限很挑剔。因此确保 ~/.ssh 具有 0700 的权限,并且 and the authorized keys 文件的权限是 0600。 

ROOT 密码 "VAGRANT"

Vagrant 实际上不使用预期的 root 密码。不过,有一个通用的 root 密码可以让大家使用起来更容易,而且需要时大伙儿会自己改。  
大家一般设置 base box 的 root 密码为 "vagrant",使事情简单一点。 

无密码的 SUDO

这很重要! Many aspects of Vagrant expect the default SSH user to have passwordless sudo configured. This lets Vagrant configure networks, mount synced folders, install software, and more.

To begin, some minimal installations of operating systems don't even include sudo by default. Verify that you install sudo in some way.

After installing sudo, configure it (usually using visudo) to allow passwordless sudo for the "vagrant" user. This can be done with the following line at the end of the configuration file:

vagrant ALL=(ALL) NOPASSWD: ALL  
Additionally, Vagrant doesn't use a pty or tty by default when connected via SSH. You'll need to make sure there is no line that has requiretty in it. Remove that if it exists. This allows sudo to work properly without a tty. Note that you can configure Vagrant to request a pty, which lets you keep this configuration. But Vagrant by default doesn't do this. 

SSH 的调整

当 Vagrant 机器没有联网,为了让 SSH 更快点,需要在 SSH 服务里配置 UseDNS 选项为 no。  
避免了 SSH 客户端登录时的 DNS 反向解析查找,这需要几秒时间。 

其他软件

At this point, you have all the common software you absolutely need for your base box to work with Vagrant. However, there is some additional software you can install if you wish.

While we plan on it in the future, Vagrant still doesn't install Chef or Puppet automatically when using those provisioners. Users can use a shell provisioner to do this, but if you want Chef/Puppet to just work out of the box, you'll have to install them in the base box.

Installing this is outside the scope of this page, but should be fairly straightforward.

In addition to this, feel free to install and configure any other software you want available by default for this base box.

打包 BOX

Packaging the box into a box file is provider-specific. Please refer to the provider-specific documentation for creating a base box. Some provider-specific guides are linked to towards the top of this page.

发布 BOX

如果乐意你可以发布这个 box 文件。However, if you want to support versioning, putting multiple providers at a single URL, pushing updates, analytics, and more, we recommend you add the box to Vagrant Cloud.  
在这个服务里,同时可以上传公开和私有的 box。 

测试 BOX

为了测试这个 box,假装你是 Vagrant 的新用户,导演,来,给个镜头:

$ vagrant box add my-box /path/to/the/new.box
...
$ vagrant init my-box
...
$ vagrant up
...

如果你做的 box 使用的是其他虚拟机,vagrant up 时请确保指定了 --provider 选项。  
如果 up 成功了,你的 box 也就 OK 啦。 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值