下面简述我在Cloud Foundry部署个人应用“咖啡厅”的坎坷历程,仅做为笔记使用。我想每一个人遇到的问题都是不一样的,布署不成功找缘由最好、也是最有效的方法就是看Tomcat系统错误日志logs! java
根据众多教程及方法,咱们知道部署CF应用有多种方式,我所熟悉的是经过Ruby命令行和Eclipse插件,在此推荐Eclipse插件,由于这种方式更直观,并且能够很方便的查看系统日志,便于错误调试。 node
1.Eclipse插件的下载 mysql
1)Help-- >Eclipse Marketplace,在弹出框里,输入Cloud Foundry,点击安装,安装后重启Eclipse,就表明安装完成了。 git
2)安装完成须要调出这个插件使用,方法是:Window --> Show View ,在弹出框里选择Server,点击肯定,这是就会在平时咱们经常使用的控制台栏(这个地方我不知道官方的说法是啥)出现了Server这个栏目。若是咱们曾使用过Tomcat的话,会在这里看到Tomcat服务选项。 github
这里虽没有直接显示Cloud Foundry Server的影子,并不表明安装错误,而是咱们没有新建!在Server选项框的“内容区”右键-->New -->Server,在弹出的对话框里下拉,回出现VMware,点进去就看到CloudFoundry了,选择它,肯定。这样咱们就创建了Cloud Foundry Server。 web
3)在上一步里调出的Cloud Foundry Server控制面板中,先验证帐户(用户名是你申请时的邮箱,密码是注册时发给您的那几个随机字符---不知道如何修改密码)。验证完成后就能够进入Cloud Foundry Server控制面板了,左上角列出了部署的应用,若是没有,能够直接把应用从Project Explorer拖到这里,根据提示引导,就能够完成部署了。 sql
4)数据库支持:在上面的应用列表框的下面就是DataBase Service,点击这个标题栏的带星的图标就能够创建本身的数据了。但我不知道如何建表,据说是不支持,这样咱们就须要在程序里注册了。 数据库
5)部署应用:当咱们搭建好服务器环境和数据库支持,就能够把咱们的应用部署在CF上了。最简单的方式是把应用用鼠标拖动到CF管理窗体中的Applications窗口中 api
6)调试应用:以上只是对Eclipse插件的简单实用及部署,咱们的应用在部署的时候极可能不成功,最好的解决方法应该是查看系统日志。查看部署应用文件列表的方法:Window-->Show View-->Remote Systems-->Remote Systems,这样咱们就在Eclipse右侧会看到咱们Remote Systems窗口,在这里咱们就能够检查CF端部署的应用了。这个窗口是文件列表的形式,咱们一步步双击,就能耐心点到咱们的应用里,在应用名的目录里会有logs 和 tomcat 选项,logs里的内容不全面,建议看tomcat文件里的logs,那里会有更详细的日子记录,调试目标也应该注意针对这里面的。 tomcat
以上就是关于Eclipse插件的使用介绍,也是推动使用的方式。若是你对这个不感兴趣的话,兴许命令行VMC的方式能够给你点参考,命令行相对于Eclipse插件来讲,操做起来功能更多,但不是很方便,它能带给咱们最大的好处就是能够直接使用命令提示行创建数据表,不须要程序去完成了。一样的步骤:下软件,安装,部署,调试……
1)搭建VMC命令环境
下软件:vmc须要Ruby支持,因此须要下载Ruby软件(至关于JDK)。我是Windows用户,因此须要下载安装Windows下面的Ruby安装包(http://www.rubyinstaller.org),下载后安装便可。能够经过Windows开始菜单来访问命令行工具 (All Programs > Ruby <version> > Start Command Prompt with Ruby)。最后,经过下面Ruby命令行更新RubyGems:
....> gem update --system
安装vmc
...> gem install vmc Windows平台
安装完成就能够与Cloud Foundry平台链接了,命令:
prompt$ vmc target api.cloudfoundry.com
登陆平台的命令:
prompt$ vmc login
输入邮箱,根据提示正确输入密码就应该可以登陆成功,若是命令能够,就能够着手部署咱们的应用了。方法是先定位到咱们的应用目录内(如kafeting这个应用,应先进入应用所在磁盘下,再使用cd命令,如:cd 应用目录路径,就进入应用中了【其实上传的应用是把文件push到服务器tomcat/webapps/ROOT目录里面了】),使用 vmc push 就能够布署咱们的应用(在部署的时候会询问你是否create service...,实际上是数据库服务,根据须要)。
注:第一次安装命令提示输入参数,部署完成后会在应用目录下生成一个manifest.yml文件,这是ruby文件,里面记录了咱们应用的一些部署参数,是为了方便更新应用建立的。若是咱们想从新部署,能够删除此文件。
2)建数据库:若是你的应用须要数据库服务,就须要先下载工具,更加帖子:Cloud Foundry mysql 数据导入里的介绍的方法安装命令步骤以下:
gem install rest-client
gem install eventmachine --pre
gem install caldecott
若是安装以上的提示能安装成功,并使用部署完成后系统会检查,若是检查失败,应用程序在本地是能够运行的:vmc tunnel命令,就说明安装成功,若是没有的话我就不知道了*{*.
使用vmc tunnel命令实现了直接操做数据库的功能,在mysql>命令里就能够建立数据表了。
3)其余vmc的经常使用命令
vmc可使用的命令有:
Getting Started
target [url] Reports current target or sets a new target
login [email] [--email, --passwd Login
info System and account information
Applications
apps List deployed applications
Application Creation
push [appname] Create, push, map, and start a new application
push [appname] --path Push application from specified path
push [appname] --url Set the url for the application
push [appname] --instances <N> Set the expected number <N> of instances
push [appname] --mem M Set the memory reservation for the application
push [appname] --runtime RUNTIME Set the runtime to use for the application
push [appname] --no-start Do not auto-start the application
Application Operations
start <appname> Start the application
stop <appname> Stop the application
restart <appname> Restart the application
delete <appname> Delete the application
rename <appname> <newname> Rename the application
Application Updates
update <appname> [--path] Update the application bits
mem <appname> [memsize] Update the memory reservation for an application
map <appname> <url> Register the application to the url
unmap <appname> <url> Unregister the application from the url
instances <appname> <num|delta> Scale the application instances up or down
Application Information
crashes <appname> List recent application crashes
crashlogs <appname> Display log information for crashed applications
logs <appname> [--all] Display log information for the application
files <appname> [path] [--all] Display directory listing or file download for [path]
stats <appname> Display resource usage for the application
instances <appname> List application instances
Application Environment
env <appname> List application environment variables
env-add <appname> <variable[=]value> Add an environment variable to an application
env-del <appname> <variable> Delete an environment variable to an application
Services
services Lists of services available and provisioned
create-service <service> [--name,--bind] Create a provisioned service
create-service <service> <name> Create a provisioned service and assign it <name>
create-service <service> <name> <app> Create a provisioned service and assign it <name>, and bind to <app>
delete-service [servicename] Delete a provisioned service
bind-service <servicename> <appname> Bind a service to an application
unbind-service <servicename> <appname> Unbind service from the application
clone-services <src-app> <dest-app> Clone service bindings from <src-app> application to <dest-app>
Administration
user Display user account information
passwd Change the password for the current user
logout Logs current user out of the target system
add-user [--email, --passwd] Register a new user (requires admin privileges)
delete-user <user> Delete a user and all apps and services (requires admin privileges)
System
runtimes Display the supported runtimes of the target system
frameworks Display the recognized frameworks of the target system
Misc
aliases List aliases
alias <alias[=]command> reate an alias for a command
unalias <alias> Remove an alias
targets List known targets and associated authorization tokens
Help
help [command] Get general help or help on a specific command
help options Get help on available options
最后特别提醒的是Cloud Foundry提供的数据库用户名和密码的问题。先说说我遇到的状况吧:
我以前部署了2个应用,建立了1个数据库服务,2个应用都绑定在这个数据库服务上。经过jsp页面输出系统环境变量的值(VCAP_SERVICES),比较获得的2个JSON结果,发现结果并不相同。因此咱们在布署时不能拿第一个应用获得的值来设置第二个应用的用户名和密码,这算是个人发现吧。最好的办法是使用自适应方式,JFinal自适应实现方式,能够参考开源系统ChunMengLu / jnode,但要注意使用的JSON包,是普通的仍是FastJSON,2者是有区别的, 我就在这上面耗了很久才明白过来。
自适应的原理就是输出环境安装环境的环境变量信息,若是想知道系统全部的环境变量Key,能够经过方法:
Map<String,String> m = System.getenv();
获取,但对咱们来讲,最有用的仍是VCAP_SERVICES对应的值。
PS:我也曾不止一次尝试使用本地安装的SQLyog去远程访问布署应用的数据库,但没有成功,不知道是我链接参数设置有问题仍是CF自己就不支持,若是支持的话,各有利弊吧~~其余方式如:使用Navicate链接数据库我并无尝试过,若是你感兴趣,能够去尝试一下。
附:社区里一篇提问:Cloud Foundry 怎么链接MYSQL数据库,而后建立数据库和表 里面会有些有用的连接。
最后,预祝您的Cloud Foundry布署之旅愉快~!