Liferay on AWS

Deploying Liferay on AWS Elastic Beanstalk, Configuring RDS for database,
S3 for data folder and Scaling Liferay using Load Balancer on Cloud

Pre-requisites: 

Creating EBs Instance
  • Create New Application
Click on AWS Home (Yellow box at top left corner of page) and navigate to Elastic Beanstalk service. 
Click “Create New Application” to create your application. Provide necessary info required e.g. shown below

  • Configure Environment Type
Configure Environment Type as applicable for your application, In below case we are using Web Server, Tomcat 7 with Java 6 on 64 bit Linux machine.
Select Environment Type as Load balancing, auto scaling (utilize the feature of AWS as we want our application to scale up / down depending on load balancer configuration).

  •    Select Application
Since we are doing initial setup of Elastic Beanstalk instance we will select sample application for first time and click continue.
(You can upload your application here but we still need to configure our application war and also complete the setup / configure environment) so we select sample application initially.

  • Configure Environment
Provide Environment Information for your application. E.g. Env you are creating could be Development Env, QA Env, Prod Env, etc.  
  • Create RDS DB
Select check box to “Create RDS DB Instance with this environment” to create database associated with this env

  • Configure EBS Instance
Configure your Instance, Instance type micro are cheap but it depends on application whether it can run on Micro (Micro instances will be slow if application is heavy). In our E.g. we will use m1.large, EC2 Key pair (Created under Network & Security to access EC2 instance). Provide other necessary details (self-explanatory)
  • RDS Configuration
Select the Instance class for database instance db.m1.micro should also work (but this also depends on your application)
E.g. we will use db.m1.large and allocate min 5 GB storage, give username & password that will be used to access your DB. Remember the default database name is “ebdb” where all the tables will get created. If you need to configure different database name you would need to create separate RDS instance for database where you can have advance configuration option for your database instance. RDS through EBs has limited config.
Select retention setting as desired and Select the availability as Multiple Availability Zones to have instance availability in other zones if you have configured your application for load balancing similar to your application
  • Review Configurations
As last Review Information to check your configuration is proper and Save to complete environment creation.
The environment setup will begin to create your application instance, database instance and this will take 10-15 mins to complete.


You will see below screen where events will be logged to check the status, Wait for the Health to turn in Green.

  • Configure Container option
Once the environment healths turn to green click on configuration & selects Container Option & update your JVM heap size to avoid pergem out of memory issue.

  • Modify RDS DB instance
From AWS Home Navigate to RDS, select your Instance and right click to Modify configuration. Provide your Parameter Group (E.g. M1 Parameter Group created to have UTF-8 encoding for tables, default parameter is not UTF-8 and Latin which might create issue later for application, so create your Parameter Group with desired encoding and select for db instance before the tables are created) and Security group (where accessibility to instance is maintained through inbound / outbound rules) Ref: Working with Security Group
Select Apply Immediately and Continue.

  • Reboot RDS Instance
It will take few mins to modify your RDS check the status and wait till it says “Pending Reboot” and
Then Right Click your RDS instance to “Reboot” it. 
This step is important as RDS Instance needs to be rebooted before tables are created, Reboot will update your DB instance to have UTF-8 encoding and default to tables created thereafter.

Importance Details for RDS:
You will get the endpoint (host) & port to access your RDS database instance
User name & Password is the one you had configured earlier
DB Name: ebdb

Your Elastic Beanstalk instance (EBS) & RDS instance are ready for use...
  •    Create S3 bucket for storing liferay data folder
From AWS home click on S3 “Create Bucket” provide Bucket Name & Region and click “Create”

Customizing Liferay war that is ready to deploy on AWS EBs instance (Configured to use RDS for database and S3 for liferay data folder)


Approach


Our goal is to deploy Liferay standalone war on tomcat 7 along with dependencies & additional tomcat configuration but without manual following these steps and automate it as our liferay application war needs to be scalable & should be deployable on other EBS instance when the additional instance is automatically up in Load Balancing.

