EC2 Installation with Amazon's Linux AMI - Documentation topics on: amazon,aws,centos,ec2,install,linux,.

EC2 Installation with Amazon's Linux AMI

This document provides instructions and scripts to install dotCMS from Source on Amazon's Linux 2 AMI (based on CentOs) on EC2.

Requirements

These instructions assume use of the following:

  • Server OS: Linux 2
  • AMI: Latest Linux 2 AMI running on Amazon EC2
  • Java: Open JDK 1.8
  • Database: PostgreSQL 9.6
  • dotCMS: Version 5.0.x or higher

Configuration

1. Start up a new Amazon Linux AMI (Amazon Machine Image)

Example: amzn2-ami-hvm-2.0xxxx

2. Choose an Amazon Instance Type with appropriate memory and disk space

 
Memory Size:

  • Recommended Memory: 7.5GB or more.
  • Minimum Memory: 3.75GB
  • For more information on dotCMS memory usage, see the Memory Configuration documentation.

Disk Space:

  • Recommended Disk Space: 20GB or higher for a better testing/development experience.
    • Examples: Amazon m3 instance types with additional storage selected, or Amazon m4 or t2.
  • Minimum Disk Space: 8GB.
    • Note: If using the Amazon m3.medium instance type, additional disk space must be added to reach the 8GB minimum.

3. Place the box in a Security Zone that allows for access to port 22, 80 and 443

4. Connect to the server using ssh.

ssh -i ~/keys/your-key.pem ec2-user@{servers.amazon.public.ip}

Installation

5. Run the following commands (manually or via a script).

 
Note:

  • Several of the below commands require replacement of portions of the command with appropriate text (such as replacing the password 'abc123' when creating the dotcms user in the PostgreSQL database).
    • Make sure you read and understand each command before executing it.
  • These commands assume dotCMS version 5.0.1.
    • If you use a different dotCMS version, update the version numbers and file names (for dotCMS, Tomcat, and other parameters and folders) appropriately.  
       
# Using Amazon's Linux 2 AMI - Sept. 1st, 2018

sudo yum update -y

############################################################
#
# Step one, install Postgres
#
############################################################

# Add the postgres-9.6 to the repo
sudo amazon-linux-extras enable postgresql9.6

# Install postgres server
sudo yum install postgresql-server -y

# Create postgres data dir
sudo /usr/bin/postgresql-setup --initdb

# Create a new pg_hba.conf to allow postgres to use password Auth
echo "local all all peer"             >  ./pg_hba.conf
echo "host  all all 127.0.0.1/32 password" >> ./pg_hba.conf
echo "host  all all ::1/128 ident"    >> ./pg_hba.conf

# Change perms to postgres and move it into place
sudo chown postgres.postgres ./pg_hba.conf
sudo mv ./pg_hba.conf /var/lib/pgsql/data/pg_hba.conf

# Start postgres service
sudo systemctl start postgresql

# Login using psql as user postgres
sudo -u postgres -- psql

# In psql run these db commands
 create database dotcms;
 create user dotcms with PASSWORD 'abc123';
 grant ALL on database dotcms to dotcms;
 \q

# Verify - login as dotcms with your password above
psql -Udotcms -h 127.0.0.1 dotcms

############################################################
#
# Step two, install Java and redirect low ports to tomcat
#
############################################################

# Install Java 8
sudo yum install java-1.8.0-openjdk-headless.x86_64 -y

# Set up routing from low ports to tomcat's 8080/8443 
sudo iptables -t nat -A PREROUTING -p tcp --dport 80  -j REDIRECT --to-ports 8080
sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443


############################################################
#
# Step three, create dotcms user and app dirs (where 5.0.1 is current verion)
#
############################################################

# Setup the dotcms user and app dirs
sudo adduser -d /opt/dotcms dotcms
sudo mkdir -p /opt/dotcms/wwwroot/dotcms_5.0.1
sudo mkdir /opt/dotcms/data
sudo chown -R dotcms.dotcms /opt/dotcms

# sym link current to 5.0.1 directory, makes upgrades easier 
sudo ln -s /opt/dotcms/wwwroot/dotcms_5.0.1 /opt/dotcms/wwwroot/current

# become dotcms user
sudo su dotcms -

cd ~/wwwroot/current

# download dotCMS - versions might vary 
wget https://doc.dotcms.com/physical_downloads/release_builds/dotcms_5.0.1.tar.gz

# untar the download
tar -zxvf dotcms_5.0.1.tar.gz

# Set up the config plugin  - if the tomcat version changes, these paths might as well
mkdir -p plugins/com.dotcms.config/ROOT/dotserver/tomcat-8.5.32/webapps/ROOT/META-INF
cp dotserver/tomcat-8.5.32/webapps/ROOT/META-INF/context.xml plugins/com.dotcms.config/ROOT/dotserver/tomcat-8.5.32/webapps/ROOT/META-INF/

# Update java's max memory
mkdir -p plugins/com.dotcms.config/ROOT/bin
cp bin/startup.sh plugins/com.dotcms.config/ROOT/bin/

# set your java memory, in this case changing 1G to 4G
sed -i 's/Xmx1G/Xmx4G/g' plugins/com.dotcms.config/ROOT/bin/startup.sh


# edit the plugin context.xml for the DB connection pool,
# delete the H2 entry and uncomment the Postgres, replace with the user/pass that was added to postgres
vim plugins/com.dotcms.config/ROOT/dotserver/tomcat-8.5.32/webapps/ROOT/META-INF/context.xml

# Set the assets and dotsecure folders under /opt/dotcms/data
echo "DYNAMIC_CONTENT_PATH=/opt/dotcms/data/dotsecure" >> plugins/com.dotcms.config/conf/dotmarketing-config-ext.properties
echo "ASSET_REAL_PATH=/opt/dotcms/data/assets" >> plugins/com.dotcms.config/conf/dotmarketing-config-ext.properties
echo "TAIL_LOG_LOG_FOLDER=/opt/dotcms/wwwroot/current/dotserver/tomcat-8.5.32/logs" >> plugins/com.dotcms.config/conf/dotmarketing-config-ext.properties

# deploy your repetable config plugin (you should carry this over to new versions when you upgade)
./bin/deploy-plugins.sh

# touch out so you can tail it
touch /opt/dotcms/wwwroot/current/dotserver/tomcat-8.5.32/logs/catalina.out

# run !!
./bin/startup.sh && tail -f dotserver/tomcat-8.5.32/logs/catalina.out


# You should see the ASCII dotCMS logo and the database get pre built
# and the starter site content get imported 

Verification

The server will build the database automatically and show its progress in the log files (this may take five minutes or more).

You will know that the server started up correctly when you see messages similar to the following in the log file:

# Once you see something like this, you should be able to hit your site at its ip.  A
31-Aug-2018 16:37:26.705 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/opt/dotcms/wwwroot/dotcms_5.0.1/dotserver/tomcat-8.5.32/webapps/ROOT] has finished in [219,898] ms