2014年5月31日星期六

OpenShift_001:部署Java Web应用到OpenShift上

环境:MAC OS X:10.9.3 + OpenShift OnLine

OpenShift是Red Hat的PaaS,其中最小配置可以免费使用。
本文介绍如何部署一个Java Web应用到OpenShift上。

第1步:当然是要注册一个账号:https://www.openshift.com/,过程从略。

第2步:安装OpenShift RHC Client Tools。

1. 检查ruby是否安装了
$ruby -e 'puts "Welcome to Ruby"'
Welcome to Ruby

2. 检查git是否安装了
$ git --version
git version 1.8.5.2 (Apple Git-48)

3. 安装rhc:$ sudo gem install rhc
Password:
===========================================================================

If this is your first time installing the RHC tools, please run 'rhc setup'

===========================================================================
Successfully installed rhc-1.24.4
Parsing documentation for rhc-1.24.4
1 gem installed

4. 设置rhc:$ rhc setup

OpenShift Client Tools (RHC) Setup Wizard

This wizard will help you upload your SSH keys, set your application namespace,
and check that other programs like Git are properly installed.

Login to openshift.redhat.com: maping930883@hotmail.com
Password: ********

OpenShift can create and store a token on disk which allows to you to access the
server without using your password. The key is stored in your home directory and
should be kept secret.  You can delete the key at any time by running 'rhc
logout'.
Generate a token now? (yes|no) yes
Generating an authorization token for this client ... lasts about 1 month

Saving configuration to /Users/maping/.openshift/express.conf ... done

Your public SSH key must be uploaded to the OpenShift server to access code.
Upload now? (yes|no)
yes

Since you do not have any keys associated with your OpenShift account, your new
key will be uploaded as the 'default' key.

Uploading key 'default' ... done

Checking for git ... found git version 1.8.5.2 (Apple Git-48)

Checking common problems .. done

Checking for a domain ... maping930883

Checking for applications ... found 2

  jenkins http://jenkins-maping930883.rhcloud.com/
  php     http://php-maping930883.rhcloud.com/

  You are using 3 of 3 total gears
  The following gear sizes are available to you: small

Your client tools are now configured.

第3步:安装JBoss Devloper Studio 7.1.1 GA。
之所以安装JBDS,是因为这个开发工具,已经包含了JBoss Tools插件。
你也可以使用Eclipse,然后手动安装这个插件。

第4步:打开JBDS,新建应用,选择OpenShift->OpenShift 应用
它会询问你的OpenShift账号等信息。
创建好应用后,就可以发布了。
选择Team->Commit,提交修改。
选择Team->Push to Upstream,推送提交到服务器上。

第5步:访问你的应用。

使用ssh连接到你的应用
(1)rhc ssh -a testopenshift
(2)cd $OPENSHIFT_DATA_DIR
可以使用命令:env,查看都有哪些环境变量。

使用scp拷贝文件
(1)scp setJdk6Env.sh 5386f544e0b8cdfdd00000fb@testopenshift-maping930883.rhcloud.com:~/app-root/data/setJdk6Env.sh
(2)scp 5386f544e0b8cdfdd00000fb@testopenshift-maping930883.rhcloud.com:~/app-root/data/test.sh .

参考文献:
1. https://www.openshift.com/developers/rhc-client-tools-install
2. http://blog.csdn.net/fulinkster/article/details/6692595
3. http://blog.csdn.net/cherry_sun/article/details/7598721
4. http://www.lupaworld.com/article-234801-1.html
5. http://www.oschina.net/translate/how-to-run-apache-tomcat-8-on-openshift
6. http://www.360doc.com/content/13/0505/15/11978685_283129497.shtml
7. http://www.huiwei19.com/free/605.html
8. http://virtual.51cto.com/art/201211/365976.htm
9. https://www.youtube.com/watch?v=4Htd9vAxJAc

没有评论: