vagrant 使用

来源:互联网 发布:中国交通地图软件 编辑:程序博客网 时间:2024/05/20 18:50

vagrant 文档: http://docs.vagrantup.com/v2/getting-started/index.html

1. 初识vagrant

从 http://www.vagrantup.com/downloads 站点下载相应版本的vagrant并安装

安装完成后会自动将"vagrant"加入系统的环境变量中.

vagrant支持的provider有virtualbox, vmware, aws等,下面的介绍中使用的是virtualbox, virtualbox免费并支持多个平台.

1.1 用vagrant来启动一台32位的ubuntu虚拟机

➜  ~  vagrant init hashicorp/precise32A `Vagrantfile` has been placed in this directory. You are nowready to `vagrant up` your first virtual environment! Please readthe comments in the Vagrantfile as well as documentation on`vagrantup.com` for more information on using Vagrant.
➜  ~  vagrant upBringing machine 'default' up with 'virtualbox' provider...==> default: Box 'hashicorp/precise32' could not be found. Attempting to find and install...    default: Box Provider: virtualbox    default: Box Version: >= 0==> default: Loading metadata for box 'hashicorp/precise32'    default: URL: https://vagrantcloud.com/hashicorp/precise32==> default: Adding box 'hashicorp/precise32' (v1.0.0) for provider: virtualbox    default: Downloading: https://vagrantcloud.com/hashicorp/precise32/version/1/provider/virtualbox.box==> default: Successfully added box 'hashicorp/precise32' (v1.0.0) for 'virtualbox'!==> default: Importing base box 'hashicorp/precise32'...==> default: Matching MAC address for NAT networking...==> default: Checking if box 'hashicorp/precise32' is up to date...==> default: Setting the name of the VM: hsgroot_default_1399458969510_99441==> default: Clearing any previously set network interfaces...==> default: Preparing network interfaces based on configuration...    default: Adapter 1: nat==> default: Forwarding ports...    default: 22 => 2222 (adapter 1)==> default: Booting VM...==> default: Waiting for machine to boot. This may take a few minutes...    default: SSH address: 127.0.0.1:2222    default: SSH username: vagrant    default: SSH auth method: private key    default: Warning: Connection timeout. Retrying...    default: Warning: Connection timeout. Retrying...    default: Warning: Connection timeout. Retrying...    default: Warning: Remote connection disconnect. Retrying...==> default: Machine booted and ready!==> default: Checking for guest additions in VM...    default: The guest additions on this VM do not match the installed version of    default: VirtualBox! In most cases this is fine, but in rare cases it can    default: prevent things such as shared folders from working properly. If you see    default: shared folder errors, please make sure the guest additions within the    default: virtual machine match the version of VirtualBox you have installed on    default: your host and reload your VM.    default:     default: Guest Additions Version: 4.2.0    default: VirtualBox Version: 4.3==> default: Mounting shared folders...    default: /vagrant => /home/hsgroot

1.2 登陆刚创建的虚拟机

vagrant ssh

1.3 注销虚拟机

vagrant destroy

2 建立vagrant 工程

创建vagrant工程时会自动生成配置文件Vagrantfile. Vagrantfile是描述Project中的虚拟机的类型以及如何配置这些虚拟机.

0 0
原创粉丝点击