[历史归档]本文原发布于 cstriker1407.info 个人博客内容为历史存档仅供参考。发布时间2016-08-25 标题vagrant简单使用笔记分类操作系统 标签vagrantvagrant简单使用笔记软件依赖使用vagrant启动虚拟机实例闲话不扯了简单的记个流水账。PS本文比较水很多内容都省略了。软件依赖vagrant依赖现有的虚拟机软件【VMware,virtualbox】等这里考虑到速度解决战斗直接使用免费的virtualbox。下载地址vagrant【 https://www.vagrantup.com/downloads.html 】virtualbox【 https://www.virtualbox.org/wiki/Downloads 】使用vagrantvagrant默认提供了很多box参考网址【 https://atlas.hashicorp.com/ubuntu/boxes/ 】这里简单起见我们使用ubuntu/xenial64。进入命令行输入如下命令此时会在当前目录中建立一个vagrantfile文件这个文件是用来描述当前虚拟机实例的。注意这里的名字如果这个名字能够和本地box列表中的对应上那么就使用box中的虚拟机模板来在本地路径中实例化一个虚拟机如果这个名字在本地box列表中没有找到就回去box网站上搜索和下载。D:\codevagrant init ubuntu/xenial64 A Vagrantfile has been placed in this directory. You are now ready to vagrant up your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on vagrantup.com for more information on using Vagrant.可以看到作者本地没有这个虚拟机模板因此尝试启动这个虚拟机实例时会自动下载。启动虚拟机实例D:\codevagrant up ubuntu/xenial64 Bringing machine ubuntu/xenial64 up with virtualbox provider... default: Box ubuntu/xenial64 could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: 0 default: Loading metadata for box ubuntu/xenial64 default: URL: https://atlas.hashicorp.com/ubuntu/xenial64 default: Adding box ubuntu/xenial64 (v20161119.0.0) for provider: virtualbox default: Downloading: https://atlas.hashicorp.com/ubuntu/boxes/xenial64/versions/20161119.0.0/providers/virtualbox.box default: Progress: 0% (Rate: 3793/s, Estimated time remaining: 25:52:35)如果网速非常慢可以使用下载工具手动下载链接下载后使用命令手动将虚拟机模板加入本地vagrant的box列表。D:\codevagrant box add -name ubuntu/xenial64 xenial-server-cloudimg-amd64-vagrant.box再次启动D:\codevagrant up Bringing machine default up with virtualbox provider... default: Importing base box ubuntu/xenial64... default: Matching MAC address for NAT networking... default: Setting the name of the VM: code_default_1479832133505_47764 default: Clearing any previously set network interfaces... default: Preparing network interfaces based on configuration... default: Adapter 1: nat default: Forwarding ports... default: 22 (guest) 2222 (host) (adapter 1) default: Running pre-boot VM customizations... 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: ubuntu default: SSH auth method: password 。。。。。。 。。。。。。 default: default: Guest Additions Version: 5.0.24 default: VirtualBox Version: 5.1 default: Mounting shared folders... default: /vagrant D:/code注意这里已经表明了SSH用户名和共享目录那密码呢D:\codevagrant ssh ssh executable not found in any directories in the %PATH% variable. Is an SSH client installed? Try installing Cygwin, MinGW or Git, all of which contain an SSH client. Or use your favorite SSH client with the following authentication information shown below: Host: 127.0.0.1 Port: 2222 Username: ubuntu Private key: D:/code/.vagrant/machines/default/virtualbox/private_key可以看到登录密码被放到了private_key文件中。如果想变更用户名和密码可以修改对应虚拟机实例的vagrantfile。vagrant的虚拟机是基于vagrantfile文件的关于这个文件如何使用可以参考【 https://www.vagrantup.com/docs/vagrantfile/ 】这里作者只使用最简单的功能就不在展开了。