So we will work on customizing liferay war to automate steps through AWS script & overcome issues, below are steps
Before starting go through below links for understanding AWS EBS way of customization the application

1. To start we will create .ebextensions folder which will have your .config file listing the commands it needs to run on EBS instance along with files you need for your application setup.
liferay-*.war is the fresh stand alone war which we will be customizing for it to be ready deploy on AWS EBs

2. Now let’s understand what will be there in the .ebextensions folder
  • ext folder: having all the dependency jar that need to be copied to tomcat7/lib/ext
  • .config: listing your cmds
  • installcmd.sh: having script to install s3cmd on EBS instance this is require for configuring s3
  • .s3cfg: file require for accessing the AWS s3 (this file will have your access_key & security_key) more about .s3cfg & s3cmd
  • catalina.properties, ROOT.xml, server.xml, setenv.sh: These files are copied from liferay-tomcat bundle as we will require to setup tomcat 7
  • portal-ext.properties: file will have properties for pointing liferay home, database config, s3 confg.

3. 01_liferaysetup.config : EBS ebextensions .config file. This file will be read and cmds mentioned will be executed when liferay war is uploaded & getting deployed on tomcat 7

To explain in short for cmd in below file,
  • cp will copy files from .ebextensions/ folder to respective path mentioned below
  • chmod for making the file executable with ec2-user
  • mkdir to create folder at desired path
  • chown to change user ownership with right permission for files & folder
  • /bin/bash ./installcmd.sh for running the shell script to install s3cmd
  • s3cmd -c /home/ec2-user/.s3cfg get -f s3://liferay-data/Deploy/*.war /usr/share/tomcat7/deploy
above s3cmd uses the .s3cfg file having your access credentials to access s3 and s3 bucket location where your wars will be present and
destination folder where you want the files to be copied to from s3. (/usr/share/tomcat7/deploy is default path where the Tomcat7 will be installed in EBs)

4. portal-ext.properties –


  • Make sure liferay home is set correctly which point to stand alone tomcat 7
  • Setup wizard is set false as we don’t want user to see the configuration screen when liferay war will be deployed to other instances when load balancer & scaling is set. (i.e. when liferay war is deployed in new instance it will not find portal-setup-wizard.properties and it will present user with Portal Configuration screen)
  • Set appropriate DB config endpoint with port, credentials for your RDS instance you configured above
  • Set your access credentials of AWS EC2 for configuring s3 and provide bucket name which will be your liferay-data folder
Once you have correctly configured portal-ext.properties add it to your custom liferay-*.war at respective location /WEB-INF/classes/

5. installcmd.sh : It has executable script that will install s3cmd on EBS instance, this cmd is required to access s3 bucket

6. .s3cfg : you can get this config file for s3 by installing s3cmd where you would be required to input access_key, secret_key
Reference Link : Install s3cmd

Add .ebextensions to Custom Liferay war

By now you are aware of .ebextensions, .config file & files required for setting up liferay.
Add this .ebextensions folder once it’s completely ready for your liferay application & add it to root level of your liferay-*.war as shown below in first image & verify your files are present in./ebextensions folder.

Your custom liferay-*.war is now ready to Deploy on AWS EBs 
  • Upload and Deploy Application

Navigate to your environment and Click on “Upload and Deploy”

Choose your custom liferay war & give Version Label and click “Deploy”. These versions are maintained and you can see them in All Version where you can manage version and deploy specific version on your environment.

Verify your steps for errors
  • Watch the Logs for any error in AWS EBs instance for your environment (logs can also be viewed by click on Snapshot logs)
  • SSH your EBS instance & verify whether your cmd in .config executed properly by browsing the files & folder, permission, etc

AWS References for Advance Setup:

Comments

  1. You queries are welcome | Send suggestions to Improve this blog.

    ReplyDelete

Post a Comment