在windows中使用vagrant

妙音 posted @ 2015年11月13日 21:02 in vagrant with tags vagrant;virtualbox , 1480 阅读
  • 介绍
vagrant封装linux开发环境,可以统一团队成员的开发环境。封装后,可以linux/windows/mac上运行.
  • 环境
以win8安装vagrant为例子。vagrant需要virtualbox提供虚拟化支持,因此先安装virtualbox。
  • 安装
https://www.vagrantup.com/downloads.html
  • vagrant镜像
vagrant镜像下载地址
 
http://www.vagrantbox.es/
 
以centos-7.0为例子,下载地址
 
https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.1.0/centos-7.0-x86_64.box
  • 新建目录
D:\vagrant\centos
 
下载后的centos-7.0-x86_64.box放到此目录
  • 添加box
D:\vagrant\centos>vagrant box add --name centos7 .\centos-7.0-x86_64.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos7' (v0) for provider:
    box: Unpacking necessary files from: file://D:/vagrant/centos/centos-7.0-x86
_64.box
    box: Progress: 100% (Rate: 48.1M/s, Estimated time remaining: --:--:--)
==> box: Successfully added box 'centos7' (v0) for 'virtualbox'!
  • 查看box列表
D:\vagrant\centos>vagrant box list
centos7            (virtualbox, 0)
  • 初始化工作目录
D:\vagrant\centos>vagrant init centos7
  • 启动
D:\vagrant\centos>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> 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: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => D:/vagrant/centos
==> default: Machine already provisioned. Run `vagrant provision` or use the `--
provision`
==> default: flag to force provisioning. Provisioners marked to run always will
still run.
  • 安装ssh工具
 
启动之后,登录系统需要ssh,windows没有ssh,可以安装copssh。安装后,再将ssh.exe路径配置到环境变量中。
 
https://www.itefix.net/content/copssh-free-edition
  • 登录
D:\vagrant\centos>vagrant ssh
cygwin warning:
  MS-DOS style path detected: D:/vagrant/centos/.vagrant/machines/default/virtua
lbox/private_key
  Preferred POSIX equivalent is: /cygdrive/d/vagrant/centos/.vagrant/machines/de
fault/virtualbox/private_key
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
Last login: Thu Nov  5 03:10:24 2015 from 10.0.2.2
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$ 
使用其它工具登录,初始账号是vagrant/vagrant
  • 关闭
D:\vagrant\centos>vagrant halt
==> default: Attempting graceful shutdown of VM...
  • vagrant命令
vagrant up  启动
vagrant halt 普通关闭
vagrant ssh 连接
vagrant suspend 休眠
vagrant reload  重启
vagrant destroy 删除
vagrant box add --name box_name /path/of/box/file #添加本地box
 

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter