openshift教程_教程:掌握OpenShift

呼延学
2023-12-01

openshift教程

本文将引导您完成使用OpenShift在Cloud中设置一台,两台,三台而不是五台新计算机所需的简单步骤。 您将部署您的应用程序以进行开发,测试或在数分钟之内将它们全面展示给全世界。 没有更多的混乱。

我们首先概述什么是OpenShift,它来自何处以及如何在工作站上获得客户端工具设置。 然后,您将带您了解适用于OpenShift的客户端工具。 几分钟之内,您便可以开始专注于应用程序开发,并在OpenShift中进行部署以对其进行测试。 完成后,您将只丢弃测试机器并继续前进。 此后,您将完全有能力在选择时,需要的地方并立即注意进入OpenShift Cloud。 这就是开发应该的样子,没有堆栈干扰的开发。

现在,在IT世界中,有关云的宣传大肆宣传。 对于IaaS,PaaS和SaaS之类的各个领域,不乏首字母缩写词。 OpenShift是Red Hat的平台即服务(PaaS),它为您提供了运行应用程序的平台。 对于作为开发人员的您来说,您想要查看将应用程序作为仅提供的服务放置的环境。 您无需理会该服务如何由一组组件构造,如何配置或在何处运行。 您只想利用他们提供的此服务来部署,开发,测试和运行您的应用程序。 在此基本级别上,OpenShift为您的Java应用程序提供了一个平台。

首先,让我们快速了解一下OpenShift的来源。 它始于一家总部位于加利福尼亚州红木城的名为Makara的公司,该公司提供的解决方案使组织能够在私有或公共云上部署,管理,监视和扩展其应用程序。 红帽于2010年11月收购了Makara,第二年他们将红帽技术合并到一个名为OpenShift的新项目中。

最近,OpenShift团队宣布启动名为OpenShift Origin的开源项目,从而使整个代码库都可以在线获得。 您甚至可以使用它们提供的liveCD进行试用,但这不在本文讨论范围之内 。 对于Java开发人员来说,使这种技术融合有趣的是,Red Hat 在OpenShift中包含了基于JBoss AS 7的下一代应用程序平台。 这为您的所有开发需求带来了快速的闪电应用平台。

OpenShift

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

OpenShift入门在网站上有很好的记录,可以作为快速入门,一旦您注册了Red Hat Cloud(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应用程序日志文件并将其转储到命令外壳中。
  • 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-create-app客户端工具完成的。

# 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空间。

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

首先,让我们看一下git项目中提供的自述文件,该文件对存储库布局有一些见解。

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目录。 您只需放入WAR文件,在项目根目录中删除pom.xml文件,它们就会被自动部署。 如果要部署爆炸的WAR文件,则只需添加README文件中概述的名为“ .dodeploy”的文件即可。 对于实际的项目开发,我们希望通过普通的src目录结构推送代码,也可以通过使用提供的pom.xml文件来实现。 提供的自述文件提供了开始使用所需的所有详细信息。

我们的演示应用程序jbpmmigration还带有一个README文件,该文件提供了将项目内容添加到我们的新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-inthe.rhcloud.com/jbpmmigration_upload-0.2在线找到我们的应用程序。

然后,最后一步是您已经完成了该应用程序的工作,并希望将其释放给新的应用程序。 然后,您可以使用rhc-snapshot >客户端工具进行备份,然后使用rhc-ctl-app客户端工具删除实例。

# 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项目非常容易。 将更改推送到新实例后,您将关闭并在云中测试应用程序开发。 这是真的。 这很简单。 现在走到那里,将您的代码提升到云炒作之上。

翻译自: https://jaxenter.com/tutorial-getting-to-grips-with-openshift-105161.html

openshift教程

 类似资料: