Vagrant 下载太慢解决方法(本地安装box文件)
使用 vagrant up 安装 centos 7 时下载速度特别慢。
解决方法 :
将镜像下载到本地(镜像下载地址http://www.vagrantbox.es/)
使用 vagrant box add {title} {url} 命令的方式添加本地的镜像
然后使用 vagrant init {title}
最后再 vagrant up 即可完成虚拟机的安装
其中 title 代表你给这个镜像取的名称,url 代表镜像本地的存储路径
如:
vagrant box add centos7 F:\backups\Centos7\centos-7.0-x86_64.box
vagrant init centos7
vagrant up
执行 vagrant init centos7
报:
`Vagrantfile` already exists in this directory. Remove it before
running `vagrant init`.
按照提示删除用户文件夹下 Vagrantfile 文件再次 vagrant init centos7
变成这样就可以 vagrant up
了
vagrant up
执行完成,如下所示:
现在虚拟机已经启动了,vagrant ssh
连接就可以了
vagrant ssh
踩坑1:路径有空格报错
This command was not invoked properly. The help for this command is
available below.
Usage: vagrant box add [options] <name, url, or path>
Options:
-c, --clean Clean any temporary download files
-f, --force Overwrite an existing box if it exists
--insecure Do not validate SSL certificates
--cacert FILE CA certificate for SSL download
--capath DIR CA certificate directory for SSL download
--cert FILE A client SSL cert, if needed
--location-trusted Trust 'Location' header from HTTP redirects and use the same credentials for subsequent urls as for the initial one
--provider PROVIDER Provider the box should satisfy
--box-version VERSION Constrain version of the added box
The box descriptor can be the name of a box on HashiCorp's Vagrant Cloud,
or a URL, or a local .box file, or a local .json file containing
the catalog metadata.
The options below only apply if you're adding a box file directly,
and not using a Vagrant server or a box structured like 'user/box':
--checksum CHECKSUM Checksum for the box
--checksum-type TYPE Checksum type (md5, sha1, sha256)
--name BOX Name of the box
-h, --help Print this help
踩坑2:安装过程某一步(不知道哪步)出问题会导致 vagrant ssh
以后要输入密码才能进入系统,按照开源软件的习惯,密码 = 用户名
输入 vagrant
登录成功
vagrant 常用命令
vagrant box add [options] <name, url, or path> - 添加box至vagrant的管理列表
vagrant init 初始化虚拟机至当前文件夹并自动生成配置文件vagrantfile
vagrant up 启动当前所在文件夹的虚拟机,若未初始化会自动初始化
vagrant ssh - 连接虚拟机
vagrant halt - 关闭虚拟机
vagrant reload - 重启虚拟机
vagrant destroy - 删除虚拟机,相当于删除VirtualBox列表中的Box,但Box文件还在
vagrant package - 打包开发环境