Tuesday, September 21, 2010

How to configure GateIn with Amazon RDS !!

Couple of weeks back JBoss Stormgrind project created an AMI (ami-0cda3165) for GateIn  3.1.0.Final . If you have created an Amazon's EC2 instance from existing AMI before, creating a GateIn EC2 instance is no different. When  an instance is running, you can access the default portal at URL which will look something like http://ec2-75-101-229-18.compute-1.amazonaws.com:8080/portal/ Don't try accessing the URL, it will go to /dev/null ;-) If you ssh into your instance, you can see JBoss+GateIn bundle at /opt/gatein-3.1.0.FINAL. By default, GateIn comes bundled with HSQLDB but normally people have a separate instance of DB such as MySQL running on separate server so here I am going to show you how you can configure Amazon RDS aka MySQL 5.1 with your GateIn instance running in cloud.

1. In AWS management console, search for Gatein or you can directly enter ami-0cda3165. In subsequent window pick your availability zone and select instance type as "Small" which is enough to use GateIn for smaller use case and lighter load. Then select your key-pair, security group. Make sure your security group has port 8080 turned on. Ultimately, the details of instance should look similar to following screenshot:


2. Launch your instance and when AWS console says instance is running, you should be able to access the GateIn's landing page at http://ec2-75-101-229-18.compute-1.amazonaws.com:8080/portal/ This verifies that we have GateIn AMI working properly which is running atop HSQL.

3. Now, let's create a RDS instance. Launch DB instance wizard under Amazon RDS tab, select instance class as small, size 5G,  give a name to your DB instance (this is not the schema name in case you are wondering) e.g. gateinmysql and of course master userid and password. In next window of wizard, give a DB name which is schema name. For availability zone, select the same zone you selected in step 1. This means that both GateIn and DB servers are collocated which will give you a better network QoS. Your configuration should look something like following:
Launch the DB, go get a cup of coffee because it takes a while for Amazon to launch a DB instance. When it's runnig, your DB server name should look like  gateinmysql.ck0mw2jbysdo.us-east-1.rds.amazonaws.com

4.  Now we need to hook 1 & 3 together. For this, let's ssh into the GateIn instance and stop GateIn server. We then modify the file, /opt/gatein-3.1.0.FINAL/server/default/conf/gatein/configuration.properties with the details from screenshot in 3. You can see complete detail of configuring GateIn with MySql at GateIn 3.1 reference guide. 

5. Copy (scp or wget) MySQL jdbc driver to /opt/gatein-3.1.0.FINAL/server/default/lib

6. Delete data, log, tmp, work folders from /opt/gatein-3.1.0.FINAL/server/default so that we have a clean server again.

7. Start GateIn server by doing "bash run.sh -c default -b 0.0.0.0". After couple of minutes depending on how good network connection between GateIn & RDS is, you should be able to see your portal running again at the URL you saw in 2. You can also use mysql-administrator in your laptop/desktop to see the tables and data GateIn created during startup.

Unless you are a zombie, you would not want to repeat this process every time you need to run GateIn with RDS. You should create your own GateIn AMI based on all modifications you have done. The feature I liked about RDS is that you can take a snapshot of database and relaunch again. Amazon preserves the RDS public server name which means that configuration changes that you made on 4 would continue to work.

Please let me know if you run into any problem when you to try to do yourself and I will update this blog accordingly. Happy clouding and portaling.
-----------------
Help me in my mission at http://www.eejot.org

No comments: