Monday, 8 September 2025

Core Git Commands for DevOps in Production

 

1. Cloning Repositories


rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj
$ git clone https://github.com/rajkumargupta14/hello-world-1.git
Cloning into 'hello-world-1'...
remote: Enumerating objects: 345, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 345 (delta 3), reused 2 (delta 2), pack-reused 339 (from 2)
Receiving objects: 100% (345/345), 48.93 KiB | 1.40 MiB/s, done.
Resolving deltas: 100% (78/78), done.

2.  Do the required changes in code like in below case done changes in index.jsp file

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main (master)
$ cd webapp/

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ ls
WEB-INF/  index.jsp
rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ vi index.jsp


3.  Check the git status

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   index.jsp

no changes added to commit (use "git add" and/or "git commit -a")

4.  Add all changes to local repo

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git add .

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   index.jsp



5. Saves changes to the local repository with a message.:-


rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git commit -m "Updated the index file"
[master b81dd6a] Updated the index file
 Committer: Gupta <raj.f.gupta@capgemini.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:

    git config --global --edit

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+), 1 deletion(-)

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean


6. Commit to remote repo it will open browser to  validate with your GitHub account after verification it will merge the code:-


rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$ git push origin master
info: please complete authentication in your browser...
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 12 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 548 bytes | 78.00 KiB/s, done.
Total 7 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/rajkumargupta14/hello-world-1.git
   53817e9..b81dd6a  master -> master

rgupta99@LIN-5CG2217BB4 MINGW64 ~/Desktop/Raj/hello-world-1/webapp/src/main/webapp (master)
$






Sunday, 7 September 2025

Integrate Tomcat with Jenkins and Deploy Java app on a Tomcat server


  1. Install 'deploy to container' plugin. This plugin needs to deploy on tomcat server.
  • Install 'deploy to container' plugin without restart
    • Manage Jenkins > Jenkins Plugins > available > deploy to container





  1. Jenkins should need access to the tomcat server to deploy build artifacts. setup credentials to enable this process. use credentials option on Jenkins home page.
  • setup credentials
    • credentials > jenkins > Global credentials > add credentials
      • Username : deployer
      • Password : deployer
      • id : deployer
      • Description: user to deploy on tomcat server




