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

标签: vagrant 跨平台 开发 | 发表时间:2015-03-24 08: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应用程序了.

Java开发者一个月开发出跨平台开源办公软件

- - Solidot
Java开发者Anthony Goubard用了一个月的时间开发出一个简单的跨平台开源办公套件,可运行在Windows、Mac OS X、Linux和浏览器上. 这个办公软件被称为 Joeffice,包含了非常基础的字处理器、电子表格、幻灯演示程序和数据库软件,Goubard称,软件用NetBeans构建,使用了大量流行的Java开源库,因此他才能在30天内完成开发.

分清“语言/规范”以及“平台/实现”,以及跨平台.NET开发

- 王雪松 - 博客园-老赵点滴 - 追求编程之美
在许多年前,“语言”就等同于“平台”,例如C,C++以及最早的Ruby和Python等等. 但是随着技术发展,出现了一些通用的平台,例如.NET和Java,逐渐这些平台上的语言也越来越多. 再后来,某些语言在不同平台上的实现也越来越多,事情也变得有些复杂. 技术在发展,但是从目前社区的讨论中,我发现许多朋友的观念还没有跟上.

【转发】使用 Sencha Touch 开发超炫的跨平台移动 Web 应用

- - HTML5研究小组
胡 沙, IBM CSTL 软件工程师, IBM. Sencha Touch 是由  Sencha 公司开发的移动 Web 应用开发框架,用以提升主流移动设备在浏览器上的触碰操作,增强用户体验. 该框架以久负盛名的 Ext JS 富客户端框架为基础,并支持最新的 HTML5 及 CSS3 标准,与流行的 Apple iOS 和 Andriod 设备兼容.