我接下来的操作就是把这个本来用vb打开会有图形界面的虚拟机,转化成直接可以用原系统terminal的基于 vagrant 工具运行虚拟机。原理就是通过一番操作得到 Vagrant 能用的 .box 文件,然后用 vagrant 激活之,做一个vagrant。
Step.0
先得有用 VirtualBox 建立的虚拟机,如图中这个sam。
虚拟机在VB中
Step.1 得到 .box 文件
$ VBoxManage list vms
"sam" {d15cacce-268c-4c80-8b38-d27e07b54a69}
$ vagrant package --base d15cacce-268c-4c80-8b38-d27e07b54a69 --output cloudera.box
==> d15cacce-268c-4c80-8b38-d27e07b54a69: Exporting VM...
==> d15cacce-268c-4c80-8b38-d27e07b54a69: Compressing package to: /Users/Samuel/cloudera.box
Step.2 把 .box 文件加载给 Vagrant
新建一个文件夹,我这里就用hadoop
~/hadoop $ vagrant init cloudera /Users/Samuel/cloudera.box
这样就会有个~/hadoop/Vagrantfile
Step.3 添加内容到 Vagrantfile
中配置
其实这一步主要作用是让Vagrant能直接访问这个虚拟机,目的是让起能和原系统间交流,共享文件。
config.ssh.username = "cloudera"
config.ssh.password = "cloudera"
在 end
之前的任意一行添加这两个就行了,给出主用户的名和密码。
Step.4 运行之
~/hadoop $ vagrant up
==> default: Clearing any previously set forwarded ports...
==> 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: cloudera
default: SSH auth method: password
==> 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.2.6
default: VirtualBox Version: 5.1
==> default: Mounting shared folders...
default: /vagrant => /Users/Samuel/hadup
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
~/hadoop $ vagrant ssh
Last login: Fri Sep 14 07:09:31 2018 from 10.0.2.2
[cloudera@localhost ~]$
网友评论