Git Product home page Git Product logo

jenkins_tomcat_demo's Introduction

Jenkins Tomcat Demo

How to Install Tomcat

Follow below URL to deploy tomcat on Ubuntu 22.04

https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-10-on-ubuntu-20-04

- sudo useradd -m -d /opt/tomcat -U -s /bin/false tomcat
- sudo apt update
- sudo apt-get install openjdk-17-jdk -y
- cd /tmp
- wget https://dlcdn.apache.org/tomcat/tomcat-10/v10.1.17/bin/apache-tomcat-10.1.17.tar.gz
- sudo tar xzvf apache-tomcat-10*tar.gz -C /opt/tomcat --strip-components=1
- sudo chown -R ubuntu:ubuntu /opt/tomcat/
- sudo chmod -R u+x /opt/tomcat/bin

Open tomcat-users.xml file and add roles & users for managing tomcat. Execute below command and details in below table. To exit from the nano editor press Cntrl+X and then press Y

- sudo nano /opt/tomcat/conf/tomcat-users.xml

Paste in tomact.users.xml file

<role rolename="manager-gui, manager-script" />
<user username="manager" password="manager_password" roles="manager-gui, manager-script" />

<role rolename="admin-gui" />
<user username="admin" password="admin_password" roles="manager-gui,admin-gui" />

To remove the restriction for the Manager page, open its config file for editing and COMMENT out the Valve definition like below

  • sudo nano /opt/tomcat/webapps/manager/META-INF/context.xml

...

<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
<!--  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.Csr>
</Context>

Do the same thing for host manager as well

- sudo nano /opt/tomcat/webapps/host-manager/META-INF/context.xml

...

<Context antiResourceLocking="false" privileged="true" >
  <CookieProcessor className="org.apache.tomcat.util.http.Rfc6265CookieProcessor"
                   sameSiteCookies="strict" />
<!--  <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
  <Manager sessionAttributeValueClassNameFilter="java\.lang\.(?:Boolean|Integer|Long|Number|String)|org\.apache\.catalina\.filters\.Csr>
</Context>

Create the tomcat service file

- sudo nano /etc/systemd/system/tomcat.service

Paste the below contents. Make sure the variable JAVA_HOME is set correctly.

NOTE: If you have a different Java version then you can check the Java path by running the below command path of Java is correct

  • sudo update-java-alternatives -l

[Unit]
Description=Tomcat
After=network.target

[Service]
Type=forking

User=ubuntu
#Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/java-1.17.0-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target

Execute the below steps to start the Tomcat server

- sudo systemctl daemon-reload
- sudo systemctl start tomcat
- sudo systemctl status tomcat

Press q to exit the command.

- sudo ufw allow 8080

You can access Tomcat server on browser using URL http://your_server_ip:8080


Steps to Configure Jenkins

Deploying using SCP command

  • Add SSH Agent plugin
  • Add Tomcat server private key (.pem file) as Jenkins credential
  • Create a Jenkins pipeline Job
  • Define a parameter as name TOMCAT_IP, as this is used in Jenkinsfile

Deploying using Container Plugin

  • Add "Deploy to Container" Plugin

jenkins_tomcat_demo's People

Contributors

vcjain avatar vikash-galaxyweblinks avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.