Showing posts with label lab1. Show all posts
Showing posts with label lab1. Show all posts

Monday, 17 August 2020

How to install Java, Jenkins, Maven, Tomcat on Ubuntu 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

sudo apt update

Install Java Open JDK 8 package

sudo apt-get install default-jdk -y



Once install java, enter the below command


Verify Java Version

java -version

 

openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.16.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

Now lets do Jenkins installation

 

Installing Jenkins

Installing Jenkins on Ubuntu is relatively straightforward. We’ll enable the Jenkins APT repository, import the repository GPG key, and install the Jenkins package.

Import the GPG keys of the Jenkins repository using the following wget command:

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

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


Once the Jenkins repository is enabled, update the apt package list and install the latest version of Jenkins by typing:

sudo apt-get updatesudo apt-get install jenkins

systemctl status jenkins

You should see something like this:

● jenkins.service - LSB: Start Jenkins at boot time
     Loaded: loaded (/etc/init.d/jenkins; generated)
     Active: active (exited) since Thu 2020-07-16 20:22:12 UTC; 15min ago
...


Next Make Sure Port 8080 is Open

Go to your instance in AWS.... select Security Groups

Then click on the Security Group ID

Click on Edit Inbound Rules

Select Custom TCP Insert 8080 for Port range And set Source to 0.0.0.0/0

then Click Add rule

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:

 

http://EC2_public_dns_name:8080

 

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
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.

sudo apt-get update


sudo apt-get install tomcat8 -y


 

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


 

 

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


 


Change port no from 8080 to 8090

sudo vi /var/lib/tomcat8/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/tomcat8/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-script"/>

<user username="tomcat" password="password" roles="manager-script"/>

 


 

Add more memory to JVM

sudo vi /etc/default/tomcat8

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 tomcat8

 

sudo systemctl status tomcat8


 

 

you may get message that says tomcat is active running.

press q for quitting from that window.

Now go to browser, copy public DNS
http://Ec2_public_dns_name:8090
  Note: Open port 8090 in AWS for this to work follow the steps on 
Next Make Sure Port 8080 is Open above

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



That's it. You have setup Jenkins and Tomcat successfully!!

 Watch installation videos Below

Part 1




Part 2

                                                                      




Part 3

IF YOU MISCONFIGURED YOUR TOMCAT USER PLEASE USE BELOW


<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">
<!--
  NOTE:  By default, no user is included in the "manager-gui" role required
  to operate the "/manager/html" web application.  If you wish to use this app,
  you must define such a user - the username and password are arbitrary. It is
  strongly recommended that you do NOT use one of the users in the commented out
  section below since they are intended for use with the examples web
  application.
-->
<!--
  NOTE:  The sample user and role entries below are intended for use with the
  examples web application. They are wrapped in a comment and thus are ignored
  when reading this file. If you wish to configure these users for use with the
  examples web application, do not forget to remove the <!.. ..> that surrounds
  them. You will also need to set the passwords to something appropriate.
-->
<!--
  <role rolename="tomcat"/>
  <role rolename="role1"/>
  <user username="tomcat" password="<must-be-changed>" roles="tomcat"/>
  <user username="both" password="<must-be-changed>" roles="tomcat,role1"/>
  <user username="role1" password="<must-be-changed>" roles="role1"/>
-->
<role rolename="manager-script"/>

<user username="tomcat" password="password" roles="manager-script"/>
</tomcat-users>





How to upgrade Maven

  java.lang.IllegalStateException I had installed maven in my ubuntu using command  apt install maven This installed maven in path /usr/shar...