vagrant的学习 之 基础学习

vagrant的学习 之 基础学习


本文根据慕课网的视频教程练习,感谢慕课网!

慕课的参考文档地址:https://github.com/apanly/mooc/tree/master/vagrant


(1)下载安装虚拟机VirtualBox(我安装的版本是5.2.4)。


(2)下载Ubuntu镜像(我安装的是教程指定的ubuntu-14.04-amd64.box)。


(3)下载安装vagrant软件(安装后会提示需要重启电脑)。


(4)打开Xshell软件:

  输入:vagrant -v,查看vagrant版本。

  输入:vagrant box list 查看当前已有的镜像。

  输入:vagrant box add 命名镜像名字  镜像位置

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

  再次输入:vagrant box list 就可以看到刚添加的镜像。


(5)初始化创建一个虚拟机配置:

在D盘创建一个study目录:

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

  输入:vagrant init  镜像名称 ,初始化创建一个虚拟机配置文件(执行后会自动生成一个Vagrantfile文件)。

    vagrant init ubuntu1404


(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'

搜到的结果,参考原文:https://www.cnblogs.com/fengchi/p/6549784.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,配置网络可以参考我的另一篇博客:https://www.cnblogs.com/gyfluck/p/9553993.html

1、复制备份原软件源列表:

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

2、打开sources.list:

sudo vim /etc/apt/sources.list

3、清空内容,复制 视频中的 软件源列表,到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.

暂时忽略。


  



原文地址:https://www.cnblogs.com/gyfluck/p/9548756.html