您好,登录后才能下订单哦!
这篇文章主要讲解了“Win7怎么安装Vagrant”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Win7怎么安装Vagrant”吧!
去VB官方网站下载VirtualBox的Windows安装包。一路Next就OK了。VirtualBox的硬件加速很重要,Windows 7 默认是关闭VT-x(Intel芯片),需要去BIOS里开启。
去Vagrant官网下载Windows下的安装包,同样是一路Next,安装完毕后需要重启,正好借此机会去BIOS里查看下是否开启了虚拟化技术。
有两个路径要手动添加:
Virtualbox的运行程序路径,Vagrant脚本运行Virtualbox和VBoxManager的时候需要。
ssh.exe程序所在路径,ssh.exe在安装git的时候会一起安装,如果还没有安装git,需要下载安装git
虽然可以网络方式安装Box,但是,天朝的情况也是知道的,因此,保险起见,下载下来先。下载地址:http://www.vagrantbox.es/
下载完毕,假设把镜像存在d:\boxes下,运行命令:
vagrant box add trusty64 d:\boxes\trusty-server-cloudimg-amd64-vagrant-disk1.box
其中,trusty64是盒子在vagrant管理的盒子列表中的名字,后面跟的路径是盒子文件所在的路径。正常情况下,可以看到如下输出:
==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'trusty64' (v0) for provider: box: Unpacking necessary files from: file://d:/boxes/trusty-server-cloudi mg-amd64-vagrant-disk1.box box: Progress: 100% (Rate: 19.0M/s, Estimated time remaining: --:--:--) ==> box: Successfully added box 'trusty64' (v0) for 'virtualbox'!
工作区可以理解为项目在本机的代码,Vagrant会将这个代码挂载到启动的虚拟机的相应目录下,这就实现了,在本机编码,而代码在虚拟机里运行的方法,不再需要ftp或者别的方式去反复部署代码。假设工作区是d:\va, 在命令行下切换到这个目录,然后执行vagrant init trusty64, 其中trusty64就是在上一步创建的盒子名称,该命令就是使用trusty64盒子初始化当前目录为vagrant的工作区。命令执行成功,会输出如下信息:
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.
在当前目录下,会有一个Vagrantfile文件。
万事具备,可以运行一个实例了。使用命令 Vagrant up,正常情况下,会有如下输出:
D:\va>vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'trusty64'... ==> default: Matching MAC address for NAT networking... ==> default: Setting the name of the VM: va_default_1456111656613_62745 ==> 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 (guest) => 2222 (host) (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: Remote connection disconnect. Retrying... default: default: Vagrant insecure key detected. Vagrant will automatically replace default: this with a newly generated keypair for better security. default: default: Inserting generated public key within guest... default: Removing insecure key from the guest if it's present... default: Key inserted! Disconnecting and reconnecting using new SSH key... ==> 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 o f 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 t he 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.3.36 default: VirtualBox Version: 5.0 ==> default: Mounting shared folders... default: /vagrant => D:/va
以下几个命令,用来管理vagrant启动的虚拟机。
列出当前虚拟机状态:vagrant status
关闭当前虚拟机: vagrant halt
暂停当前虚拟机:vagrant suspend
重器,以使配置文件的更新生效: vagrant reload
按照上述步骤,应该能一次搞定,如果还是遇到了问题,请先查看博文:http://my.oschina.net/u/248080/blog/618060
安装完毕,运行起来后,总不能什么都不安装配置吧。势必需要ssh登陆。用Windows自带命令行也是可以的,执行vagrant ssh就可以了。
如果习惯用putty,那需要先把Vagrant自带的key给转化成putty需要的格式:
运行puttygen.exe,Conversions菜单>>Import key
Vagrant生成的私钥在工作区目录下的.vagrant\machines\default\virtualbox\private_key
导入这个私钥到puttygen里,点Save private key,转存成ppk格式。
启动putty.exe,在Connection>>SSH>>Auth里的选择刚刚生成的ppk文件
Host为127.0.0.1,端口是2222,点Open
ssh的用户名是vagrant
如果习惯用Secure Shell Client,通过如下步骤添加一个公钥:
启动Secure Shell Client
进入Edit>>Settings>>Global Settings>>User Authentication>>Keys
点Generate New按钮,生成一个RSA 2048加密的密钥对。
生成完毕,点export导出。
再次用puttygen导入刚刚导出的私钥文件,复制文本框里的公钥字符串,粘贴到虚拟机的.ssh/authorized_keys文件里
同样的方法,用127.0.0.1,端口2222,用户名vagrant登陆。
感谢各位的阅读,以上就是“Win7怎么安装Vagrant”的内容了,经过本文的学习后,相信大家对Win7怎么安装Vagrant这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。