本文共 4093 字,大约阅读时间需要 13 分钟。
1.Virtual box:VirtualBox 6.0.8 platform packages
https://www.virtualbox.org/wiki/Downloads
2.Vagrant:2.2.4
https://www.vagrantup.com/downloads.html
3.docker官网
4.vagrant cloud下载镜像网址https://app.vagrantup.com/boxes/search
1.配置Virtual box本地镜像路径
(1)管理-》全局设定
(2)修改虚拟电脑位置
1.打开cmd
2.创建centos7工作目录D:cd D:\Program Files\dockerimagemkdir centos7cd centos7
3.初始化box,生成配置文件vagrantfile
vagrant init centos/7
4.添加box:centos/7
D:\Program Files\dockerimage\centos7>vagrant box add centos/7==> box: Loading metadata for box 'centos/7' box: URL: https://vagrantcloud.com/centos/7This box can work with multiple providers! The providers that itcan work with are listed below. Please review the list and choosethe provider you will be working with.1) hyperv2) libvirt3) virtualbox4) vmware_desktopEnter your choice: 3==> box: Adding box 'centos/7' (v1902.01) for provider: virtualbox box: Downloading: https://vagrantcloud.com/centos/boxes/7/versions/1902.01/providers/virtualbox.box==> box: Box download is resuming from prior download progress box: Download redirected to host: cloud.centos.orgining: --:--:--) box: Progress: 100% (Rate: 2877k/s, Estimated time remaining: --:--:--)==> box: Successfully added box 'centos/7' (v1902.01) for 'virtualbox'!
5.启动本地环境(在virtual box中可以看到)
D:\Program Files\dockerimage\centos7>vagrant upBringing machine 'default' up with 'virtualbox' provider...==> default: Importing base box 'centos/7'...==> default: Matching MAC address for NAT networking...==> default: Checking if box 'centos/7' version '1902.01' is up to date...==> default: Setting the name of the VM: centos7_default_1560209749504_30254==> 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: 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: Machine booted and ready!==> default: Checking for guest additions in VM... default: No guest additions were detected on the base box for this VM! Guest default: additions are required for forwarded ports, shared folders, host only default: networking, and more. If SSH fails on this machine, please install default: the guest additions and repackage the box to continue. default: default: This is not an error message; everything may continue to work properly, default: in which case you may ignore this message.==> default: Rsyncing folder: /cygdrive/d/Program Files/dockerimage/centos7/ => /vagrant
打开virtual box
6.查看vagrant启动虚拟机状态
..\dockerImage\centos7> vagrant status结果:Current machine states:default running (virtualbox)The VM is running. To stop this VM, you can run `vagrant halt` toshut it down forcefully, or you can run `vagrant suspend` to simplysuspend the virtual machine. In either case, to restart it again,simply run `vagrant up`.
7.连接centos7
vagrant ssh #只有一个或者vagrant ssh 主机名 #有多个主机
(1)报错
D:\Program Files\dockerimage\centos7>vagrant ssh vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic). (2)原因是windows登录用户没有秘钥权限 (3)解决办法参考:8.root用户
127.0.0.1:2222root/vagrant
vagrant box add 添加box的操作vagrant init 初始化box的操作,会生成vagrant的配置文件Vagrantfile vagrant up 启动本地环境 vagrant ssh 通过 ssh 登录本地环境所在虚拟机 (Windows不支持使用此指定登录)vagrant halt 关闭本地环境 vagrant suspend 暂停本地环境 vagrant resume 恢复本地环境vagrant reload 修改了 Vagrantfile 后,使之生效(相当于先 halt,再 up) vagrant destroy彻底移除本地环境 vagrant box list 显示当前已经添加的box列表 vagrant box remove 删除相应的boxvagrant package 打包命令,可以把当前的运行的虚拟机环境进行打包 vagrant plugin 用于安装卸载插件vagrant status 获取当前虚拟机的状态 vagrant global-status 显示当前用户Vagrant的所有环境状态
转载地址:http://hgygi.baihongyu.com/