Vagrant + Virtual Box 搭建开发环境

Vagrant + Virtual Box 搭建开发环境

一、简介

vagrant 简介

官网介绍 下载地址

Vagrant 是一款用来构建虚拟开发环境的工具,非常适合 php/python/ruby/java 这类语言开发 web 应用,“代码在我机子上运行没有问题”这种说辞将成为历史。

我们可以通过 Vagrant 封装一个 Linux 的开发环境,分发给团队成员。成员可以在自己喜欢的桌面系统(Mac/Windows/Linux)上开发程序,代码却能统一在封装好的环境里运行,非常霸气。

Vargant的优点

1、 统一开发环境。一次配置打包,统一分发给团队成员,统一团队开发环境,解决诸如“编码问题”,“缺少模块”,“配置文件不同”带来的问题;

2、 避免重复搭建开发环境。新员工加入,不用浪费时间搭建开发环境,快速加入开发,减少时间成本的浪费;

3、 多个相互隔离开发环境。可以在不用box里跑不同的语言,或者编译安装同一语言不同版本,搭建多个相互隔离的开发环境,卸载清除时也很快捷轻松。

VirtualBox 简介

官网介绍 下载地址

VirtualBox 是一个免费开源的虚拟机,相对 VMware 来说更加小巧

VirtualBox是一个功能强大的x86和AMD 64/Intel 64虚拟化产品适用于企业及家庭使用。VirtualBox不仅是面向企业客户的极其丰富、高性能的产品,而且也是在GNU通用公共许可证(GPL)版本2的条件下作为开放源码软件免费提供的唯一专业解决方案。关于VirtualBox

目前,VirtualBox运行在Windows、Linux、Macintosh和Solaris主机上,支持大量的客人操作系统包括但不限于Windows(NT 4.0、2000、XP、Server 2003、Vista、Windows 7、Windows 8、Windows 10)、DOS/Windows 3.x、Linux(2.4、2.6、3.x和4.x)、Solaris和OpenSolaris、OS/2和OpenBSD。

二、安装步骤

Vargant 安装

此处省略。。。(一路next即可)

VirtualBox 安装

此处省略。。。(一路next即可)

三、使用

vagrant 使用

安装操作系统 必须先创建目录centos7,并在该目录下打开PowerShell

vagrant init centos/7

添加镜像virtualbox.box到vagrant管理的镜像中

vagrant box add centos/7 D:\virtualbox.box

查看vagrant管理的镜像

vagrant box list

启动

PS E:\VirtualBox VMs\centos7> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: centos7_default_1587001475085_70918
==> 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: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: No guest additions were detected on the base box for this VM! Guest
    default: additions are required for forwarded ports, shared folders, host only
    default: networking, and more. If SSH fails on this machine, please install
    default: the guest additions and repackage the box to continue.
    default:
    default: This is not an error message; everything may continue to work properly,
    default: in which case you may ignore this message.
==> default: Rsyncing folder: /cygdrive/e/VirtualBox VMs/centos7/ => /vagrant

关闭

PS E:\VirtualBox VMs\centos7> vagrant halt
==> default: Attempting graceful shutdown of VM...

vagrant 常用指令

vagrant halt     优雅关闭
vagrant up       正常启动
vagrant ssh      进入刚才创建的centos7中
vagrant status   查看centos7的状态
vagrant halt     停止/关闭centos7
vagrant destroy  删除centos7
vagrant status   查看当前vagrant创建的虚拟机

安装过程可能遇到的错误

1)、Vagrant 和 Virtual Box版本不一致造成的错误

请参考博客 https://blog.csdn.net/m82_a1/article/details/97250162

使用过程错误

1)、vagrant ssh 无权限

请参考博客 https://blog.csdn.net/weixin_34008805/article/details/91453210

PS E:\VirtualBox VMs\centos7> vagrant ssh
vagrant@127.0.0.1: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

参考文章

vagrant 官方文档 https://www.vagrantup.com/docs/vagrantfile/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值