使用简单,不用自己安装虚拟机,有现成的镜像,只需下载安装vagrant后直接调用就可以了
我使用的是virtualbox的镜像
1、下载安装vagrant
下载地址 :https://www.vagrantup.com/downloads
选择适合自己电脑的版本下载,安装时下一步下一步就可以了
2、下载virtualbox和virtualbox镜像
virtuabox下载地址:https://www.virtualbox.org/wiki/Downloads 安装时点击下一步即可
镜像下载地址: http://www.vagrantbox.es/
我下载的为:centos65-x86_64-20140116.box
3、下载之后开始加载
1)cmd下找到镜像所在的位置
D:\xu\cetnos65>dir
2021/09/13 10:37 293,676,266 centos65-x86_64-20140116.box
2)安装虚拟机
D:\xu\cetnos65>vagrant box add new_box centos65-x86_64-20140116.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'new_box' (v0) for provider:
box: Unpacking necessary files from: file://D:/xu/cetnos65/centos65-x86_64-20140116.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: new_box
Provider: virtualbox
Version: 0
3)注册虚拟机
D:\xu\cetnos65>vagrant init box_name
`Vagrantfile` already exists in this directory. Remove it before
running `vagrant init`.
4)启动虚拟机
D:\xu\cetnos65>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'new_box'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: cetnos65_default_1632642565053_83625
Vagrant is currently configured to create VirtualBox synced folders with
the `SharedFoldersEnableSymlinksCreate` option enabled. If the Vagrant
guest is not trusted, you may want to disable this option. For more
information on this option, please refer to the VirtualBox manual:
https://www.virtualbox.org/manual/ch04.html#sharedfolders
This option can be disabled globally with an environment variable:
VAGRANT_DISABLE_VBOXSYMLINKCREATE=1
or on a per folder basis within the Vagrantfile:
config.vm.synced_folder '/host/path', '/guest/path', SharedFoldersEnableSymlinksCreate: false
==> 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 虚拟机的ip地址和端口号
default: SSH username: vagrant 用户名和密码均为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: The guest additions on this VM do not match the installed version of
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 the
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.6
default: VirtualBox Version: 6.1
==> default: Mounting shared folders...
default: /vagrant => D:/xu/cetnos65
4、打开virtualbox进行查看,已经在运行
5、远程软件进行连接
问题:
加载时遇到了一个问题:
报错kernel_require.rb:83:in `require'
原因是我安装vagrant时,安装目录采用了中文的原因,将安装目录变更为英文后,记得变更环境变量,否则会报错找不到命令vagrant