End To End Deploy in Ubuntu
End To End Deploy in Ubuntu
● Click on Services at the top left to view the drop-down list of resources.
● Click on EC2 under the Compute menu from the drop-down list.
5
● Click on the Launch Instance button and select Launch Instance from the menu.
● Choose an Amazon Machine Image (AMI) from the list of AMIs and click on Select.
6
● Click on Launch.
7
● Click on Launch.
● Navigate to the security groups console.
8
● Add a rule to the security group to which the instance belongs to allow SSH, with the
following settings:
Type: SSH
Protocol: TCP
Port Range: 22
● Add a rule to the security group to which the instance belongs to allow http traffic to
port 8081, with the following settings:
Protocol: TCP
● Run the following commands to install Java and Tomcat and grant permissions to the
Tomcat user:
cd /tmp
curl -O https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.64/bin/apache-tomcat-
9.0.64.zip
unzip apache-tomcat-*.zip
source ~/.bashrc
sudo vi /etc/systemd/system/tomcat.service
--------------------------------------------------------------------------------
[Unit]
After=network.target
[Service]
Type=forking
User=tomcat
Group=tomcat
Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh
[Install]
WantedBy=multi-user.target
sudo update-java-alternatives -l
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.11.0-openjdk-amd64/jre
13
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='JAVA_OPTS=-Djava.awt.headless=true
-Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
14
● Open the server.xml file with the command sudo nano conf/server.xml.
● Add address="0.0.0.0" to the connector and save the file.
● Open the user’s file with the following command: sudo nano
/opt/tomcat/conf/tomcat-users.xml
● Add the following lines right before the last line and save the file:
● By default, newer versions of Tomcat restrict access to the Manager and Host Manager
apps to connections coming from the server itself. Since we are installing on a remote
machine, you will need to remove or alter this restriction. To change the IP address
16
restrictions on these, open the appropriate context.xml files with the following
commands:
● Start and verify the Tomcat server with the following commands:
sudo /opt/tomcat/bin/startup.sh
Cd /opt/tomcat
the file <tomcat>/webapps/manager/META-INF/context.xml has been adjusted:
● Click OK.
● On the configuration page, scroll down to the Source Code Management section.
● Select Git in SCM.
● Add the repository URL.
19
● Scroll down to the Build Trigger and pick the poll SCM option. Enter the expression for
nightly builds.
● Click on Save.
● Click OK.
● On the configuration page, scroll down to the Source Code Management section.
● Select Git in SCM.
● Add the repository URL.
● In the Build Trigger tab, click on build after other projects are built.
● Type the name of the previous project and select the Trigger only if the build is stable
option.
23
● Click on Add post-build action and select Publish JUnit test result report. Fill the fields
with appropriate values.
● Click on Save.
● Click on Build Now in the project window.
● Jenkins will now build your pipeline and output the logs.
● The JUnit test reports can be viewed under the Test Result tab.
25
● Click OK.
● On the configuration page, scroll down to the Source Code Management section.
● Select Git in SCM.
● Add the repository URL.
28
● In the Build Trigger tab click on the build after other projects are built.
● Type the name of the previous project and select the Trigger only if the build is stable
option.
● Fill the required parameters for the plugin. Use the following screenshot as a reference:
● Choose the Context Path in which the application should be installed. It would rename
the WAR file before deploying to the server and thereby the application context root
would be changed.
● Click on the Add post-build action and select Sent Email Notification. Fill the fields with
appropriate values.
31
● Click on Save.
● Click on Build Now in the project window.
● Jenkins will now build your job and output the logs.
● Navigate to the URL on your browser to view your webapp.
● Trigger the first freestyle job to start the pipeline.