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=,gid= 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.--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键切换到命令行模式

:,$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: 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 ( 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.

暂时忽略。




vagrant的学习 之 基础学习的更多相关文章

  1. [AngularJS学习笔记] 基础学习01

    2016-06-06开始学习AngularJS AngularJS是会extend HTML的 ng-directives 先学习了四个 ng-app:定义AngularJS Application的 ...

  2. 前端学习:html基础学习一

    1.HTML的语法(主要内容HTML语法格式.文档注释.代码格式) HTML的特点 1.可以设置文本的格式,比如标题.字号.文本颜色.段落等等 2.可以创建列表(例如打开百度,我们可以看到这样的列表) ...

  3. JavaScript 学习笔记(基础学习)

    一:来自W3School工具的学习 1:document.getElementById(id) : 访问某个标签的元素,然后对它进行操作 .innerHTML 对其内容进行修改 2:document. ...

  4. Python学习---线程基础学习

    线程基础 什么是线程(thread) 线程是CPU调度能够进行运算调度的最小单位.它被包含在进程之中,是进程中的实际运作单位.一条线程指的是进程中一个单一顺序的控制流[换言之,线程就是一堆指令集合], ...

  5. 视频学习_css基础学习

    块状元素 block element 容器元素  设置高宽 width height  可以容纳 文本 内脸 和其他块状 霸道  独占一行 特例:form  只容纳 块状元素 常见元素 http:// ...

  6. 前端学习:html基础学习五

    9.HTML表单设计(主要内容<form><input><select>标记) 表单标记 <form>...</form> <form ...

  7. 前端学习:html基础学习四

    7.HTML表格(主要内容<table><caption><tr><th><td>标记) <table>标记 基本格式 < ...

  8. 前端学习:html基础学习三

    5.图像标记(主要内容<img>标记) <img>标记的使用方法 <img src="路径/文件名.图片格式" width="属性值&quo ...

  9. 前端学习:html基础学习二

    3.文档设置标记上-格式标记(主要内容标记<br><p><center><pre><li><ul><ol><d ...

随机推荐

  1. POJ 2002 Squares 数学 + 必须hash

    http://poj.org/problem?id=2002 只能说hash比二分快很多.随便一个hash函数都可以完爆二分. 判断是否存在正方形思路如下: 1.枚举任意两个点,作为正方形的一条边,那 ...

  2. sdut1283Five in a Row, Again

    一简单的状压题 比赛时跑偏了 ,脑子最近乱的跟浆糊似得呢.. #include <iostream> #include<cstdio> #include<cstring& ...

  3. CF940D Alena And The Heater

    思路: 模拟. 实现: #include <bits/stdc++.h> using namespace std; const int INF = 1e9; ], n; string b; ...

  4. hihocoder offer收割编程练习赛11 B 物品价值

    思路: 状态压缩 + dp. 实现: #include <iostream> #include <cstdio> #include <cstring> #inclu ...

  5. 关于Android软键盘把布局顶上去的问题

    首先说下我的需求:布局最上面是一个bar,有左上角返回按钮和标题,bar下面是一个ScrollView,里面有各种TextView和EditText, 点击下面的EditText时,不希望软键盘把ba ...

  6. Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图的数据操作

    导航 目   录:Farseer.net轻量级ORM开源框架 目录 上一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图实体类映射 下一篇:Farseer.net轻量级ORM开源 ...

  7. C++ 继承/派生、访问属性、构造函数

    1.子类继承父类的继承方式:public,private,protected,不写则默认为private: 2.子类会继承父类的全部成员(除了构造函数.析构函数,虽然析构函数有virtual,但是不是 ...

  8. biff - 新到邮件提醒

    总览 (SYNOPSIS) biff [ny ] 描述 (DESCRIPTION) Biff 通知系统在当前终端会话期间有新邮件是否提醒你. 支持的选项有 biff n 禁止新邮件提醒. y 开启新邮 ...

  9. ALTER OPERATOR CLASS - 修改一个操作符表的定义

    SYNOPSIS ALTER OPERATOR CLASS name USING index_method RENAME TO newname DESCRIPTION 描述 ALTER OPERATO ...

  10. CAD交互绘制虚线(com接口)

    用户可以在控件视区任意位置绘制直线. 主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY ...