Author Archive

How to achieve high availability on Openshift ?

Hi,

High availability is a very important feature for any kind of infrastructure. As the name suggests the services should be available at any given point of time. You can have several parallel instance of an application and can scale up and down depending on the business requirement, without worrying much about the cost. Load is distributed across different servers, and even if one or more of the servers fails, the application is still accessible via the other application instances. HA is crucial for scalable enterprise applications, as you can improve performance by adding more gears (which will be replica of your current one).

Lets create a scaled application and see how High Availability works in Openshift. Follow Below steps :

Step-1: Create a new application. Please note that we are using “-s” here to enable scaling:

$ rhc app create -a myhaproxy -t jbossas-7 -s

Above will create a directory “myhaproxy” at the location from where you ran the command from your terminal.

Now there are two types of scaling : Automatic and Manual. The command mentioned in Step-1 creates an application which is auto-scalable, i.e. the application will be scaled based on the incoming load. However you can also scale your application manually. For eg: if you are anticipating a certain amount of load, or you have limited resources (less number of gears available), or if you want to control the cost manually.

Lets see how can we scale our application manually.

Step-2 : Navigate from the directory “myhaproxy” which got created in Step-1 to :

$ cd myhaproxy/.openshift/markers/

Step-3 : Create a blank file as “disable_auto_scaling” :

$ touch disable_auto_scaling

Step-4 : Now add the changes to git repository, commit the changes and push them to Openshift server :

..

$ cd ../../

$ git add .openshift/markers/disable_auto_scaling

$ git commit -m "disabling auto-scaling"

$ git push

..

Step-3 : Once the auto-scaling is disabled, lets enable manual scaling :

Create an SSH connection to your application :

$ssh UUID@APPNAME-NAMESPACE.rhcloud.com

for eg :

ssh 123a456c09d12345b123a12345cc1234@myhaproxy-mydomain.rhcloud.com

Step-4 : Run below command to enable manual scaling :

$ add gear -a APPNAME -u UUID -n NAMESPACE

for eg :

..

add-gear -a myhaproxy -u 123a456c09d12345b123a12345cc1234 -n mydomain

..

Now manual scaling is enabled. Let’s check if High Availability works. Try to access the application using the url :

myhaproxy-mydomain.rhcloud.com, this gives the welcome page.

Now again ssh to your application using :

ssh 123a456c09d12345b123a12345cc1234@myhaproxy-mydomain.rhcloud.com

Grep for the java process and kill the process id, now our JBoss server is down. If high availability is working, the url should still work.

myhaproxy-mydomain.rhcloud.com, if this gives the welcome page, we are good :). (Preferably try from a different browser)

You can see high availability statistics from the management console, by logging in to

You can also select minimum or maximum number of gears you want to scale up to.

Regards,
Middlewaremagic Team 🙂


Scheduling timed jobs using cron on Openshift

Hi,

Cron is UNIX/Linux service or daemon to execute scheduled commands according to instruction in a file. It uses a daemon, crond, which runs constantly in the background and checks every minute/ hour/ day/ week/ month or an year (based on the configuration) to see if any of the scheduled jobs need to be executed; if so, it executes them. These jobs are generally referred to as cron jobs.

You can use the OpenShift Enterprise cron scheduler to set up timed jobs for your applications. This would need a running Openshift application, a cron cartridge (cron-1.4) and a cronjob script.

Follow Below steps to configure a cronjob:

Step-1: Create a new application:

$ rhc app create -a crontestapp -t php-5.3

Above will create a directory “crontestapp” at the location from where you ran the command from your terminal.

Step-2 : Add the cron scheduler cartridge to your new application, to configure the cronjobs :

rhc app cartridge add -a crontestapp -c cron-1.4

Step-3 : Add the cron jobs to your application depending on whether you want to execute them minutely, hourly, daily, weekly or monthly. for this navigate to :

${Your Project dir}/crontestapp/.openshift/cron/{minutely,hourly,weekly,daily,monthly}/

For example try below script:

..
#!/bin/bash
#This is a test cron script
#Author : Nikhil Mone
(echo ========== Hostname ========= ; hostname ; echo ========== Date ========== ; date ; echo ========== Grep PHP procs ========= ; ps -ef | grep php ; echo =========================) > $OPENSHIFT_REPO_DIR/php/foo.txt &
..

Step-4 : Now commit your changes and push them to the remote repository.

$ git add .openshift/cron/

$ git commit -m “configuring my test cron jobs”

$ git push

The script will write the output to the file foo.txt every minute. Now try to access your application from the browser and append “/foo.txt”

for eg :

http://crontestapp-mydomain.rhcloud.com/foo.txt

You can also use curl to verify the operation of this script:

..
$ curl http://crontestapp-mydomain.rhcloud.com/foo.txt

========== Hostname =========
ex-std-node69.prod.rhcloud.com
========== Date ==========
Sat Jan 12 13:55:04 EST 2013
========== Grep PHP procs =========
1269     27627     1  0 11:53 ?        00:00:02 /usr/sbin/httpd -C Include /var/lib/openshift/642c790205d04d7db91a368c5cbf04c2//php-5.3/conf.d/*.conf -f /usr/libexec/openshift/cartridges/php-5.3/info/configuration/etc/conf/httpd_nolog.conf -k start
1269     27629 27627  0 11:53 ?        00:00:00 /usr/sbin/rotatelogs /var/lib/openshift/642c790205d04d7db91a368c5cbf04c2/php-5.3/logs/error_log-%Y%m%d-%H%M%S-%Z 86400
1269     27630 27627  0 11:53 ?        00:00:00 /usr/sbin/rotatelogs /var/lib/openshift/642c790205d04d7db91a368c5cbf04c2/php-5.3/logs/access_log-%Y%m%d-%H%M%S-%Z 86400
1269     27652 27627  0 11:53 ?        00:00:00 /usr/sbin/httpd -C Include /var/lib/openshift/642c790205d04d7db91a368c5cbf04c2//php-5.3/conf.d/*.conf -f /usr/libexec/openshift/cartridges/php-5.3/info/configuration/etc/conf/httpd_nolog.conf -k start
1269     28774 28765  0 13:55 ?        00:00:00 grep php
=========================
..

The scripts that we put inside cron subdirectories get executed according to their frequencies and in alphabetical order. One need to make sure if you are using interdependent crons then the script names should be in alphabetical order.

You can use the below command to enable or disable your cron scripts. For example, to disable all of your scripts:

$ rhc app cartridge stop -a crontestapp -c cron-1.4

To enable all of your scripts:

$ rhc app cartridge start -a crontestapp -c cron-1.4

Note : The cron commands affect all cron jobs. You cannot disable or enable individual cron jobs.

Regards,
Middlewaremagic Team 🙂


Application Monitoring using MongoDB Monitoring Service (MMS) on Openshift

Hi,

In this article we will discuss about monitoring the appliation which are deployed over Openshift. We will use MongoDB Monitoring Service (MMS) to achieve this. Application monitoring is very important for developers before and after deploying the applications in production, let that be performance measurement, some tuning or random health checks.

The MongoDB Monitoring Service (MMS) is a cloud-based monitoring service, designed by 10gen, to monitor the health of MongoDB deployments. MMS provides an agent that runs on MongoDB servers, and this agent reports information such as opcounters, memory information, number of connections, network I/O, database storage size, and more. All of this information is available in customizable charts that are displayed in your web browser.

Openshift provides us a cartridge that can be used for monitoring the MongoDB apps. Ofcourse you would need to add a MongoDB cartridge as well, but this doesn’t mean that you can not use any other databse. 🙂

I tried a sample app that uses mysql database and I was still able to get the monitoring set up for that. 🙂

Below are the steps that you need to follow to have MMS setup :

Step-1: Create a test application (in this example a java app) :

$ rhc app create -a monitoringDemo -t jbossas-7

Step-2 : Add MongoDB cartridge to above application :

$ rhc app cartridge add -a monitoringDemo -c mongodb-2.0

Step-3 : Login to https://mms.10gen.com and create an account.

Step-4 : Once done download the mms agent by clicking on “download the agent” link on the Hosts page. Extract the zip file, you will get a dir as “mms-agent”.

Step-5 : Open a terminal and navigate to your project directory, from where you executed Step-1.

Step-6 : You will see a directory created as “monitoringDemo”, move upto “.openshift” inside it :

..
[userone@userone monitoringDemo]$ ls -ltra
total 44
-rw-rw-r--.  1 userone userone    7 Jul 25 18:58 .gitignore
drwxrwxr-x.  3 userone userone 4096 Jul 25 18:58 src
-rw-rw-r--.  1 userone userone 1695 Jul 25 18:58 pom.xml
-rw-rw-r--.  1 userone userone   56 Jul 25 19:01 README.md
-rwxrwxr-x.  1 userone userone    0 Jul 25 19:09 .gitkeep
-rwxrwxr-x.  1 userone userone    0 Jul 25 19:09 mysql-connector-java-5.1.13-bin.jar.dodeploy
-rw-rw-r--.  1 userone userone 7629 Jul 25 19:09 README
drwxrwxr-x.  4 userone userone 4096 Jul 25 19:10 deployments
drwxr-xr-x.  6 userone userone 4096 Jul 25 19:10 .
drwxrwxrwx. 24 userone userone 4096 Aug  2 19:41 ..
drwxrwxr-x.  7 userone userone 4096 Aug  7 14:54 .openshift
drwxrwxr-x.  8 userone userone 4096 Aug  7 14:56 .git
[userone@userone monitoringDemo]$ pwd
/myProjDir/monitoringDemo
[userone@userone monitoringDemo]$ cd .openshift/
..

Step-7 : Create a new directory as “mms” :

..
[userone@userone .openshift]$ mkdir mms
[userone@userone .openshift]$ ls -ltra
total 28
drwxrwxr-x. 7 userone userone 4096 Jul 25 18:58 cron
drwxrwxr-x. 3 userone userone 4096 Jul 25 18:58 config
drwxrwxr-x. 2 userone userone 4096 Jul 25 18:58 action_hooks
drwxrwxr-x. 2 userone userone 4096 Jul 25 18:58 markers
drwxr-xr-x. 6 userone userone 4096 Jul 25 19:10 ..
drwxrwxr-x. 7 userone userone 4096 Aug  7 14:54 .
drwxrwxr-x. 2 userone userone 4096 Aug  7 14:55 mms
[userone@userone monitoringDemo]$ pwd
/myProjDir/monitoringDemo/.openshift
..

Step-8 : After step-4 you would have got a directory as “mms-agent” navigate inside it and copy “settings.py” file to “/myProjDir/monitoringDemo/.openshift/mms”

Note : Make sure you do that, or else MMS won’t work.

Step-9 : Navigate back to project directory add the changes to git repo, commit those changes and then push:

$ cd /myProjDir/monitoringDemo/

$ git add .openshift/mms/

$ git commit -a -m “some commit message”

$ git push

Step-10 : Now add the MMS agent cartridge to your application :

$ rhc app cartridge add -a monitoringDemo -c 10gen-mms-agent-0.1

Phewww setup is almost done, now lets make it work 🙂

Step-11 : ssh to your application :

$ ssh UUID@applicationname-namespace.rhcloud.com

for eg :

ssh 90497856323c4122a11602485445c7b2@monitoringDemo-userone.rhcloud.com

and run below command :

..
$ echo $OPENSHIFT_NOSQL_DB_URL
mongodb://admin:ABCD8YrgQth2@10.10.10.10:27017/
..

here:

* admin = MongoDB username
* ABCD8YrgQth = password
* 10.10.10.10 = IP address of your MongoDB host/node

Step-12 : Navigate to https://mms.10gen.com and click the Hosts + button at the top of the page and add all the details from the output of Step-11.

Step-13 : Click the name of the host that you want to monitor to view the available data collection streams. First time it will take some time as it needs to schedule the checks.

This is not over yet, you can also configure multiple alerts and can can customize your view according to your requirement. Pretty simple,easy, open-source monitoring 🙂

Regards,
Middlewaremagic Team


Copyright © 2010-2012 Middleware Magic. All rights reserved. |