Installing and verifying the software stack  

The next step is to remote log into the EC2 instance, and install Apache Tomcat and the MySQL client libraries. We will use the private key file created and downloaded under Creating EC2 Instance Key Pairs in an earlier step.

  • Assign rights to the private key: Copy the private key file to the .ssh folder in your home directory, if for some reason it does not exists then create it and make sure that it has read/write/executable rights assigned for the owner (drwx-----). To log in from your command line, type in the following to assign correct rights to the private key file downloaded earlier. This assigns read/write and execution rights only to the file owner. Unless the rights are changed, it will not be possible to login remotely.  
chmod 700 ~/.ssh/AWSBook2EdKeyPair.pem
  • Remote login: Now, we can login remotely. The default user name for Ubuntu AMI’s is ubuntu, the IP address to connect to is the EIP of the EC2 instance is 34.215.190.229, type Yes when you get a warning that the authenticity of the host 34.215.190.229 can’t be established.
Aurobindos-MacBook-Pro-2:.ssh aurobindosarkar$ ssh -i ~/.ssh/AWSBook2EdKeyPair.pem [email protected]
The authenticity of host '34.215.190.229 (34.215.190.229)' can't be established.
ECDSA key fingerprint is SHA256:GS+9/SSDhI4rI81hEIi14ujeeyMJpMmt49DjCsu+DDU.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '34.215.190.229' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-1022-aws x86_64)

* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.

The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.

To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details.

ubuntu@ip-172-31-18-70:~$
  • Installing software: The next step is to install Apache Tomcat and MySQL client libraries on to the EC2 instance. First update the package repositories and then install the packages.
sudo apt-get update;
sudo apt-get install tomcat7 mysql-client-5.7;
  • Verify Tomcat7 installation: Open any browser and type in http://34.215.190.229:8080 . You will see a default Apache Tomcat page on the browser.
  • Verify MySQL access from EC2 instance: From the EC2 instance command line, type the endpoint (URL) from RDS instance dashboard.
mysql -u a1dbroot -p -h a1ecommerce.cpyfddnufvjm.us-west-2.rds.amazonaws.com -P 3306

When prompted for the password, type in the password you entered while creating the DB instance. At the end of it, you should see a MySQL command prompt.

Repeat the earlier-mentioned step from your development machine. This verifies the DB instance is accessible from both the EC2 instance and your development machine.

Now, we have the DB instance configured, and the Tomcat web server is up and running, all we need to do next is to deploy the a1ecommerce application on EC2 instance. But this needs a minor modification in the configuration file for the code to point to the correct database instance (now on the AWS cloud instead being in of our development machine).

  • Change the database endpoint: Check out the latest version from GitHub, and in the data-access.properties file in src/main/resources/spring folder change the following properties to:
jdbc.url=jdbc:mysql://a1ecommerce.cpyfddnufvjm.us-west-2.rds.amazonaws.com:3306/a1ecommerceDb

jdbc.username=a1dbroot # username of Amazon DB instance
jdbc.password=a1dbroot #Password for the Amazon DB instance

After modifying the data-access.properties file, it is time to build the project and copy the war file to the EC2 instance for deployment. From the root of the project,

mvn package

This will create a1ecommerce.war file in the target folder copy this to the EC2 instance for deployment.

scp -i ~/.ssh/AWSBook2EdKeyPair.pem ./target/a1ecommerce.war [email protected]:~/

This copies the a1ecommerce.war file from the target folder to the home folder of ubuntu in the EC2 instance.

sudo cp a1ecommerce.war /var/lib/tomcat7/webapps

Next, we ssh into the EC2 instance and copy the file to the Tomcat webapps folder. This will deploy the war file to the Apache Tomcat webserver.

At this stage, you have successfully completed deploying a web application on the Amazon cloud. To verify, from the browser, type in the http://34.215.190.229:8080/a1ecommerce, and you should see the A1Electronics ecommerce site up and running.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.82.82