---
title: "VMC命令 Bluemix"
author: "vergilwang"
date: "2013-08-05T17:18:00Z"
tags: []
categories: ["互联网"]
slug: "vmc-bluemix"
draft: false
lastmod: "2014-02-15T12:27:50Z"
id: 2011130
url: "https://vergilwang.iteye.com/blog/2011130"
---

# 安装命令行接口vmc

 

 

 

 

[in](http://blog.csdn.net/happyteafriends/article/details/8228840)

您可以在Unix终端或Windows命令提示符下使用Cloud Foundry的命令行界面（vmc）执行所有的Cloud Foundry的操作，如配置您的应用程序，并将其部署到Cloud Foundry等。

您可以执行vmc命令，以同样的方式部署你的应用程序到CloudFoundry.com或您自己的本地版本Cloud Foundry（Micro Cloud Foundry）。基本命令是相同的，唯一的区别是，您最初指定一个不同的target，然后再使用您的Cloud Foundry的凭据登录。

本节介绍安装vmc的前提条件，安装说明，以及如何部署一个简单的应用程序。

## []()前提条件: 安装 Ruby 和 RubyGems

vmc被作为一个Ruby gem来提供，这意味着你必须安装Ruby和RubyGems（Ruby包管理器）才能运行vmc。  
支持Ruby的以下版本:

- 1.8.7
- 1.9.2

如果你已经安装了 Ruby和RubyGems, 则可以跳过这一节，如果您需要安装，则参考：[如何安装Ruby和RubyGems](http://blog.csdn.net/magic_wz/article/details/8225611)

## []()安装vmc程序

如果您已经安装了[Ruby和RubyGems](http://blog.csdn.net/magic_wz/article/details/8225611)，那么安装vmc就非常简单了

- 首先去[Cloud Foundry](http://cloudfoundry.com/)注册一个账户. 您将会从邮箱收到您的账户信息。
- 打开终端 (Linux and Mac) 执行以下命令:

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt$sudogeminstallvmc

您需要知道sudo的密码.

如果是Windows系统, 打开一个Ruby的命令提示符，并执行以下命令：

**\[plain]**[view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt&gt;geminstallvmc

执行 `vmc target 命令来指定您要部署程序到哪个Cloud Foundry`:

 

- 要部署到PaaS Cloud Foundry, 指定`https://api.cloudfoundry.com`
- 部署到本地Micro Cloud Foundry, 指定`http://api.<appname>.cloudfoundry.me`, 其中appname是你在MicroCloud Foundry的网站上为您应用注册的域名. 参看[Installing Micro Cloud Foundry](http://docs.cloudfoundry.com/infrastructure/micro/installing-mcf.html).

 

 

 

下面的命令指定目标是PaaS Cloud Foundry:

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt$vmctargethttps://api.cloudfoundry.com

 

- 要确定你的当前目标，不带任何参数执行vmc target命令：

 

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt$vmctarget

<!--THE END-->

- 注册Cloud Foundry后，使用您电子邮件收到的用户凭据登录，您的用户名通常是您的电子邮件地址。

**\[plain]**[view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt$vmclogin

 

- 通过获取您的帐户信息，确保您已成功登录：

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt$vmcinfo

<!--THE END-->

- 修改密码:

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt$vmcpasswd

<!--THE END-->

- 通过执行vmc help命令查看完整的VMC的命令列表，以及它们的参数和一个简短的介绍：

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt$vmchelp

 

现在，您已经成功安装了vmc，并运行一些基本的命令。

## []()验证安装部署，一个示例应用程序

现在，你已经安装了vmc，登录到你的target，你就可以开始将应用程序部署到云。

本节说明如何部署一个简单的应用程序，该应用不需要任何服务（如MySQL或RabbitMQ）。本节的目的是通过部署和运行一个非常基本的应用程序，让你很快对vmc和Cloud Foundry有一个初步的感知。后面的章节描述了如何配置您的应用程序，并使用services连接到数据库或管理消息。

- 创建一个简单的应用程序，不需要任何服务，并适当地将其打包, 例如一个`*.war包的`Spring应用.
  
  如果您目前还没有一个应用程序，请参阅下一节的[创建一个简单的Sinatra应用](http://blog.csdn.net/happyteafriends/article/details/8228840#creating-a-simple-sinatra-application)，它介绍了如何使用Sinatra在短短的几分钟创建一个基本的Ruby写的[Hello World](http://blog.csdn.net/happyteafriends/article/details/8228840#creating-a-simple-sinatra-application)应用程序。
- 打开一个终端窗口（Linux）或命令提示符（Windows）,并改变其目录为包含您应用程序的目录。
  
  例如，如果您使用Sinatra创建了简单的Ruby写的[Hello World](http://blog.csdn.net/happyteafriends/article/details/8228840#creating-a-simple-sinatra-application)应用程序：

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt$cd/usr/bob/sample-apps/hello

<!--THE END-->

- 使用vmc的push命令部署你的应用程序，部署信息将会以交互地提示：

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt$vmcpush

提示需要输入yes或者no,默认值则用大写字母来表示，例如默认 “yes” , 则显示`[Yn]`.

下面的示例输出清晰地显示了您的响应 ，例子中显式输入了默认值。请参阅这个例子后的进一步解释：

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. Wouldyouliketodeployfromthecurrentdirectory?\[Yn]Yes
2. ApplicationName:hello
3. ApplicationDeployedURL:'hello.cloudfoundry.com'?hello-bob.cloudfoundry.com
4. DetectedaSinatraApplication,isthiscorrect?\[Yn]Yes
5. MemoryReservation\[Default:128M](64M,128M,256M,512Mor1G)(PressEntertotakedefault)
6. Wouldyouliketobindanyservicesto'hello'?\[yN]:No

完成提示的输入后，`vmc提供以下输出表明push（部署）成功`:

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. UploadingApplication:
2. Checkingforavailableresources:OK
3. Packingapplication:OK
4. Uploading(0K):OK
5. PushStatus:OK
6. StagingApplication:OK
7. StartingApplication:OK

应用程序的名称是指应用程序的内部名称以及您要部署的实际文件不带扩展名，这个例子中名称是hello.应用程序部署URL是指应用成功地部署到Cloud Foundry并启动后在浏览器中访问它所使用的URL。确保你指定一个唯一的的部署URL，否则vmc会返回一个错误消息提示URI已经被占用或保留。上面的例子中URL是hello-bob.cloudfoundry.com

验证您的应用程序可以通过执行vmc app命令：

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. $vmcapps
2. +--------------+----+--------+-------------------------------+----------+
3. |Application|#|Health|URLS|Services|
4. +--------------+----+--------+-------------------------------+----------+
5. |hello|1|RUNNING|hello-bob.cloudfoundry.com||
6. +--------------+----+--------+-------------------------------+----------+

在浏览器中输入vmc push时候指定的URL,上面例子中是hello-bob.cloudfoundry.com.

例如，如果您部署好了Hello World Sinatra应用，则您可以在浏览器中看到输出的文本信息：Hello from Cloud Foundry

![hello-bob-app.png](http://docs.cloudfoundry.com/images/screenshots/installing-vmc/hello-bob-app.png)

## []()部署应用更新

现在,您部署了自己的第一个应用程序,如果你修改了它，通过如下过程很容易对它进行更新。

在某种程度上改变你的应用程序,这样,当你运行它,你就会知道它是哪个版本。

例如，在Hello World Sinatra应用中修改hello.rb文件, 改变文本`Hello from Cloud Foundry`为`Hello from Cloud Foundry and VMware`.

在你的命令提示符或终端，确保您仍然在包含您的应用程序文件的目录，(`/usr/bob/sample-apps/hello.rb`本例子的目录)执行`vmc update命令`,指定您的应用的名称,本例子中名称是`hello`:

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. $vmcupdatehello
2. UploadingApplication:
3. Checkingforavailableresources:OK
4. Packingapplication:OK
5. Uploading(0K):OK
6. PushStatus:OK
7. StoppingApplication:OK
8. StagingApplication:OK
9. StartingApplication:OK

在浏览器中刷新应用，您将看到修改已经生效:

![hello-bob-app-updated.png](http://docs.cloudfoundry.com/images/screenshots/installing-vmc/hello-bob-app-updated.png)

## []()创建一个简单的Sinatra应用

首先在电脑中下载和安装[Sinatra Web framework](http://www.sinatrarb.com/)

创建目录，用于包含您的应用程序，例如：

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. prompt$mkdir/usr/bob/sample-apps/hello

使用您常用的文本编辑器，在刚才创建的目录下创建一个文件叫`hello.rb`，该文件内如如下：

**\[plain]** [view plain](http://blog.csdn.net/happyteafriends/article/details/8228840 "view plain")[copy](http://blog.csdn.net/happyteafriends/article/details/8228840 "copy")[print](http://blog.csdn.net/happyteafriends/article/details/8228840 "print")[?](http://blog.csdn.net/happyteafriends/article/details/8228840 "?")

 

1. require'sinatra'
2. get'/'do
3. "HellofromCloudFoundry"
4. end

![hello.rb](http://docs.cloudfoundry.com/images/screenshots/installing-vmc/vmc_hello.jpg "hello app")

## []()下一步：

- [Installing Micro Cloud Foundry](http://docs.cloudfoundry.com/infrastructure/micro/installing-mcf.html)
- [Deploying and Managing Applications](http://docs.cloudfoundry.com/tools/deploying-apps.html)
- [Configuring Applications to Use Cloud Foundry](http://docs.cloudfoundry.com/frameworks.html)
- [VMC Quick Reference Guide](http://docs.cloudfoundry.com/tools/vmc/vmc-quick-ref.html)
- [Debugging](http://docs.cloudfoundry.com/tools/vmc/debugging.html)