Enter an item name: JavaApp

  • Source Code Management:

    • Repository: https://github.com/rajkumargupta14/hello-world-1
    • Branches to build : */master
  • Poll SCM : - * * * *

  • Build:

    • Root POM:pom.xml
    • Goals and options: clean install package
  • Post-build Actions

    • Deploy war/ear to container
      • WAR/EAR files : **/*.war
      • Containers : Tomcat 8.x
        • Credentials: deployer (user created on above)
        • Tomcat URL : http://<PUBLIC_IP>:8080
















Save and run the job now. Once done access by using Public IP and port number 8080



Saturday, 6 September 2025

Tomcat Server installation on EC2 instance to run Java App


Install Apache Tomcat , You must have EC2 server with JAVA install on that:-


[root@WebServer ~]# cd /opt/

[root@WebServer opt]# yum install wget

[root@WebServer opt]# wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.109/bin/apache-tomcat-9.0.109.tar.gz

[root@WebServer opt]# tar -xvzf apache-tomcat-9.0.109.tar.gz

[root@WebServer opt]# mv apache-tomcat-9.0.109 tomcat

give executing permissions to startup.sh and shutdown.sh which are under bin.

chmod +x /opt/apache-tomcat-<version>/bin/startup.sh 
chmod +x /opt/apache-tomcat-<version>/bin/shutdown.sh

create link files for tomcat startup.sh and shutdown.sh

ln -s /opt/tomcat/bin/startup.sh /usr/local/bin/tomcatup
ln -s /opt/tomcat/bin/shutdown.sh /usr/local/bin/tomcatdown


Add /usr/local/bin to your $PATH (if missing)


Check your current $PATH:

echo $PATH

If /usr/local/bin is missing, add it temporarily:

export PATH=$PATH:/usr/local/bin

To make it permanent for root, add the line to /root/.bashrc or /root/.bash_profile:

echo 'export PATH=$PATH:/usr/local/bin' >> /root/.bashrc
source /root/.bashrc

=======================================

[root@WebServer tomcat]# find / -name context.xml

/opt/tomcat/conf/context.xml

/opt/tomcat/webapps/docs/META-INF/context.xml

/opt/tomcat/webapps/examples/META-INF/context.xml

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

/opt/tomcat/webapps/manager/META-INF/context.xml

[root@WebServer tomcat]# vi /opt/tomcat/webapps/host-manager/META-INF/context.xml

[root@WebServer tomcat]# vi /opt/tomcat/webapps/manager/META-INF/context.xml



And comment below line in both files by adding

<!-- and at end -->






Add below line in this file at the end:- 

[root@WebServer tomcat]# vi /opt/tomcat/conf/tomcat-users.xml


 <role rolename="manager-gui"/>
 <role rolename="manager-script"/>
 <role rolename="manager-jmx"/>
 <role rolename="manager-status"/>
 <user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status"/>
 <user username="deployer" password="deployer" roles="manager-script"/>
 <user username="tomcat" password="s3cret" roles="manager-gui"/>



Now access by using public ip and port 8080 after stopping and starting tomcat server by using below command:-

tomcatdown

tomcatup






Using unique ports for each application is a best practice in an environment. But tomcat and Jenkins runs on ports number 8080. Hence lets change tomcat port number to 8090. Change port number in conf/server.xml file under tomcat home


cd /opt/apache-tomcat-<version>/conf
# update port number in the "connecter port" field in server.xml
# restart tomcat after configuration update
tomcatdown
tomcatup

Friday, 5 September 2025

How to build Java project using Jenkins and create war files

 

After integration of Maven, Java and Git in Jenkins create new Project in Jenkins with below details:-


In my case my Java code is save in below git repo:-





Then Apply and Save and click on build now:-



Then build will be start after its done webapp.war files will be save in below path:-



Thursday, 4 September 2025

How to integrate Maven with Jenkins to build Java Project

Step 1:- Download Maven from official sites:-  

https://maven.apache.org/download.cgi


[root@jenkins-server ~]# pwd

/root

[root@jenkins-server ~]# cd /opt/

[root@jenkins-server opt]# ls

[root@jenkins-server opt]# ls

[root@jenkins-server opt]# wget https://dlcdn.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz

--2025-09-05 04:46:31--  https://dlcdn.apache.org/maven/maven-3/3.9.11/binaries/apache-maven-3.9.11-bin.tar.gz

Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644

Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 9160848 (8.7M) [application/x-gzip]

Saving to: ‘apache-maven-3.9.11-bin.tar.gz’


apache-maven-3.9.11-bin.tar.gz            100%[===================================================================================>]   8.74M  --.-KB/s    in 0.08s


2025-09-05 04:46:32 (113 MB/s) - ‘apache-maven-3.9.11-bin.tar.gz’ saved [9160848/9160848]


[root@jenkins-server opt]# ls

apache-maven-3.9.11-bin.tar.gz


Step 2:- Once downloaded the untar it.


[root@jenkins-server opt]# tar -xvzf apache-maven-3.9.11-bin.tar.gz

apache-maven-3.9.11/README.txt

apache-maven-3.9.11/LICENSE

apache-maven-3.9.11/NOTICE

apache-maven-3.9.11/lib/

apache-maven-3.9.11/lib/aopalliance.license

apache-maven-3.9.11/lib/asm.license

 


Step 3 :- Rename the folder name



[root@jenkins-server opt]# ls

apache-maven-3.9.11  apache-maven-3.9.11-bin.tar.gz

[root@jenkins-server opt]# mv apache-maven-3.9.11 maven

[root@jenkins-server opt]# ls

apache-maven-3.9.11-bin.tar.gz  maven

[root@jenkins-server opt]# cd maven/

[root@jenkins-server maven]# ls

LICENSE  NOTICE  README.txt  bin  boot  conf  lib

[root@jenkins-server maven]# cd bin/

[root@jenkins-server bin]# ls

m2.conf  mvn  mvn.cmd  mvnDebug  mvnDebug.cmd  mvnyjp


Run the manven command to check:-


[root@jenkins-server bin]# ./mvn -v

Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b)

Maven home: /opt/maven

Java version: 21.0.8, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-21-openjdk

Default locale: en, platform encoding: UTF-8

OS name: "linux", version: "6.12.0-55.25.1.el10_0.x86_64", arch: "amd64", family: "unix"



Step 4:- Now set environment variable to run from anywhere 


[root@jenkins-server bin]# cd ~

[root@jenkins-server ~]# ls

'='

[root@jenkins-server ~]# ls -a

 .   ..   .bash_history   .bash_logout   .bash_profile   .bashrc   .cshrc   .ssh   .tcshrc   .wget-hsts  '='

[root@jenkins-server ~]# vi .bash_profile

[root@jenkins-server ~]# cat .bash_profile

# .bash_profile


# Get the aliases and functions

if [ -f ~/.bashrc ]; then

        . ~/.bashrc

fi

M2_HOME=/opt/maven

M2=/opt/maven/bin

JAVA_HOME=/usr/lib/jvm/java-17-openjdk-17.0.16.0.8-2.el9.x86_64

# User specific environment and startup programs


PATH=$PATH:$HOME/bin:$JAVA_HOME:$M2_HOME:$M2


export PATH

[root@jenkins-server ~]# source .bash_profile

[root@jenkins-server ~]# echo $PATH

/root/.local/bin:/root/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/lib/jvm/java-17-openjdk-17.0.16.0.8-2.el9.x86_64:/opt/maven:/opt/maven/bin

[root@jenkins-server ~]# mvn -v

Apache Maven 3.9.11 (3e54c93a704957b63ee3494413a2b544fd3d825b)

Maven home: /opt/maven

Java version: 21.0.8, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-21-openjdk

Default locale: en, platform encoding: UTF-8

OS name: "linux", version: "6.12.0-55.25.1.el10_0.x86_64", arch: "amd64", family: "unix"

[root@jenkins-server ~]#



To find Java path run below command:-

[root@jenkins-server ~]# find / -name jvm
/usr/lib/jvm
/usr/share/jvm
/etc/jvm
[root@jenkins-server ~]# cd /usr/lib/jvm
[root@jenkins-server jvm]# ls
java                                      java-21-openjdk  jre-17-openjdk                           jre-openjdk
java-17                                   java-openjdk     jre-17-openjdk-17.0.16.0.8-2.el9.x86_64
java-17-openjdk                           jre              jre-21
java-17-openjdk-17.0.16.0.8-2.el9.x86_64  jre-17           jre-21-openjdk
[root@jenkins-server jvm]# ls -ltrh
total 0
lrwxrwxrwx. 1 root root 40 Aug 18 20:05 jre-17-openjdk-17.0.16.0.8-2.el9.x86_64 -> java-17-openjdk-17.0.16.0.8-2.el9.x86_64
drwxr-xr-x. 7 root root 97 Sep  3 07:27 java-17-openjdk-17.0.16.0.8-2.el9.x86_64
lrwxrwxrwx. 1 root root 21 Sep  3 07:27 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 29 Sep  3 07:27 jre-openjdk -> /etc/alternatives/jre_openjdk
lrwxrwxrwx. 1 root root 24 Sep  3 07:27 jre-17 -> /etc/alternatives/jre_17
lrwxrwxrwx. 1 root root 32 Sep  3 07:27 jre-17-openjdk -> /etc/alternatives/jre_17_openjdk
lrwxrwxrwx. 1 root root 26 Sep  3 07:27 java -> /etc/alternatives/java_sdk
lrwxrwxrwx. 1 root root 34 Sep  3 07:27 java-openjdk -> /etc/alternatives/java_sdk_openjdk
lrwxrwxrwx. 1 root root 29 Sep  3 07:27 java-17 -> /etc/alternatives/java_sdk_17
lrwxrwxrwx. 1 root root 37 Sep  3 07:27 java-17-openjdk -> /etc/alternatives/java_sdk_17_openjdk
drwxr-xr-x. 5 root root 68 Sep  3 10:12 java-21-openjdk
lrwxrwxrwx. 1 root root 24 Sep  3 10:12 jre-21 -> /etc/alternatives/jre_21
lrwxrwxrwx. 1 root root 32 Sep  3 10:12 jre-21-openjdk -> /etc/alternatives/jre_21_openjdk





Now install Maven plugins in Jenkins and configure path .

Also configure path of git and Java in Jenkins






If you have multiple java install and to select java 17 use below command:-




Wednesday, 3 September 2025

How to install Jenkins on Redhat EC2 Server

 Step 1:  Download below repo


[root@ip-172-31-18-18 ~]# sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

--2025-09-03 10:08:33--  https://pkg.jenkins.io/redhat-stable/jenkins.repo

Resolving pkg.jenkins.io (pkg.jenkins.io)... 146.75.38.133, 2a04:4e42:56::645

Connecting to pkg.jenkins.io (pkg.jenkins.io)|146.75.38.133|:443... connected.

HTTP request sent, awaiting response... 200 OK

Length: 85

Saving to: ‘/etc/yum.repos.d/jenkins.repo’


/etc/yum.repos.d/jenkins.repo             100%[===================================================================================>]      85  --.-KB/s    in 0s


2025-09-03 10:08:33 (2.71 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [85/85]


===================================================

Step 2:  Download key

[root@ip-172-31-18-18 ~]# sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key


==========================================
Step 3:-  Install java

[root@ip-172-31-18-18 ~]# sudo yum install fontconfig java-21-openjdk
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.

Last metadata expiration check: 0:03:37 ago on Wed Sep  3 10:08:57 2025.
Package fontconfig-2.15.0-7.el10.x86_64 is already installed.

============================================
Step 4:- Install Jenkin now


[root@ip-172-31-18-18 ~]# sudo yum install jenkins
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.

Last metadata expiration check: 0:03:58 ago on Wed Sep  3 10:08:57 2025.

============================================================
Step 5:-  Start the Jenkins

[root@ip-172-31-18-18 ~]# sudo systemctl daemon-reload
[root@ip-172-31-18-18 ~]# sudo systemctl enable jenkins
Created symlink '/etc/systemd/system/multi-user.target.wants/jenkins.service' → '/usr/lib/systemd/system/jenkins.service'.
[root@ip-172-31-18-18 ~]# sudo systemctl start jenkins
[root@ip-172-31-18-18 ~]# sudo systemctl status jenkins
● jenkins.service - Jenkins Continuous Integration Server
     Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; preset: disabled)
     Active: active (running) since Wed 2025-09-03 10:13:52 UTC; 19s ago
 Invocation: 7cec58f4a86b4ad98baa29275db3c9f4
   Main PID: 14143 (java)
      Tasks: 42 (limit: 5687)
     Memory: 452.6M (peak: 462.1M)
        CPU: 14.054s
     CGroup: /system.slice/jenkins.service

===================================================
Step 6:-  Now access the Jenkings by using public ip and port 8080

http://52.90.54.118:8080/

/var/lib/jenkins/secrets/initialAdminPassword





How to setup yum repos and install Java in Redhat AWS EC2 Server

Step 1:- Create one file under /etc/yum.repos.d/ with name centos-stream.repo and copy past below lines


[root@ip-172-31-18-18 yum.repos.d]# cat centos-stream.repo
[centos-stream-appstream]
name=CentOS Stream AppStream
baseurl=https://mirror.stream.centos.org/9-stream/AppStream/x86_64/os/
enabled=1
gpgcheck=0

[centos-stream-baseos]
name=CentOS Stream BaseOS
baseurl=https://mirror.stream.centos.org/9-stream/BaseOS/x86_64/os/
enabled=1
gpgcheck=0
[root@ip-172-31-18-18 yum.repos.d]#





===================================

Step 2:- clean the yum repo

[root@ip-172-31-18-18 yum.repos.d]# sudo yum clean all
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.

18 files removed

====================================

Step 3:- Refreshes package metadata


[root@ip-172-31-18-18 yum.repos.d]# sudo yum makecache
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.

CentOS Stream AppStream                                                                                                                44 MB/s | 4.2 MB     00:00
CentOS Stream BaseOS                                                                                                                   25 MB/s | 6.7 MB     00:00
Red Hat Enterprise Linux 10 for x86_64 - AppStream from RHUI (RPMs)                                                                    19 MB/s | 3.1 MB     00:00
Red Hat Enterprise Linux 10 for x86_64 - BaseOS from RHUI (RPMs)                                                                       55 MB/s |  20 MB     00:00
Red Hat Enterprise Linux 10 Client Configuration                                                                                       24 kB/s | 1.9 kB     00:00
Metadata cache created.


============================================

Step 4:- Now install the java


[root@ip-172-31-18-18 yum.repos.d]# sudo yum install -y java-17-openjdk java-17-openjdk-devel
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use "rhc" or "subscription-manager" to register.

Last metadata expiration check: 0:00:12 ago on Wed Sep  3 07:27:05 2025.
Dependencies resolved.
======================================================================================================================================================================
 Package                                                 Architecture           Version                             Repository                                   Size
======================================================================================================================================================================
Installing:
 java-17-openjdk                                         x86_64                 1:17.0.16.0.8-2.el9                 centos-stream-appstream                     425 k




==========================================

Step 5:- Now verify the Java


[root@ip-172-31-18-18 yum.repos.d]# java --version
openjdk 17.0.16 2025-07-15 LTS
OpenJDK Runtime Environment (Red_Hat-17.0.16.0.8-1) (build 17.0.16+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.16.0.8-1) (build 17.0.16+8-LTS, mixed mode, sharing)