使用 Vagrant 打造跨平台开发环境

标签: vagrant 跨平台 开发 | 发表时间:2015-03-24 16:06 | 作者:dcj3sjt126com
出处:http://www.iteye.com

参考地址1: http://segmentfault.com/blog/fenbox/1190000000264347

参考地址2: http://blog.phpor.me/2014/10/12/vagrant-%E6%9C%AC%E5%9C%B0%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83.html

 

下载的系统是centos6.3 64位: https://s3.amazonaws.com/itmat-public/centos-6.3-chef-10.14.2.box

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

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

 

以下是实战内容:

Last login: Tue Mar 24 14:20:44 on console
➜  ~  ls
AFNetworking               Documents                  Music                      Rainforest                 install.log                swift_language_learning.md
AndroidStudioProjects      Downloads                  PhpstormProjects           VirtualBox VMs             mbox                       t.txt
Applications               Library                    Pictures                   a.php                      myfile.in                  test.awk
Desktop                    Movies                     Public                     dead.letter                paros
➜  ~  cd Documents/vagrant_maxwelldu 
➜  vagrant_maxwelldu  ls
movienext
➜  vagrant_maxwelldu  cd movienext 
➜  movienext  ls
➜  movienext  ll
➜  movienext  vagrant box add base ~/Downloads/centos-6.3-chef-10.14.2.box 
==> box: Adding box 'base' (v0) for provider: 
    box: Downloading: file:///Users/michaeldu/Downloads/centos-6.3-chef-10.14.2.box
