vagrant的學習 之 基礎學習

vagrant的學習 之 基礎學習


 

本文根據慕課網的視頻教程練習,感謝慕課網!html

慕課的參考文檔地址:https://github.com/apanly/mooc/tree/master/vagrantgit


 

(1)下載安裝虛擬機VirtualBox(我安裝的版本是5.2.4)。


 

(2)下載Ubuntu鏡像(我安裝的是教程指定的ubuntu-14.04-amd64.box)。


 

(3)下載安裝vagrant軟件(安裝後會提示須要重啓電腦)。


 

(4)打開Xshell軟件:

  輸入:vagrant -v,查看vagrant版本。github

  輸入:vagrant box list 查看當前已有的鏡像。shell

  輸入:vagrant box add 命名鏡像名字  鏡像位置ubuntu

  (vagrant box add  ubuntu1404 E:\ubuntu-14.04-amd64.box)vim

  再次輸入:vagrant box list 就能夠看到剛添加的鏡像。windows


 

(5)初始化建立一個虛擬機配置:

在D盤建立一個study目錄:centos

[c:\~]$ d:
[D:\]$ mkdir study

  輸入:vagrant init  鏡像名稱 ,初始化建立一個虛擬機配置文件(執行後會自動生成一個Vagrantfile文件)。網絡

    vagrant init ubuntu1404less


 

(6)啓動虛擬機:

  輸入:vagrant up ,啓動虛擬機。

  可是報錯:  

The version of powershell currently installed on this host is less than
the required minimum version. Please upgrade the installed version of
powershell to the minimum required version and run the command again.

提示powershell版本太低,windows7默認的powershell是2.0,須要升級,

搜到這個網址:http://www.pstips.net/powershell-introduction-and-install.html
而後下載:4.0版本,http://www.microsoft.com/en-us/download/details.aspx?id=40855

選擇Windows6.1-KB2819745-x64-MultiPkg.msu下載安裝。

安裝後須要重啓電腦,而後再次執行:vagrant up,這是後虛擬機運行起來了,可是結果出有點錯誤信息:

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:

mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant

The error output from the command was:

mount: unknown filesystem type 'vboxsf'

搜到的結果,參考原文:http://www.javashuo.com/article/p-uvsyfavw-dw.html

解釋是:共享目錄沒法使用,虛擬機已經在運行了。

如下的方案都須要進入虛擬機裏面執行。

默認登陸帳號和密碼都是:vagrant。

ubuntu系統處理方案

sudo apt-get update

sudo apt-get install virtualbox-guest-utils

(備註:第二條命令比較慢,而後再使用 vagrant up 就沒有錯誤了)

centos系統處理方案(mac版)

sudo yum update
sudo yum install gcc
sudo yum install kernel-devel

exit #退出虛擬機
vagrant halt # 關閉虛擬機
加載  VBoxGuestAdditions.iso 鏡像並掛載
該鏡像位於VirtualBox安裝文件夾下,能夠全文件搜索
sudo find / -name VBoxGuestAdditions.iso 
將CD進行掛載
mount /dev/cdrom /cdrom #(該cdrom是我在/目錄下建立的文件夾)
進入cdrom並運行相關程序。
cd /cdrom; 
sh ./VBoxLinuxAdditions.run
等待程序安裝完畢,VirtualBox加強功能軟件就在系統中安裝完畢

重啓虛擬機

vagrant up

(7)登陸虛擬機:

使用:vagrant ssh 能夠登陸到虛擬機:

[D:\study]$ vagrant ssh
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-24-generic x86_64)

                                                                 * Documentation:  https://help.ubuntu.com/
                   New release '16.04.5 LTS' available.
                                                       Run 'do-release-upgrade' to upgrade to it.

沒有登錄成功,也沒有報錯,只是提示ubuntu有新版本。

暫時未找到爲何沒有登陸成功的問題,放棄直接使用VirtualBox操做。


 (8)修改軟件下載源,提高下載速度:

【備註:這裏發現虛擬機命令行沒法與電腦進行復制粘貼,想到的方法是使用Xshell工具,

須要配置靜態ip,配置網絡能夠參考個人另外一篇博客:http://www.javashuo.com/article/p-wuqskvfn-eb.html

一、複製備份原軟件源列表:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

二、打開sources.list:

sudo vim /etc/apt/sources.list

三、清空內容,複製 視頻中的 軟件源列表,到sources.list中。

清空內容:

按Esc鍵切換到命令行模式

:1,$d

新內容:

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

更新源:

sudo apt-get update

會看到在用aliyun的源,遇到一些錯誤信息:

Get:77 http://mirrors.aliyun.com trusty/universe Translation-en [4,089 kB]                                                  
Ign http://mirrors.aliyun.com trusty/main Translation-en_US                                                                 
Ign http://mirrors.aliyun.com trusty/multiverse Translation-en_US                                                           
Ign http://mirrors.aliyun.com trusty/restricted Translation-en_US                                                           
Ign http://mirrors.aliyun.com trusty/universe Translation-en_US                                                             
Fetched 35.2 MB in 1min 22s (424 kB/s)                                                                                      
W: Failed to fetch http://mirrors.aliyun.com/ubuntu/dists/trusty-backports/InRelease  Unable to find expected entry 'multiversei/binary-amd64/Packages' in Release file (Wrong sources.list entry or malformed file)

E: Some index files failed to download. They have been ignored, or old ones used instead.

暫時忽略。

相關文章
相關標籤/搜索