我接下來的操作就是把這個(gè)本來用vb打開會有圖形界面的虛擬機(jī)檀咙,轉(zhuǎn)化成直接可以用原系統(tǒng)terminal的基于 vagrant 工具運(yùn)行虛擬機(jī)凰兑。原理就是通過一番操作得到 Vagrant 能用的 .box 文件,然后用 vagrant 激活之顷啼,做一個(gè)vagrant逐虚。
Step.0
先得有用 VirtualBox 建立的虛擬機(jī)刑赶,如圖中這個(gè)sam克伊。
虛擬機(jī)在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
新建一個(gè)文件夾酥郭,我這里就用hadoop
~/hadoop $ vagrant init cloudera /Users/Samuel/cloudera.box
這樣就會有個(gè)~/hadoop/Vagrantfile
Step.3 添加內(nèi)容到 Vagrantfile
中配置
其實(shí)這一步主要作用是讓Vagrant能直接訪問這個(gè)虛擬機(jī),目的是讓起能和原系統(tǒng)間交流愿吹,共享文件褥民。
config.ssh.username = "cloudera"
config.ssh.password = "cloudera"
在 end
之前的任意一行添加這兩個(gè)就行了,給出主用戶的名和密碼洗搂。
Step.4 運(yùn)行之
~/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 ~]$