In
the previous articles we have seen how to deploy a application and configure
Database in OpenShift. By default OpenShift supports JBoss 7.In this article we
will see how we can configure Tomcat in OpenShift.
Since
Tomcat is not an officially support application type on OpenShift, we need to
create a DIY application.
You
can use your own Languages and Data Stores by talking advantage of OpenShift's
powerful Do-It-Yourself (DIY) feature if the built-in Perl, Ruby, PHP, Python,
and Java EE6 support doesn't suit you. OpenShift's DIY allows you run just
about any program that speaks HTTP.
Create a Tomcat
application
[root@vx111a funtest]# rhc app create tomcat diy
Using diy-0.1 (Do-It-Yourself 0.1) for 'diy'
Application Options
-------------------
Domain: fundomain
Cartridges: diy-0.1
Gear Size: default
Scaling: no
Creating application 'tomcat' ... done
Disclaimer: This is an
experimental cartridge that provides a way to try unsupported languages,
frameworks, and middleware on OpenShift.
Waiting for your DNS name to be available ... done
Initialized empty Git repository in /soa/openShift/funtest/tomcat/.git/
The authenticity of host 'tomcat-fundomain.rhcloud.com
(107.21.128.82)' can't be established.
RSA key fingerprint is
cf:ee:77:cb:0e:fc:02:d7:72:7e:ae:80:c0:90:88:a7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added
'tomcat-fundomain.rhcloud.com,107.21.128.82' (RSA) to the list of known hosts.
Your application 'tomcat' is now available.
URL: http://tomcat-fundomain.rhcloud.com/
SSH to:
537f5367500446573b00011e@tomcat-fundomain.rhcloud.com
Git remote:
ssh://537f5367500446573b00011e@tomcat-fundomain.rhcloud.com/~/git/tomcat.git/
Cloned to: /soa/openShift/funtest/tomcat
Run 'rhc show-app tomcat' for more details about your app.
This
will create a application named tomcat and will also inform OpenShift that we
are using DIY type application and will plan to install tomcat on OpenShift.
By
default diy cartridge has a ruby server installed, which can be stop/start
using start and stop scripts. Navigate into the tomcat application in the local
repository,
[root@vx111a funtest]# ll
drwxr-xr-x. 6 root root 4096 May 23 23:56 dbtest
drwxr-xr-x. 6 root root 4096 May 23 22:12 funtest
drwxr-xr-x. 6 root root 4096 May 24 00:57 tomcat
[root@vx111a funtest]# cd tomcat/
[root@vx111a tomcat]# ls
-alrt
drwxr-xr-x. 5 root root 4096 May 24 00:56 ..
-rw-r--r--. 1 root root
169 May 24 00:57 README.md
drwxr-xr-x. 4 root root 4096 May 24 00:57 .openshift
drwxr-xr-x. 2 root root 4096 May 24 00:57 misc
drwxr-xr-x. 2 root root 4096 May 24 00:57 diy
drwxr-xr-x. 6 root root 4096 May 24 00:57 .
drwxr-xr-x. 8 root root 4096 May 24 00:57 .git
[root@vx111a tomcat]# cd .openshift/
[root@vx111a .openshift]# ls -alrt
drwxr-xr-x. 7 root root 4096 May 24 00:57 cron
drwxr-xr-x. 2 root root 4096 May 24 00:57 action_hooks
drwxr-xr-x. 4 root root 4096 May 24 00:57 .
drwxr-xr-x. 6 root root 4096 May 24 00:57 ..
The
action_hooks is the place where the scripts exist.
[root@vx111a .openshift]# cd action_hooks/
[root@vx111a action_hooks]# ls
README.md start stop
To
disable the ruby server Stop the tomcat
[root@vx111a action_hooks]# rhc app stop -a tomcat
RESULT:
tomcat stopped
[root@vx111a action_hooks]# ll
total 12
-rw-r--r--. 1 root root 171 May 24 00:57 README.md
-rwxr-xr-x. 1 root root 280 May 24 00:57 start
-rwxr-xr-x. 1 root root 339 May 24 00:57 stop
Remove
the start and stop files
[root@vx111a action_hooks]# rm start
rm: remove regular file `start'? y
[root@vx111a action_hooks]# rm stop
rm: remove regular file `stop'? y
Now
create the files again and push them to the repository with git
[root@vx111a action_hooks]# touch start
[root@vx111a action_hooks]# touch stop
Commit
the files with Git
[root@vx111a action_hooks]# git commit -a -m "Replaces
start and Stop Scripts"
[master 5c81663] Replaces start and Stop Scripts
Committer: root
<root@vx111a.jas.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are
accurate.
You can suppress this message by setting them explicitly:
git config --global
user.name "Your Name"
git config --global
user.email you@example.com
If the identity used for this commit is wrong, you can fix it
with:
git commit --amend
--author='Your Name <you@example.com>'
2 files changed, 0
insertions(+), 15 deletions(-)
mode change 100755 =>
100644 .openshift/action_hooks/start
mode change 100755 =>
100644 .openshift/action_hooks/stop
[root@vx111a action_hooks]# git push
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 499 bytes, done.
Total 4 (delta 0), reused 0 (delta 0)
remote: Stopping DIY cartridge
remote: CLIENT_RESULT: Application is already stopped
remote: Building git ref 'master', commit 5c81663
remote: Preparing build for deployment
remote: Deployment id is a5448020
remote: Activating deployment
remote: Starting DIY cartridge
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success
To
ssh://537f5367500446573b00011e@tomcat-fundomain.rhcloud.com/~/git/tomcat.git/
f2b1a44..5c81663 master -> master
Now
we disabled the Ruby server that comes by default with DIY application.
Download and
Install Tomcat
Check
the domain and get the details regarding the tomcat application
[root@vx111a action_hooks]# rhc domain show
Domain fundomain (owned by jagadesh.manchala@gmail.com)
-------------------------------------------------------
Created: May 22 5:19 PM
ID: 537de4445973ca6cf70000b2
Allowed Gear Sizes:
small
tomcat @
http://tomcat-fundomain.rhcloud.com/ (uuid: 537f5367500446573b00011e)
------------------------------------------------------------------------------
Domain: fundomain
Created: May 23
7:25 PM
Gears: 1 (defaults to small)
Git URL: ssh://537f5367500446573b00011e@tomcat- fundomain.rhcloud.com/~/git/tomcat.git/
SSH:
537f5367500446573b00011e@tomcat-fundomain.rhcloud.com
Deployment: auto (on
git push)
diy-0.1
(Do-It-Yourself 0.1)
----------------------------
Gears: 1 small
Ssh
to the tomcat application and navigate to OPENSHIFT_DATA_DIR location
cd $OPENSHIFT_DATA_DIR
wget
http://apache.mesi.com.ar/tomcat/tomcat-7/v7.0.53/bin/apache-tomcat-7.0.53.tar.gz
tar zvf apache-tomcat-7.0.53.tar.gz
tar xvf apache-tomcat-7.0.53.tar.gz
cd apache-tomcat-7.0.3
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
if
this does not give any IP address , we can use /sbin/ifconfig by which we can
get the IP address
Now
make these changes to the server.xml ,
Change
the Server shutdown port : <Server port="15005" shutdown="SHUTDOWN">
Add
the IP address obtained to the HTTP Connector
<Connector port="8080"
protocol="HTTP/1.1" address="10.171.23.252"
connectionTimeout="20000"
redirectPort="8443"
/>
Change
the AJP port value too
<Connector port="15009"
protocol="AJP/1.3" redirectPort="8443" />
Change
the address for the default host name
<Engine name="Catalina"
defaultHost="10.171.23.252">
Change
the address in Host name too
<Host name="10.171.23.252"
appBase="webapps"
unpackWARs="true"
autoDeploy="true">
Save the File once changes are done.
Now
we need to make changes to the tomcat-user.xml file so that we can enable some
users for logging into the tomcat console.
Add
these lines to the tomcat-user.xml file
<role
rolename="manager-gui"/>
<user
username="tomcat" password="tomcat"
roles="manager-gui"/>
Save
the file
Start the tomcat
cd
bin
sh
startup.sh
[tomcat-fundomain.rhcloud.com bin]\> sh ./startup.sh
Using CATALINA_BASE:
/var/lib/openshift/537f5367500446573b00011e/app-root/data/apache-tomcat-7.0.53
Using CATALINA_HOME:
/var/lib/openshift/537f5367500446573b00011e/app-root/data/apache-tomcat-7.0.53
Using CATALINA_TMPDIR:
/var/lib/openshift/537f5367500446573b00011e/app-root/data/apache-tomcat-7.0.53/temp
Using JRE_HOME:
/usr
Using CLASSPATH:
/var/lib/openshift/537f5367500446573b00011e/app-root/data/apache-tomcat-7.0.53/bin/bootstrap.jar:/var/lib/openshift/537f5367500446573b00011e/app-root/data/apache-tomcat-7.0.53/bin/tomcat-juli.jar
Tomcat started.
Once
we start the tomcat ,we can access it using the
http://tomcat-fundomain.rhcloud.com/manager/html
More
to come , Happy Learning :-)
No comments:
Post a Comment