教程:使用OpenShift获取夹点

发布于:2021-01-19 09:08:49

0

154

0

java linux openshift php ruby 教程

本文将引导您完成使用OpenShift在云中设置一台、两台、三台新机器所需的简单步骤,最多可设置五台新机器。您将部署您的应用程序以进行开发、测试或在几分钟内向全世界展示它们。别再胡闹了。

我们首先概述什么是OpenShift,它来自哪里,以及如何在工作站上设置客户端工具。然后,您将了解应用于OpenShift的客户机工具。几分钟后,您就可以开始专注于应用程序开发,并在OpenShift中部署测试。完成后,你将丢弃你的测试机,继续前进。在这之后,你将完全有能力在你选择的时候,在你需要它的地方,并且在一个时刻通知你的时候,提升到OpenShift云中。这就是开发应该是什么样的,没有堆栈干扰的开发。

现在IT界对云计算有大量的炒作。已经划分出来的各个领域都不乏缩写词,比如IaaS、PaaS和SaaS。OpenShift是Red Hat的平台即服务(PaaS),它为您提供了运行应用程序的平台。作为一名开发人员,您需要查看将应用程序作为所提供服务放置的环境。您不想为服务如何由一组组件构成、如何配置或在何处运行而烦恼。您只需要利用他们提供的服务来部署、开发、测试和运行您的应用程序。在这个基本级别上,OpenShift为Java应用程序提供了一个平台。

首先让我们快速了解一下OpenShift的来源。它起源于一家名为Makara的公司,总部位于加州红木市,提供解决方案,使企业能够在私有云或公共云上部署、管理、监控和扩展其应用程序。Red Hat于2010年11月收购了Makara,次年他们将Red Hat technologies合并到一个名为OpenShift的新项目中。

就在最近,OpenShift团队宣布了他们的开源项目OpenShift Origin的发布,使得整个代码库可以在线使用。您甚至可以使用他们提供的liveCD来体验一下,但这超出了本文的范围。对于Java开发人员来说,这种技术的融合之所以有趣,是因为Red Hat在OpenShift中包含了基于JBoss AS 7的下一代应用程序平台。这为您的所有开发需求带来了一个闪电般快速的应用程序平台。

OpenShift

OpenShift网站声明,“OpenShift是一个免费的、基于云的应用程序平台,用于Java、Perl、PHP、Python和Ruby应用程序。你的开发环境也是你的部署环境,这非常简单:而且你在云中。”这激起了人们的兴趣,所以让我们试试看我们是否可以将我们的web应用程序提升到云中。为此,我们有一个jBPM迁移web应用程序,我们将在本练习的其余部分使用它作为运行示例。

OpenShift的入门在网站上有很好的文档记录,可以作为一个快速入门,一旦你注册了一个redhatcloud(rhcloud)帐户,就可以使用它。这个快速入门为我们提供了使我们的应用程序联机所需的四个步骤,并从安装必要的客户机工具开始。这是为Red Hat Enterprise Linux(RHEL)、Fedora Linux、通用Linux发行版、Mac OS X和Windows概述的。对于RHEL和Fedora来说,它是一个简单的软件包安装,其余的是一个基于Ruby的gem安装,我们将留给读者应用到他们的系统中。

一旦安装了客户端工具,就会有几种基于rhc- <command>形式的命令。有可用的在线界面,但是大多数开发人员更喜欢命令行客户端工具提供的控件,因此我们将使用它们。以下是对可用内容的概述,并简要介绍了每种内容。

  • rhc create domain–用于将注册的rhcloud用户绑定到rhcloud中的域。每个注册的rhcloud用户最多可以有一个域。

  • rhc create app–用于为给定的rhcloud用户、给定的开发环境(Java、Ruby、Python、Perl、PHP)和给定的rhcloud域创建应用程序。您最多可以为给定域创建五个应用程序。这将为您的rhcloud实例生成完整的URI,根据所选环境设置rhcloud实例,默认情况下,将为所选开发环境创建本地git项目。

  • rhc-snapshot–用于创建给定rhcloud实例的本地备份。

  • rhc-ctl-app–用于控制给定rhcloud应用程序。您可以在这里添加数据库、检查实例的状态、启动、停止等。

  • rhc tail files–用于连接到rhcloud应用程序日志文件并将其转储到命令shell。

  • rhc user info–用于查看给定的rhcloud用户,定义的域和创建的应用程序。

  • rhc chk–用于对安装程序运行简单的配置检查。

