在Unix终端或者Windows命令行中使用Cloud Foundry命令行接口(即VMC),可以执行所有的Cloud Foundry操作,例如配置应用程序、在Cloud Foundry上发布它们。
无论你是将你的应用程序发布到了PaaS的Cloud Foundry(cloudfoundry.com)上,还是部署在Cloud Foundry的本地版本(也就是 Micro Cloud Foundry)上,使用VMC命令行接口操作它们的方式都是相同的。
以下章节描述了安装VMC的前提要求,以及如何发布一个简单的应用程序。
Subtopics(小标题)
- 先决条件:安装Ruby和RubyGems
- 安装VMC
- 通过发布一个简单的应用程序来验证安装是否成功。
- 接下来的步骤。
先决条件:安装Ruby和RubyGems
vmc是一Ruby应用程序包的形式进行分发的,这意味着你需要先安装Ruby的运行环境和RubyGems(一个Ruby包管理器)到计算机上或者其他运行vmc的环境中(可能是虚拟机上)。
如果你没有Ruby的运行环境,
当前支持的Ruby版本有如下:
- 1.8.7
- 1.9.2
如果你已经安装了Ruby和RubyGems,你可以跳过。
以下章节提供了在Windows和各种Linux发行版的计算机上安装Ruby和RubyGems的基本信息。
安装VMC
在你的计算机上安装了Ruby和RubyGems后,安装VMC的操作是很简单的。
-
-
打开终端(Linux下),然后执行如下命令。
-
PS:Window下则为打开命令行cmd.exe。
prompt$ sudo gem install vmc
所有sudo(super user 超级用户)命令,需要拥有系统管理员的权限来执行。
在Windows环境下,需要在Ruby启用的命令行下执行如下命令。
prompt> gem install vmc
-
Execute the
vmc target
command to specify the Cloud Foundry target to which you will deploy your applications:- To deploy on the PaaS Cloud Foundry, specify
api.cloudfoundry.com
- To deploy on your local Micro Cloud Foundry, specify
api.<appname>.cloudfoundry.me
, whereappname is the domain you registered for your application at the Micro Cloud Foundry Web site. SeeInstalling Micro Cloud Foundry.
The following command targets the PaaS Cloud Foundry:
- To deploy on the PaaS Cloud Foundry, specify
prompt$ vmc target api.cloudfoundry.com
To determine your current target, execute the `vmc target` command without any parameters:
prompt$ vmc target
- 使用在注册Cloud Foudnry后,通过email接受到的用户凭证信息登录。一般地,用户名即是Email地址。
prompt$ vmc login
- Ensure you have successfully logged in by retrieving information about your account:
prompt$ vmc info
- 修改密码
prompt$ vmc passwd
- View the full list of VMC commands, along with their parameters and a brief description, by executing the
vmc help
command:
prompt$ vmc help
You have now successfully installed vmc
and run a few basic commands.
通过发布一个简单的应用程序来验证安装是否成功
现在你已经安装了VMC并且登录到了你的目标(云)。你可以发布应用程序到云上边了。
该章节演示了如何发布一个简单的应用程序,该应用程序不需要任何服务(比如MySQL 或者 RabbitMQ)。
该章节的目的在于,通过发布和运行一个非常基础的应用程序,来让你快速的体验VMC和Cloud Foundry。
-
创建一个简单的应用程序,该应用程序不需要任何服务,将其合理地进行打包,例如打包为*.war文件或者Spring应用程序。
-
如果你现在没有一个应用程序,你可以参考Creating a Simple Sinatra Application获取如何通过使用Sinatra在仅仅几分钟内创建一个基本的Ruby的Hello World应用程序的说明。
-
打开终端(Linux)或者命令行(Windows),更改目录为包含你应用程序的目录。
prompt$ cd /usr/bob/sample-apps/hello
- 使用vmc push命令来发布你的应用程序。
prompt$ vmc push
需要是否回答确认的提示中,默认值是以答谢字母的形式给出的。例如,如果yes为默认值,你看到的则是Yn。
PS:是(Yes)、否(No),默认值为Yes,则是Yn,默认值为No,则是yN,默认值的使用大写。
Would you like to deploy from the current directory? [Yn] Yes Application Name: hello Application Deployed URL: 'hello.cloudfoundry.com'? hello-bob.cloudfoundry.com Detected a Sinatra Application, is this correct? [Yn] Yes Memory Reservation [Default:128M] (64M, 128M, 256M, 512M or 1G) (Press Enter to take default) Would you like to bind any services to 'hello'? [yN]: No
完成以上步骤后, 如果成功发布了应用程序,vmc显示如下成功提示:
Uploading Application:
Checking for available resources: OK
Packing application: OK
Uploading (0K): OK
Push Status: OK
Staging Application: OK
Starting Application: OK