Monday, April 4, 2022

Module 7: Jenkins Setup

 

Jenkins setup - Install Java, Jenkins, Maven, Tomcat on Ubuntu EC2 - How to install Java, Jenkins, Maven, Tomcat on Ubuntu 20.04 EC2

Please follow steps to install Java, Jenkins, Maven, Tomcat on Ubuntu EC2. Jenkins is a java based application, so you need to install Java first. 

Java Setup on Ubuntu

sudo apt-get update

Install Java 11

sudo apt install openjdk-11-jdk


Now lets do Jenkins installation

Jenkins Setup

Add Repository key to the system

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null

Append debian package repo address to the system

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null


sudo apt-get update
Install Jenkins
sudo apt-get install jenkins -y



The above screenshot should confirm that Jenkins is successfully installed.

Access Jenkins in web browser

Now Go to AWS console.
  Click on EC2, click on running instances link. Select the checkbox of EC2 you are installing Java and Jenkins.

  Click on Action.
  Copy the value from step 4 that says --> Connect to your instance using its Public DNS


Now go to browser. enter public dns name or public IP address with port no 8080.This is how to select public DNS name:


Unlock Jenkins
You may get screen, enter the below command in Git bash( Ubuntu console)
Get the password from the below file

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Copy the password and paste in the browser

Click on install suggested plug-ins.
Also create user name and password.
enter everything as admin. at least user name as admin password as admin
Click on Save and Finish. Click on Start to Use.

Maven
Maven is a build tool used for building Java applications. Please click here to learn more about Maven. You can install Maven by executing below command:

sudo apt install maven -y

you can type mvn --version
you should see the below output.


Tomcat Installation

Tomcat is a web server or web container where java web application can be deployed by developers. You can learn more about by clicking this URL.  Tomcat can be installed by executing below commands:

sudo apt-get update
sudo apt-get install tomcat9 -y


sudo apt-get install tomcat9-docs tomcat9-examples tomcat9-admin -y


sudo cp -r /usr/share/tomcat9-admin/* /var/lib/tomcat9/webapps/ -v

Click on this link to know how to make changes using Vi editor.


Change port no from 8080 to 8090
Tomcat default port is also 8080, since we have already used 8080 for Jenkins, we need to change from 8080 to 8090. You can change by modifying server.xml

sudo vi /var/lib/tomcat9/conf/server.xml


you need to scroll down by clicking down arrow button in this file change the port no from 8080 to 8090 at line starting with <Connector port="8080" protocol="HTTP/1.1"

setup an user in tomcat 

sudo vi /var/lib/tomcat9/conf/tomcat-users.xml

Scroll down all the way to the end of the file,
Add the below lines in second last line above (above </tomcat-users>)
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="tomcat" password="password" roles="manager-gui,manager-script"/>

Add more memory to JVM
sudo vi /etc/default/tomcat9

Look for the line starting JAVA_OPTS and comment that line by adding #.
Add the below line:
JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -Djava.awt.headless=true -Xmx512m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC"

sudo systemctl restart tomcat9

sudo systemctl status tomcat9


you may get message that says tomcat is active running.
press q for quitting from that window. Now go to browser, copy public DNS.

 
You should see a page that says.
It works!!!!

No comments:

Post a Comment

Module 34: Understanding Terraform

  Terraform is a platform-agnostic tool that allows you to build, change, and version infrastructure securely and efficiently. Terraform is ...