Free Apache Tomcat Hosting in the Cloud for Java Applications? It's Called OpenShift!

原文:https://openshift.redhat.com/community/blogs/free-apache-tomcat-hosting-in-the-cloud-for-java-applications-its-called-openshift

If you are a Java developer, you have probably struggled with finding a reliable host for your Tomcat based java projects that doesn’t break the bank. The OpenShift Platform-as-a-Service
is changing the Java hosting game by not only making it easy to deploy Java apps to the cloud, but also making it FREE to get started.

By default, OpenShift offers excellent support for the JBoss application server as well as Jenkins continuous
integration.  Not only that, OpenShift uses Apache Maven as the default build system to allow you to push your code via git,
and watch the build happen on a remote cloud server.

What happens if you want to just use Tomcat for your Java app?  In this blog post I will detail how to install and configure the Tomcat servlet container for deployment on the OpenShift PaaS.

Don’t want to read this article, or maybe you want to follow along?  Check out the video where
I run through these steps.

 

Step 1: Create an OpenShift account

If you don’t already have an OpenShift account, head on over to the website and signup with promo code TOMCAT.  It is completely free and Red
Hat
 gives every user three free Gears on which to run your applications.  At the time of this writing, the combined resources allocated for each user is 1.5 GB of memory and 3 GB of disk space.

 

Step 2: Install the RHC client tools

Note:  If you would rather watch a screencast of this step, check out the following videos where I demo how to install the client tools.

Windows

Linux Ubuntu

Linux Fedora

OSX

The OpenShift client tools are written in a very popular programming language called Ruby.  With OSX 10.6 or later and most Linux distributions, ruby is installed by
default so installing the client tools is a snap.  Simply issue the following command on your terminal application:

 

$ sudo gem install rhc

 

 

Step 3: Create an OpenShift application

Since Tomcat is not an officially support application type on OpenShift, we need to create a DIY application.  What's the DIY application type? Click here to
learn more. The command to do this is:

 

$ rhc app create –a tomcat –t diy-0.1

 

This will create an application named tomcat, as well as, let OpenShift know that we plan to install your own web server.  Luckily, Java is already installed and configured for the DIY application type so we only need to install and configure
the application server.

 

Step 4:  Disable the test Ruby server

The DIY application comes with a Ruby server as an example of how to use the application type.  In order for us to use Tomcat, we need to disable this service.

 

$ cd tomcat/.openshift/action_hooks

 

In this directory, there are several scripts that are executed when you push new code up to your server.  Before we remove the start and stop scripts, lets ensure that we stop the currently running Ruby server.

 

$ rhc app stop –a tomcat

 

Now lets remove the start and stop scripts and replace them with blank files.

 

$ rm start

$ rm stop

$ touch start

$ touch stop

 

Once we have removed these files and replaced them with empty files, we need to commit and push our changes to our OpenShift application.

 

$ git commit –a –m “Replaced start and stop scripts”

$ git push

 

Step 5: SSH into the machine and install Tomcat

OpenShift allows users to SSH into their machine via key based authentication.  In order to find your username, simply run the following command:

 

$ rhc domain show

 

This will display information about all of your currently running applications.  One of the fields provided is the Git URL of your application that should look similar to this:

 

ssh://df4c84505552469c9e163263a01fc00d@tomcat-onpaas.rhcloud.com/~/git/tomcat.git/

 

In this example, my username is df4c84505552469c9e163263a01fc00d and my host name is tomcat-onpaas.rhcloud.com.  At this point we can SSH into the server.

 

$ ssh df4c84505552469c9e163263a01fc00d@tomcat-onpaas.rhcloud.com

 

Step 6: Download and extract the Tomcat server

Once you are logged into the machine, simple change to the application data directory, download tomcat, and extract the contents.

 

$ cd tomcat/data

$ wget http://www.us.apache.org/dist/tomcat/tomcat-7/v7.0.29/bin/apache-tomcat-7.0.29.tar.gz

$ tar zxf apache-tomcat-7.0.29.tar.gz

$ rm apache-tomcat-7.0.29.tar.gz

$ cd apache-tomcat-7.0.29/conf

 

