VirtualBox安装虚拟机启动vagrant up命令ssh不成功报错终极解决方案

在使用Oracle VM VirtualBox虚拟机安装centos-7.box的时候出现了各种问题,我大概除了的15个小时才解决掉。

开始为了防止兼容性的问题,我都使用了教程中的版本,其实这一步注定了错误的结局。

一些列的错误,各种方式都解决了,但最后还是青色的信息出不来。虚拟化,ssh等,本机都是没问题的。虚拟机连接方式,IP地址多次更改也是ping不通。

最后就一个办法下载最新版的程序包,问题解决了。

CentOS-7-x86_64-Vagrant-2004_01.VirtualBox .box

vagrant_2.2.10_x86_64.msi

VirtualBox-6.1.12-139181-Win.exe

如果使用vagrant up方式下载不下来,只能在url中下载了,和网络有关的,我在10小时内下载了很多次,就一次成功的。

由于在本地安装,且便于安装,我将CentOS-7-x86_64-Vagrant-2004_01.VirtualBox .box放入一个文件夹内,并且改名字为centos-7.box。

盒子位置如图:

 

 红框的文件是后生成的,先不必管它。

vagrant安装位置【这个在哪其实无所谓】:

 

然后执行下面的红色代码就能安装成功了。

其他博主说的哪些安装方式我都没成功,这是很多次失败得到的结果。

切记,如果没有安装成功,要从第一步vagrant开始安装【也许是我电脑特殊吧】,如果不这么做有时候会报其他错误。

有的错误信息记不清了,但是网上解决方案很难找,我将解决位置和方法记下来。

根据自己的安装路径去找VBoxDrv.inf文件。

我的如下:

D:\Program Files\Oracle\VirtualBox\drivers\vboxdrvVBoxDrv.inf

 

 

 找到后鼠标右键——安装

这样可以清除一些错误提示。

完整安装流程:

PS D:\centos_vagrant> vagrant
Usage: vagrant [options] <command> [<args>]

    -h, --help                       Print this help.

Common commands:
     autocomplete    manages autocomplete installation on host
     box             manages boxes: installation, removal, etc.
     cloud           manages everything related to Vagrant Cloud
     destroy         stops and deletes all traces of the vagrant machine
     global-status   outputs status Vagrant environments for this user
     halt            stops the vagrant machine
     help            shows the help for a subcommand
     init            initializes a new Vagrant environment by creating a Vagrantfile
     login
     package         packages a running vagrant environment into a box
     plugin          manages plugins: install, uninstall, update, etc.
     port            displays information about guest port mappings
     powershell      connects to machine via powershell remoting
     provision       provisions the vagrant machine
     push            deploys code in this environment to a configured destination
     rdp             connects to machine via RDP
     reload          restarts vagrant machine, loads new Vagrantfile configuration
     resume          resume a suspended vagrant machine
     snapshot        manages snapshots: saving, restoring, etc.
     ssh             connects to machine via SSH
     ssh-config      outputs OpenSSH valid configuration to connect to the machine
     status          outputs status of the vagrant machine
     suspend         suspends the machine
     up              starts and provisions the vagrant environment
     upload          upload to machine via communicator
     validate        validates the Vagrantfile
     version         prints current and latest Vagrant version
     winrm           executes commands on a machine via WinRM
     winrm-config    outputs WinRM configuration to connect to the machine

For help on any individual command run `vagrant COMMAND -h`

Additional subcommands are available, but are either more advanced
or not commonly used. To see all subcommands, run the command
`vagrant list-commands`.
        --[no-]color                 Enable or disable color output
        --machine-readable           Enable machine readable output
    -v, --version                    Display Vagrant version
        --debug                      Enable debug output
        --timestamp                  Enable timestamps on log output
        --debug-timestamp            Enable debug output with timestamps
        --no-tty                     Enable non-interactive output
PS D:\centos_vagrant> vagrant box add centos/7 D:\centos_vagrant\centos-7.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos/7' (v0) for provider:
    box: Unpacking necessary files from: file:///D:/centos_vagrant/centos-7.box
    box:
The box you're attempting to add already exists. Remove it before
adding it again or add it with the `--force` flag.

Name: centos/7
Provider: virtualbox
Version: 0
PS D:\centos_vagrant> vagrant init centos/7
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.
PS D:\centos_vagrant> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: centos_vagrant_default_1599716090579_64495
==> 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: 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: 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/centos_vagrant/ => /vagrant
PS D:\centos_vagrant> vagrant ssh
[vagrant@localhost ~]$
[vagrant@localhost ~]$
[vagrant@localhost ~]$ whoami
vagrant
[vagrant@localhost ~]$ ls /
bin   dev  home  lib64  mnt  proc  run   srv       sys  usr      var
boot  etc  lib   media  opt  root  sbin  swapfile  tmp  vagrant
[vagrant@localhost ~]$ exit;
logout
Connection to 127.0.0.1 closed.
PS D:\centos_vagrant>

  

vagrant 常用命令

启动

vagrant up

退出
vagrant halt

重启
vagrant reload

如果不使用命令,有时候虚拟机会报错坏掉😔

posted @ 2020-09-10 14:18  牧牛人Alec  阅读(1437)  评论(0编辑  收藏  举报