创建您的网域

为了开始使用我们的演示应用程序,我们需要做一些简单的事情来获得一个OpenShift实例设置,以托管我们的Java应用程序,从一个域开始。

# We need to create the domain for OpenShift to start setting up # our URL with the client tooling using # rhc-create-domain -n domainname -l rhlogin # $ rhc-create-domain –help
Usage: /usr/bin/rhc-create-domain Bind a registered rhcloud user to a domain in rhcloud.
NOTE: to change ssh key, please alter your ~/.ssh/libra_id_rsa and
~/.ssh/libra_id_rsa.pub key, then re-run with –alter
-n|–namespace namespace Namespace for your application(s) (alphanumeric – max 16 chars) (required) -l|–rhlogin rhlogin Red Hat login (RHN or OpenShift login with OpenShift access) (required) -p|–password password RHLogin password (optional, will prompt) -a|–alter Alter namespace (will change urls) and/or ssh key -d|–debug Print Debug info -h|–help Show Usage info
# So we setup one for our Java application. Note that we already have # setup my ssh keys for OpenShift, if you have not yet done that, # then it will walk you through it.
$ rhc-create-domain -n inthe -l [rhcloud-user] -p [mypassword]
OpenShift key found at /home/[homedir]/.ssh/libra_id_rsa. Reusing…
Contacting https://openshift.redhat.com
Creation successful
You may now create an application. Please make note of your local config file in /home/[homedir]/.openshift which has been created and populated for you.

创建应用程序

接下来我们要创建我们的应用程序,这意味着我们要告诉OpenShift我们需要哪个堆栈。这是通过rhc创建应用程序客户端工具完成的。

# Let’s take a look at the options available before we setup a Java # instance for our application.
$ rhc-create-app –help
Contacting https://openshift.redhat.com to obtain list of cartridges… (please excuse the delay)
Usage: /usr/bin/rhc-create-app Create an OpenShift app.
-a|–app application Application name (alphanumeric – max 16 chars) (required) -t|–type type Type of app to create (perl-5.10, jbossas-7.0, wsgi-3.2, rack-1.1, php-5.3) (require) -l|–rhlogin rhlogin Red Hat login (RHN or OpenShift login) (Default: xxxxxxxxx) -p|–password password RHLogin password (optional, will prompt) -r|–repo path Git Repo path (defaults to ./$app_name) -n|–nogit Only create remote space, don’t pull it locally -d|–debug Print Debug info -h|–help Show Usage info
# It seems we can choose between several but we want the jboss-as7.0 # stack (called a cartridge). Provide a user, password and location # for the git repo to be created called ‘jbpmmigration’, see the # documentation for the defaults. Let’s watch the magic happen!
$ rhc-create-app -a jbpmmigration -t jbossas-7.0 -l [rhcloud-user] -p [mypassword] -r /home/[homedir]/git-projects/jbpmmigration
Found a bug? Post to the forum and we’ll get right on it.
IRC: #openshift on freenode
Forums: https://www.redhat.com/openshift/forums
Attempting to create remote application space: jbpmmigration Contacting https://openshift.redhat.com API version: 1.1.1 Broker version: 1.1.1
RESULT: Successfully created application: jbpmmigration
Checking ~/.ssh/config Contacting https://openshift.redhat.com Found rhcloud.com in ~/.ssh/config… No need to adjust Now your new domain name is being propagated worldwide (this might take a minute)… Pulling new repo down Warning: Permanently added ‘jbpmmigration-inthe.rhcloud.com,50.17.167.44′ (RSA) to the list of known hosts. Confirming application jbpmmigration is available
Attempt # 1 Success! Your application is now published here:
http://jbpmmigration-inthe.rhcloud.com/
The remote repository is located here: ssh://1806d6b78bb844d49378874f222f4403@jbpmmigration-inthe.rhcloud.com/~/git/jbpmmigration.git/

要对应用程序进行更改,请提交jbpmmigration/。然后运行“git push”更新OpenShift空间。

如果我们查看我给定的repo路径,就会发现git projects/jbpmmigration git存储库。请注意,如果决定更改域名,则必须调整git repository配置文件以反映远程存储库的位置,请参见上面带有“ssh:……”的行。此外,该页面已处于活动状态http://jbpmmigration-ishereon.rhcloud.com/. 这只是一个启动屏幕,让您开始,所以现在我们继续部署我们现有的jBPM迁移项目。

首先让我们看看git项目中提供的README,它提供了一些关于存储库布局的见解。

Repo layout
deployments/ – location for built wars (Details below) src/ – maven src structure pom.xml – maven build file .openshift/ – location for openshift specific files .openshift/config/ – location for configuration files such as standalone.xml (used to modify jboss config such as datasources) ../data – For persistent data (also in env var OPENSHIFT_DATA_DIR) .openshift/action_hooks/build – Script that gets run every push, just prior to starting your app

在本文中,我们将只研究部署和src目录。你只需输入你的战争文件,删除pom.xml文件文件在项目的根目录中,它们将被自动部署。如果要部署分解的WAR文件,只需添加一个名为“.dodeploy”的文件,如自述文件中所述。对于实际的项目开发,我们希望通过普通的src目录结构推动我们的代码,这也可以通过使用提供的pom.xml文件文件。提供的自述文件提供了启动所需的所有详细信息。

我们的演示应用程序jbpmmigration还附带了一个自述文件,该文件提供了将项目内容添加到新git存储库的说明,因此我们将运行这些命令将文件拉入本地项目。

# placing our application into our Openshift git repo. # $ cd jbpmmigration $ git remote add upstream -m master git://github.com/eschabell/openshift-jbpmmigration.git $ git pull -s recursive -X theirs upstream master # now we need to push the content. # $ git push origin
[jbpmmigration maven build log output removed]
remote: [INFO] ———————————————————————— remote: [INFO] BUILD SUCCESS remote: [INFO] ———————————————————————— remote: [INFO] Total time: 3.114s remote: [INFO] Finished at: Mon Nov 14 10:26:57 EST 2011 remote: [INFO] Final Memory: 5M/141M remote: [INFO] ———————————————————————— remote: ~/git/jbpmmigration.git remote: Running .openshift/action_hooks/build remote: Running .openshift/action_hooks/deploy remote: Starting application… remote: Done remote: Running .openshift/action_hooks/post_deploy To ssh://1806d6b78bb844d49378874f222f4403@jbpmmigration-inthe.rhcloud.com/~/git/jbpmmigration.git/410a1c9..7ea0003 master -> master

如您所见,我们现在已经将内容推送到我们创建的rhcloud实例,它部署了内容并启动了我们的实例。现在我们应该可以在网上找到我们的申请http://jbpmmigration-in.rhcloud.com/jbpmmigrationu upload-0.2。

最后一步是您完成了对这个应用程序的工作,并希望将它释放出来以供新的应用程序使用。然后可以使用rhc snapshot>;client工具进行备份,然后使用rhc ctl app client工具删除实例。

# Ready to get rid of our application now. # $ rhc-ctl-app -a jbpmmigration -l eschabell -c destroy
Password: ********
Contacting https://openshift.redhat.com !!!! WARNING !!!! WARNING !!!! WARNING !!!! You are about to destroy the jbpmmigration application.
This is NOT reversible, all remote data for this application will be removed. Do you want to destroy this application (y/n): y
Contacting https://openshift.redhat.com API version: 1.1.1 Broker version: 1.1.1
RESULT: Successfully destroyed application: jbpmmigration

结论

如您所见,在应用程序开发中使用五个免费实例非常容易。

这就完成了我们的OpenShift项目之旅,我们为您提供了一个机会,等待您和您的应用程序一瞥。创建您的域、定义您的应用程序需求并将您的项目导入所提供的git项目是轻而易举的事。将更改推送到新实例之后,您就可以在云中测试应用程序开发了。这是真的。这很简单。现在,走出去,把你的代码提高到云端宣传之上。