Now that we tomcat downloaded and extracted, we need to modify the server.xml file to specify the ports we want to use as well as the ip address to bind to.  Because OpenShift is a multitenant environment, you will need to use the internal ip address that is
provided to you.  In order to find this address, run the following command:

 

$ env |grep INTERNAL_IP

 

Which should return something similar to this:

OPENSHIFT_INTERNAL_IP=127.6.99.1

We need to modify the server.xml file to respect this ip address as well as change the default ports that some of the services run on.

 

Old Connector:

<Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

 

New Connector:

<Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               address="127.6.99.1”

               redirectPort="15443" />

 

Notice that we added an address tag to this connector.

 

We now need to change the following line for the Catalina Engine:

<Engine name="Catalina" defaultHost="localhost">

to

<Engine name="Catalina" defaultHost="127.6.99.1">

 

We also need to modify the host name section to point to our OpenShift host.

 

<Host name="localhost"  appBase="webapps"

            unpackWARs="true" autoDeploy="true">

to

<Host name="tomcat-yourdomain.rhcloud.com"  appBase="webapps"

            unpackWARs="true" autoDeploy="true">

 

The ports that are configured for others services will not work by default because OpenShift does not allow users to bind to any port below 15000 other than 8080.  Because of this, we need to change the following configuration items:

 

<Server port="8005" shutdown="SHUTDOWN">

to

<Server port="15005" shutdown="SHUTDOWN" address="127.6.99.1”>

 

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

to

<Connector port="15009" protocol="AJP/1.3" redirectPort="8443" address="127.6.99.1”/>

 

Step 7:  Start the Tomcat servlet container

 

$ cd ../bin

