Java application deployment setup

Posted By : Ashish Sharma | 30-Aug-2021

Introduction:

This blog will help you to setup a java application on the AWS EC2 Linux server and to automate its build deployment. This blog contains information on how to install java and other tools required to automate the deployment process.

Required tools:

1.Java

2.GIT

3.Jenkins

4.Mysql

5.Tomcat

 

GIT - 

First, we are going to install GIT because it will help us to fetch the code required for deployment. Below is the command to install git on Linux server -
sudo apt install git

After installing git we can clone the repo on that server by using the command described below- 
sudo git clone <repository url>

Now your code base is ready on the server so we can plan to install Jenkins to make the deployment process automated.

 


Java - 
Before installing Jenkins we are required to install Java because Jenkins needs java as its dependency. So we can install java buy using the command -
sudo apt-get install openjdk-8-jdk -y
Here I have installed java 8 but you can install any version of Java above this as per your requirement.

 

Jenkins -
Once java is been installed on the server we can start with Jenkins installation and for that first, we need to add the repository key in our system buy using below command -
sudo wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
This key will help Jenkins to fetch packages and dependencies.

Now we are going to use that key to add the Debian packages required by Jenkins to be added in the sources. list of system by using below command
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

Then we can update the apt packages and make the apt to use the repository we just added by running the basic linux command - sudo apt update, than we can install the Jenkins after setting up the repository for it by using below command - 
sudo apt install Jenkins -y
Here we are using -y (yes) to bypass the question Jenkins asks for permission before installation. This will allow Jenkins to directly get installed without any manual intervention.

 

Mysql - 
Now we are going to install database for the application and here I have used mysql for that purpose but you can select database as per your requirement. Below is the command to install Mysql in linux -
sudo apt install mysql-server

Now the Mysql has been installed but it does not have the necessary security to begin with so we are going to configure its security by applying a security script to it which will help us to get more control over our database. Below is the command to add a security script to the Database -
sudo mysql_secure_installation
By answering the series of questions you can add changes to your MySQL installation’s security.

 

Tomcat -
Atlast we are going to install a tomcat webserver for our java application to host a jar file. Tomcat is easy to setup and install, below is the command to install tomcat on linux server -
sudo apt install tomcat9 tomcat9-admin
I have installed tomcat9 using the above command but you can use other version of tomcat also as per your requirement. To check the other version of tomcat you can use below command before tomcat installation - 
sudo apt-cache search tomcat
This command will show you all the latest package available for download from it's internal repository.

With this all the necessary installation is done for setting up a Java project, but one needs to configure the ports properly as both tomcat and jenkins use 8080 as it's default port. So we need to assign different port to both the application as (8080 for tomcat, 8081 for jenkins).
We should also enable the necessary port on server to establish the connection with all these services like 3306 - mysql, 8080 - tomcat.

Below is the script to install all these service at once - 

 

#!/bin/bash
sudo apt update
sudo apt install git
sudo apt-get install openjdk-8-jdk -y
sudo wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt install jenkins -y
sudo apt install mysql-server
sudo apt install tomcat9 tomcat9-admin

About Author

Author Image
Ashish Sharma

. Ashish is a DevOps Engineer. He holds expertise in Clouds like AWS, IONOS, Digital Ocean and also worked on tools like - Jenkins, Docker, Ansible, GIT, BItbucket, Vagrant, Nagios, Zabbix, His hobbies are playing sports and travelling.

Request for Proposal

Name is required

Comment is required

Sending message..