本文根据慕课网的视频教程练习,感谢慕课网!html
慕课的参考文档地址:https://github.com/apanly/mooc/tree/master/vagrant。git
输入: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
在D盘建立一个study目录:centos
[c:\~]$ d: [D:\]$ mkdir study
输入:vagrant init 镜像名称 ,初始化建立一个虚拟机配置文件(执行后会自动生成一个Vagrantfile文件)。网络
vagrant init ubuntu1404less
输入: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。
解释是:共享目录没法使用,虚拟机已经在运行了。
如下的方案都须要进入虚拟机里面执行。
sudo apt-get update sudo apt-get install virtualbox-guest-utils
(备注:第二条命令比较慢,而后再使用 vagrant up 就没有错误了)
sudo yum update sudo yum install gcc sudo yum install kernel-devel exit #退出虚拟机 vagrant halt # 关闭虚拟机
sudo find / -name VBoxGuestAdditions.iso
mount /dev/cdrom /cdrom #(该cdrom是我在/目录下建立的文件夹)
cd /cdrom; sh ./VBoxLinuxAdditions.run
vagrant up
使用: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操做。
【备注:这里发现虚拟机命令行没法与电脑进行复制粘贴,想到的方法是使用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.
暂时忽略。