$ sh startup.sh && tail -f ../logs/*

 

This should start Tomcat as well as make it accessible to the outside world via port 80.  You are probably asking yourself how it’s available on port 80 when we specifically set it to use 8080.  OpenShift actually has a proxy setup that will pass all traffic
coming to your host via port 80 to a local server you have running on port 8080.  This port is specified in the system environment variable OPENSHIFT_INTERNAL_PORT.

Verify that your tomcat server is running by pointing your browser to your application at tomcat-yourNamespace.rhcloud.com

If you want to use the Tomcat management console, add a user to the tomcat-users.xml file located in the conf directory.  For example add the following role and user to that file deleting what is already there:

 

<role rolename="manager-gui"/>

<user username="tomcat" password="openshift" roles="manager-gui"/>

 

A Call to Action

Are you a Tomcat user and want to make it easier for others to use this servlet container on OpenShift?  We would love to see someone create a GitHub quickstart application that has a preconfigured Tomcat ready to go.  Follow the guide I
created that explains how to create this.  One thing to watch out for is the IP address that we added to the server.xml file.  In the quickstart, you will need to write a script that replaces this value with the users IP address as reported by the OPENSHIFT_INTERNAL_IP
environment variable.  Once you get this created, shoot us an email at openshift@redhat.comand we will send a box of OpenShift goodies your way.

Challenge accepted! and nailed it:  https://github.com/openshift/openshift-tomcat-quickstart

This quickstart makes it super fast and easy to run Tomcat on OpenShift.  It's also in the git repo so deploying your war file is as easy as adding it to webapps/ and running git add/commit/push.  Thanks @lilu

时间: 2024-09-29 16:14:06

Free Apache Tomcat Hosting in the Cloud for Java Applications? It&#39;s Called OpenShift!的相关文章

tomcat7.0部署应用出现org.apache.tomcat.dbcp.dbcp.SQLNestedException

问题描述 Tomcat部署出现这问题,如何解决首先,说明下:这个项目直接用eclipse可以直接运行,数据源用plsql连接可以连接的上其次:不管我将oracle里面.jdcb里面的驱动jar放置在tomcat/lib下,还是不放置,都是这个问题再次:tomcat使用的是7.0严重:Exceptionsendingcontextinitializedeventtolistenerinstanceofclasscom.funo.listener.SpringContextLoaderorg.spr

Linux下jsp环境:apache,tomcat配置

apache|js Linux下jsp开发环境,apache,tomcat服务器配置过程: (特别注明:本文内容均参考于互联网,经过个人实践而总结,若配置中遇到问题请联系我,可能写的时候漏掉了某些地方,感谢网上前辈的经验,希望更多的实践经验得以共享) 1.操作系统 RedHat Linux 9.0 2.所需软件 Apache 2.0.54 下载地址 http://apache.freelamp.com/httpd 下载该文件httpd-2.0.54.tar.gz Tomcat5.5.9 下载地址

Apache+Tomcat实现Web服务(3)

apache|web|web服务 然后,在Connectors部分嵌入如下内容. <ConnectorclassName="org.apache.tomcat.service.PoolTcpConnector"><Parametername="handler"value="org.apache.tomcat.service.connector.Ajp13ConnectionHandler"/><Parameterna

优化apache/tomcat配置

apache|优化 近日不得不越那个代疱地钻研发布和发布系统管理和测试的相关问题.有充分证据表明现得绝大多数的apache/tomcat配置中,apache根本就是摆设,所有的响应负担,包括静态多媒体文件实际上是由tomcat完成,而tomcat实际上是效率相当低的,大约是apache的十分之一.因此,没有达到集成两者的目的:但在优化配置本地基本成功,打算在网上测试服务器实际试行时,却碰到了"martix现象":无可解释的不可重复的异常表现.看来,在tomcat/apache的配合上要

Windows下Apache+Tomcat+MySQL+jsp+php的服务器整合配置经验总结

apache|js|mysql|window|服务器 Windows下Apache+Tomcat+MySQL+jsp+php的服务器整合配置经验总结 1.作者:moonsbird 题目:Windows下Apache+Tomcat+MySQL+jsp+php的服务器整合配置经验总结 时间:2004.8.19 最初发表于西南交通大学锦城驿站 2.本文是作者学习几年来学习jsp/配置服务器环境的经验总结.可以转载,但请注明出处. 开始学习jsp很久了,网上有许多关于jsp整合的例子,但存在着许多问题.

Apache+Tomcat负载均衡问题集锦

之前在windows 环境下搭建了下apache+tomcat负载均衡(不会的可以参考之前的文档,文档对于linux和windows都适用),一帆风顺,没有出现任何问题,今天尝试着在linux下搭建了下,其中遇到几个问题,在这里给大家分享下. linux环境,三个redhat6.5 x86_64,其中192.168.1.2安装apache,192.168.1.3和192.168.1.4安装tomcat,这里不再介绍配置,如果有不会的,可以参考前边的文章. 问题一: SESSIONID随着页面刷新

从Apache Tomcat迁移到WebSphere Application Server Liberty Profile

简介 Apache Tomcat 是一个 HTTP 服务器和 servlet 容器,常用于简单的 Web 应用程序,以及使用不需要完整的 Java EE 服务器的框架的应用程序.然而,用户经常会发现,当对 Apache Tomcat 有更多需求时,其最初的简单性就会变得复杂且不实用. 例如,也许 Apache Tomcat 安装的占用空间会变得太大,因为您需要添加第三方库来提供所需的功能.或者,服务器的启动时间也可能是一个问题,因为对 server.xml 文件的任何配置更改都需要重新启动 Ap

教您快速配置Apache+Tomcat+SSL

运行环境:Windows2003 Server SP4 + J2SDK1.5.0 + Apache2.0.54 + Tomcat5.5.9 准备软件: 1.安装 Apache 2.0.54 2.Tomcat 5.5.14 3.Jk2连接器(mod_jk2.so) 一.配置Apache和tomcat Apache安装在d:/Apache2 下,监听端口 80: Tomcat在D:/Tomcat51 下,监听端口 8080: 两者都以windows 2000服务进行安装. 将mod_jk2.so复制

使用Jersey和Apache Tomcat构建RESTful Web服务

RESTful Web 服务简介 REST 在 2000 年由 Roy Fielding 在博士论 文中提出,他是 HTTP 规范 1.0 和 1.1 版的首席作者之一. REST 中最 重要的概念是资源(resources),使用全球 ID(通常使用 URI)标识.客户端 应用程序使用 HTTP 方法(GET/ POST/ PUT/ DELETE)操作资源或资源集. RESTful Web 服务是使用 HTTP 和 REST 原理实现的 Web 服务.通常,RESTful Web 服务应该定义