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

如果不使用命令,有時候虛擬機會報錯壞掉😔

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章