==> box: Successfully added box 'base' (v0) for 'virtualbox'!
➜  movienext  ls
➜  movienext  ll
➜  movienext  vagrant box list
base (virtualbox, 0)
➜  movienext  vagrant init base
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
➜  movienext  ll
total 8
-rw-r--r--  1 michaeldu  staff  3016 Mar 24 16:00 Vagrantfile
➜  movienext  vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'base'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: movienext_default_1427184057998_56337
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (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: Warning: Connection timeout. Retrying...
    default: Warning: Remote connection disconnect. Retrying...
    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: Removing insecure key from the guest if its present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.1.22
    default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
    default: /vagrant => /Users/michaeldu/Documents/vagrant_maxwelldu/movienext
➜  movienext  vagrant ssh
Last login: Fri Sep 14 17:53:41 2012 from 10.0.2.2
[vagrant@localhost ~]$ cd /va
vagrant/ var/     
[vagrant@localhost ~]$ cd /va
vagrant/ var/     
[vagrant@localhost ~]$ cd /vagrant/
[vagrant@localhost vagrant]$ wget http://www.baidu.com
--2015-03-24 09:02:48--  http://www.baidu.com/
Resolving www.baidu.com... ^C
[vagrant@localhost vagrant]$ exit
logout
Connection to 127.0.0.1 closed.
➜  movienext  vim Vagrantfile 
➜  movienext  vagrant reload 
==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2222 (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: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.1.22
    default: VirtualBox Version: 4.3
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /Users/michaeldu/Documents/vagrant_maxwelldu/movienext
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: to force provisioning. Provisioners marked to run always will still run.
➜  movienext  vagrant ssh
Last login: Tue Mar 24 09:01:32 2015 from 10.0.2.2
[vagrant@localhost ~]$ ping www.baidu.com
PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.
64 bytes from 61.135.169.125: icmp_seq=1 ttl=63 time=5.12 ms
64 bytes from 61.135.169.125: icmp_seq=2 ttl=63 time=5.86 ms
64 bytes from 61.135.169.125: icmp_seq=3 ttl=63 time=4.77 ms
^C
--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2112ms
rtt min/avg/max/mdev = 4.775/5.255/5.867/0.459 ms

 

到这里把vagrant安装好了, 进去了, 后面还需要安装lnmp

nginx安装参考地址: http://blog.csdn.net/stuartjing/article/details/8124491

nginx对应版本地址: http://nginx.org/en/download.html

 

安装好了之后, 



已有 0 人发表留言,猛击->> 这里<<-参与讨论


ITeye推荐



相关 [vagrant 跨平台 开发] 推荐:

使用 Vagrant 打造跨平台开发环境

- - Linux - 操作系统 - ITeye博客
参考地址1: http://segmentfault.com/blog/fenbox/1190000000264347. 参考地址2: http://blog.phpor.me/2014/10/12/vagrant-%E6%9C%AC%E5%9C%B0%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83.html.

Vagrant作者分享开源体会

- - InfoQ cn
Mitchell Hashimoto是一名开源软件工程师, Vagrant项目的作者, Vagrant是一个用Ruby实现的用于构建虚拟化开发平台的工具. 如今 Vagrant已经被无数人使用,并成功获得了两个赞助商做收费技术支持. Mitchell在其博客上,分享了开发开源软件的 经验和心得,这里不仅仅是技术,还有如何做一个好的开源项目维护者,以及如何推广自己的产品.

跨平台开发工具Qt SDK 1.1.3发布

- tinda - Solidot
chinakr 写道 "Nokia于本月1日发布了Qt SDK 1.1.3,更新内容包括功能改进和软件质量提升. Qt SDK 1.1.3下载链接:Windows版,Linux版(32位),Linux版(64位)和Mac OS X版.

Moscrif:用JavaScript进行跨平台移动开发

- - InfoQ cn
Moscrif是构建在定制虚拟机上的跨平台移动开发环境. 尽管该平台提供了访问原生设备的功能,但编程语言却是JavaScript的一个定制版本. 据公司联合创始人Michal Habalcik所说,Moscrif已支持iOS、Android、Symbian、Windows Mobile和Bada等平台,而且还将在微软发布API之后,添加对Windows Phone 8的支持.

跨平台移动框架iMAG开发入门

- - IT技术博客大学习
iMAG是一个非常简洁高效的移动跨平台开发框架,开发一次可以同时兼容Android和iOS平台,有点儿Web开发基础就能很快上手. 当前移动端跨平台开发的框架有很多,但用iMAG还有一个好处,就是用iMAG开发出的App是原生的. iMAG采用XML + JavaScript(配置 + 脚本)的开发方式,它的原理是将符合iMAG开发规范的XML文件解释成对应的原生应用代码来执行.

聊聊移动端跨平台开发的各种技术

- - FEX 百度 Web 前端研发部
最近出现的 React Native 再次让跨平台移动端开发这个话题火起来了,曾经大家以为在手机上可以像桌面那样通过 Web 技术来实现跨平台开发,却大多因为性能或功能问题而放弃,不得不针对不同平台开发多个版本. 但这并没有阻止人们对跨平台开发技术的探索,毕竟谁不想降低开发成本,一次编写就处处运行呢.

App跨平台开发方案与抉择

- - CSDN博客推荐文章
内心强大才敢于承认错误,但是首先你要敢于去试错. 现在做客户端开发的公司都会面临一个巨大的问题,那么就是跨平台. 对于目前上市面上的移动设备来说. Android、IOS、WindowsPhone、BlackBattery等等移动设备系统,让我们在开发适配上都很头痛. 但是由于Google与Apple公司的竞争,现在创业公司主要关注的就只有是Android和IOS应用程序了.

移动端跨平台开发的深度解析

- - IT瘾-dev
  跨平台一直是老生常谈的话题,cordova、ionic、react-native、weex、kotlin-native、flutter等跨平台框架的百花齐放,颇有一股推倒原生开发者的势头. (事实上更多是共存发展)看完本篇,相信你会对于当下跨平台移动开发的现状、实现原理、框架的选择等有更深入的理解.

跨平台开发技术年终盘点

- - SegmentFault 最新的文章
一直以来,效率都是互联网企业的生命线. 而 “通过技术升级实现三个人干五个人的活,赚四个人的工资”是企业和个人一直渴望达到的双赢局面. 随着行业竞争加剧,为进一步提升开发效率,跨平台开发逐渐的成为了互联网行业的刚需. 这样的大趋势下,一些头部互联网公司基于自身技术背景和当时技术条件,推出了不同类型的跨平台解决方案.

Electron+Vue开发跨平台桌面应用

- - SegmentFault 最新的文章
虽然B/S是目前开发的主流,但是C/S仍然有很大的市场需求. 受限于浏览器的沙盒限制,网页应用无法满足某些场景下的使用需求,而桌面应用可以读写本地文件、调用更多系统资源,再加上Web开发的低成本、高效率的优势,这种跨平台方式越来越受到开发者的喜爱. Electron是一个基于Chromium和 Node.js,使用 HTML、CSS和JavaScript来构建跨平台应用的跨平台开发框架,兼容 Mac、Windows 和 Linux.