Y21acs570 Devops Final
Y21acs570 Devops Final
Exercise-1:
Demonstration of Git commands: cloning, updating, and pushing changes to a
remote repository.
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab
git_work
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Exercise-2:
Execution of Git commands to create a local repository, update it, and push
changes to GitHub.
[root@Y21ACS570-Gittomcatmaven git_work]#
mkdir u2 [root@Y21ACS570-Gittomcatmaven
git_work]# cd u2 [root@Y21ACS570-
Gittomcatmaven u2]# git init
hint: Using 'master' as the name for the initial branch. This
default branch name
hint: is subject to change. To configure the initial branch name to
use in all
hint: of your new repositories, which will suppress this
warning, call: hint:
hint: git config --global init.defaultBranch
<name> hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk'
and
hint: 'development'. The just-created branch can be renamed via
this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in
/home/ec2-user/git_work/u2/.git/ [root@Y21ACS570-
Gittomcatmaven u2]# git branch -m master main [root@Y21ACS570-
Gittomcatmaven u2]# nano usecase2
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab
[root@Y21ACS570-Gittomcatmaven u2]# ls -a
. .. .git usecase2
[root@Y21ACS570-Gittomcatmaven u2]# git add .
[root@Y21ACS570-Gittomcatmaven u2]# git commit -m "usecase-2 commit"
[main (root-commit) 58aa5e9] usecase-2 commit
1 file changed, 1 insertion(+)
create mode 100644 usecase2
[root@Y21ACS570-Gittomcatmaven u2]# git remote add
origin https://github.com/NailoSharu/usecase2.git
[root@Y21ACS570-Gittomcatmaven u2]# git push origin
main Username for 'https://github.com': NailoSharu
Password for 'https://[email protected]':
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 253 bytes | 253.00 KiB/s,
done. Total 3 (delta 0), reused 0 (delta 0), pack-
reused 0
To https://github.com/NailoSharu/usecase2.git
* [new branch] main -> main
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Exercise-3:
Demonstration of Git commands to pull and fetch from remote repositories.
Git pull:
[root@Y21ACS570-Gittomcatmaven git_work]# mkdir developer-1
[root@Y21ACS570-Gittomcatmaven git_work]# cd developer-1
[root@Y21ACS570-Gittomcatmaven developer-1]# git
clone https://github.com/NailoSharu/usecase3.git
Cloning into 'usecase3'...
warning: You appear to have cloned an empty repository.
[root@Y21ACS570-Gittomcatmaven developer-1]# ls -a
. .. usecase3
[root@Y21ACS570-Gittomcatmaven developer-1]# cd
usecase3 [root@Y21ACS570-Gittomcatmaven usecase3]#
nano dev1
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab
1
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab
To https://github.com/NailoSharu/fetch_operation.git
* [new branch] main -> main
[root@Y21ACS570-Gittomcatmaven fetch_operation]# git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
1
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab
1
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Exercise-4:
Demonstration of Git commands for merge, rebase, and resolving merge conflicts.
1
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Initial commit
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git merge branch-1
Updating
e1c4f72..cd79100 Fast-
forward
file1 | 1 +
1 file changed, 1 insertion(+)
create mode 100644 file1
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git push origin main
Username for 'https://github.com': NailoSharu
Password for 'https://[email protected]':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 293 bytes | 293.00 KiB/s,
done. Total 3 (delta 0), reused 0 (delta 0), pack-
reused 0
To https://github.com/NailoSharu/merge_rebase.git
e1c4f72..cd79100 main -> main
1
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab
1
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab
| 1st commit
|
* commit e1c4f720426dbc0a08ada664dc330fa21746427d
Author: NailoSharu <[email protected]>
Date: Sun Dec 15 11:52:21 2024 +0530
Initial commit
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git checkout main
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git rebase branch-2
Successfully rebased and updated refs/heads/main.
[root@Y21ACS570-Gittomcatmaven merge_rebase]# git push origin main
Username for 'https://github.com': NailoSharu
Password for 'https://[email protected]':
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 319 bytes | 319.00 KiB/s,
done. Total 3 (delta 0), reused 0 (delta 0), pack-
reused 0
To https://github.com/NailoSharu/merge_rebase.git
cd79100..de7066e main -> main
1
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Exercise-5:
Creation of an EC2 instance and installation and configuration of Git, JDK,
Maven, and Tomcat. Creation of a maven application and packaging.
1
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab
1
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab
2. Instance Type:
o Choose the instance type as t2.micro
3. Key pair
o Create a new key pair(or select an existing one). Download the key pair (with .pem
extension) and store it securely, as it will be required for SSH access.
4. Network settings
o Leave the default settings (or customize as needed). Ensure allow SSH traffic from is
selected
o Click on Launch instance
1
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab
2
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Installing GIT:
Installing JDK:
2
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Installing Tomcat:
2
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab
apache-tomcat-9.0.98.tar.gz 100%
[================================================================>]
12.17M --.-KB/s in 0.1s
2
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab
2
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab
2
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Installing Maven:
[root@Y21ACS570-Gittomcatmaven ec2-user]# cd
/opt [root@Y21ACS570-Gittomcatmaven opt]#
wget
https://dlcdn.apache.org/maven/maven-3/3.9.9/binaries/apache-maven-
3.9.9- bin.tar.gz
--2024-12-15 09:23:00--
https://dlcdn.apache.org/maven/maven-
3/3.9.9/binaries/apache-maven-3.9.9-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
.
.
2024-12-15 09:23:00 (92.4 MB/s) - ‘apache-maven-3.9.9-bin.tar.gz’
saved [9102945/9102945]
[root@Y21ACS570-Gittomcatmaven opt]# tar -xvzf apache-maven-
3.9.9- bin.tar.gz
apache-maven-3.9.9/
README.txt apache-maven-
3.9.9/LICENSE apache-
maven-3.9.9/NOTICE
.
.
apache-maven-3.9.9/lib/maven-resolver-connector-basic-
1.9.22.jar apache-maven-3.9.9/lib/plexus-utils-3.5.1.jar
[root@Y21ACS570-Gittomcatmaven opt]# mv apache-maven-3.9.9
maven [root@Y21ACS570-Gittomcatmaven opt]# cd /home/ec2-
user [root@Y21ACS570-Gittomcatmaven ec2-user]#
nano .bashrc
nano .bashrc
2
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab
3
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab
3
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Exercise-6:
Create and push maven application using Eclipse, install Jenkins, build the
application using Jenkins plugins and host it on Tomcat.
1. Open Start menu -> Search for Eclipse -> Click Eclipse IDE forEnterprise Java
and WebDevelopers.
3. Create a new Maven Project using menu File -> New -> Maven Project
3
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab
3
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab
o Enable (Radio button) Manually define a new server -> select apache ->
selectTomcat v9.0 Server -> click on next
3
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab
o Specify the location where you have downloaded the Tomcatwindows (64 bit)
version and click on finish.
3
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab
b. Enable the checkbox (use or create repository in parent folder ofproject) andselect the
path and click on finish.
3
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab
d. Click on add all files including not selected ones to the index and click on commit
3
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab
3
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab
g. Change the branch from master to main and click on preview andnextclick on push
3
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab
a. Access Jenkins
Open Jenkins in your browser: http://<public ip>:8080 and copy the path
/var/lib/jenkins/secrets/initialAdminPassword
3a67bb92b9b54a29aa045741adfa51b3
4
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab
4
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Installing Github and Maven plugin and configuring JDK, Git and Maven usingTools Button
in Manage Jenkins Tab:
a. Goto Dashboard -> Manage Jenkins -> plugins -> available plugins -> search for GitHub ->
select the first one -> click on install
b. Again, search for maven integration -> select the first one -> click oninstall
4
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab
c. Goto to Dashboard -> Manage Jenkins -> Tools -> Add JDK
4
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab
e. Specify the name in maven section and uncheck the checkbox (install
automatically) andprovide the path and click on apply and then click on save
a. Goto Dashboard -> all -> New Item and choose maven project and clickon ok
4
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab
c. In SCM choose Git and provide the URL of GitHub repo. at repository URLand scroll down
4
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab
d. In branches to build change branch specifier from master to main and scroll down and in
goals and options type "clean install”and scroll down
4
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab
f. Goto Dashboard -> Nodes -> built-in Node -> configure -> Disk space monitoring thresholds
-> mark all the values as 0 -> click on save
4
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab
DEPLOYMENT:
Go to EC2-instances start the tomcat instance
a. Go back to Dashboard -> Manage jenkins -> Plugins -> Available pluginsSearch for publish
over SSH
b. Go to Dashboard -> manage jenkins -> Click on system -> publish overSSH -> click on add -
> provide the following
Name: TomcatServer
Hostname: private ip of instance where tomcat is installed
Username: ec2-user
4
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab
c. After providing, expand the Advanced section -> enable the checkbox(use password
authentication or use a different key) Goto file explorer and search for the .pem file of
tomcat instance and make areplica of it. Now open it in any editor copy it and paste it in
keysection
d. After pasting scroll down at last you’ll see test configuration click on it theoutput should be
success which should be displayed on the left sideof yourpage and after successful
outcome click on apply and then click on save
5
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab
e. Go to Dashboard -> open the same item -> configure -> scroll down to post-build actions ->
add post-build action -> send build artfact over SSH
5
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab
5
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab
AUTOMATION:
a. Goto the created item -> configure -> Build Triggers -> enable the checkbox
(poll SCM) and type the following in schedule * * * * *
Click on apply and then click on save
b. Back to the job and build it again using Build Now and check the consoleoutput
5
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab
5
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Exercise-7:
Demonstration of containerization using Docker.
1. Pulling docker image already exists in docker hub into the machine
Complete!
[root@Y21ACS570-dockerhost ec2-user]# service docker
start Redirecting to /bin/systemctl start
docker.service [root@Y21ACS570-dockerhost ec2-user]#
docker images REPOSITORY TAG IMAGE ID
CREATED SIZE
[root@Y21ACS570-dockerhost ec2-user]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Y21ACS570-dockerhost ec2-user]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@Y21ACS570-dockerhost ec2-user]# docker pull tomcat
Using default tag: latest
latest: Pulling from
library/tomcat de44b265507a: Pull
complete 4c2afd91a87d: Pull
complete 89e9bbcfa697: Pull
complete 11be3e613582: Pull
complete 1b9d1e181a2a: Pull
complete a923f560618a: Pull
complete 4f4fb700ef54: Pull
complete cb2453413e93: Pull
complete
Digest:
sha256:935ff51abecc8dc793cb19c229ac7a988c8899e5fcba5e69ae96530fa7
6c4d56 Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
[root@Y21ACS570-dockerhost ec2-user]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
5
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab
5
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab
5
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab
5
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab
5
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Exercise-8:
Implementation of Docker CI/CD pipeline using Jenkins.
[root@Y21ACS570-dockerhost ec2-user]# useradd
dockeradmin [root@Y21ACS570-dockerhost ec2-user]#
passwd dockeradmin Changing password for user
dockeradmin.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@Y21ACS570-dockerhost ec2-user]# usermod -aG docker
dockeradmin [root@Y21ACS570-dockerhost ec2-user]# nano
/etc/ssh/sshd_config
6
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Before testing the configuration make sure that Docker and Jenkins arestarted. Test the
configuration…
6
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab
6
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Run on browser
6
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Exercise-9:
Demonstration of Docker CI/CD pipeline using Jenkins and Ansible.
Start the Ansible, Docker, jenkins instances
In ansible instance:
[ec2-user@Y21ACS570-ansiblehost ~]$ sudo su
[root@Y21ACS570-ansiblehost ec2-user]# sudo yum install ansible -y
Last metadata expiration check: 0:01:50 ago on Sun Dec 15 23:33:35
2024. Dependencies resolved.
=======================================================================
===
===============================================================
===
Package Architecture Version
Repository Size
.
.
.
Installed:
ansible-8.3.0-1.amzn2023.0.1.noarch ansible-core-
2.15.3- 1.amzn2023.0.4.x86_64 git-core-2.40.1-
1.amzn2023.0.3.x86_64
sshpass-1.09-6.amzn2023.0.1.x86_64
Complete!
[root@Y21ACS570-ansiblehost ec2-user]# useradd
ansadmin [root@Y21ACS570-ansiblehost ec2-user]#
passwd ansadmin Changing password for user
ansadmin.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@Y21ACS570-ansiblehost ec2-user]# visudo
6
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab
6
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab
In ansible instance:
6
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Complete!
[ansadmin@Y21ACS570-ansiblehost ~]$ sudo usermod -aG docker
ansadmin [ansadmin@Y21ACS570-ansiblehost ~]$ id ansadmin
uid=1001(ansadmin) gid=1001(ansadmin)
groups=1001(ansadmin),992(docker)
[ansadmin@Y21ACS570-ansiblehost ~]$ cd /opt
[ansadmin@Y21ACS570-ansiblehost opt]$ sudo mkdir
docker [ansadmin@Y21ACS570-ansiblehost opt]$ ls -l
total 0
drwxr-xr-x. 4 root root 33 Nov 22 05:03 aws
drwxr-xr-x. 2 root root 6 Dec 15 23:50 docker
6
7
4/4 B. Tech CSE Y21ACS570 DevOps Lab
6
8
4/4 B. Tech CSE Y21ACS570 DevOps Lab
6
9
4/4 B. Tech CSE Y21ACS570 DevOps Lab
playbook: hello.yml
[ansadmin@Y21ACS570-ansiblehost docker]$ ansible-playbook
deploy_hello.yml
--syntax -check
playbook: deploy_hello.yml
a. Open the Chrome browser, sign up for DockerHub, and once you have successfullysigned in,
create a repository manually as follows:
7
0
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Username:
jaswanth440
Password:
WARNING! Your password will be stored unencrypted in
/home/ansadmin/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#creden
tials- store
Login Succeeded
[ansadmin@Y21ACS570-ansiblehost docker]$ sudo service docker start
[sudo] password for ansadmin:
Redirecting to /bin/systemctl start docker.service
In docker instance:
[root@Y21ACS570-dockerhost ec2-user]# sudo su - ansadmin
Last login: Sun Dec 15 23:53:34 UTC 2024 from 172.31.10.2 on pts/2
[ansadmin@Y21ACS570-dockerhost ~]$ docker login
7
1
4/4 B. Tech CSE Y21ACS570 DevOps Lab
Log in with your Docker ID or email address to push and pull images
from Docker Hub. If you don't have a Docker ID, head over to
https://hub.docker.com/ to create one.
You can log in with your password or a Personal Access Token (PAT).
Using a limited-scope PAT grants better security and is required
for organizations using SSO. Learn more at
https://docs.docker.com/go/access- tokens/
Username:
jaswanth440
Password:
WARNING! Your password will be stored unencrypted in
/home/ansadmin/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#creden
tials- store
Login Succeeded
[ansadmin@Y21ACS570-dockerhost ~]$ sudo chmod 777 /var/run/docker.sock
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
In jenkins instance:
[ec2-user@Y21ACS570-Jenkins ~]$ sudo su
[root@Y21ACS570-Jenkins ec2-user]# service jenkins start
Redirecting to /bin/systemctl start jenkins.service
a. Open jenkins -> Goto Dashboard -> Manage Jenkins -> System -> SSH serversClick on Add
Provide the following as follows
Name: ansiblehost
Hostname: private ip of ansibleinstance
Username: ansadmin
7
2
4/4 B. Tech CSE Y21ACS570 DevOps Lab
b. expand the Advanced section and enable the checkbox provide, the password of
ansadmin which is present in ansible instance
7
3
4/4 B. Tech CSE Y21ACS570 DevOps Lab
c. Test the configuration. Make sure that the result obtained should be success. If the result is
success, then click on apply and then click on save
d. Create a new item from the existing item. provide the name for an item. Give the name
of existing item in copy from textbox
7
4
4/4 B. Tech CSE Y21ACS570 DevOps Lab
e. Install publish over SSH plugin if it is not installed, during the configuration of an item, In
SSH server give the following Name: ansiblehost
7
5
4/4 B. Tech CSE Y21ACS570 DevOps Lab
g. Click on apply and save. Click on Build Now and check the console output
Check in both instances to verify whether the image and the container have been created or not
In ansible instance:
[ansadmin@Y21ACS570-ansiblehost docker]$ sudo docker images
[sudo] password for ansadmin:
REPOSITORY TAG IMAGE ID CREATED SIZE
hello latest 57382b95e117 4 ago 472M
minutes B
jaswanth440/hello latest 57382b95e117 4 ago 472MB
minutes
jaswanth440/hello <none> afd61e499486 11 minutes ago 472MB
jaswanth440/hello <none> d33380e564a3 20 minutes ago 472MB
7
6
4/4 B. Tech CSE Y21ACS570 DevOps Lab
In docker instance:
[ansadmin@Y21ACS570-dockerhost docker]$ docker ps -a
CONTAINER ID IMAGE COMMAND
CREATED STATUS
PORTS NAMES
7125f5a87280 jaswanth440/hello:latest "catalina.sh run" 3
minutes ago Up 3 minutes 0.0.0.0:8087->8080/tcp, :::8087-
>8080/tcp hello- server
09552dd8c1d8 6c323c5b143b "catalina.sh run" 2 hours
ago Up 2 hours
0.0.0.0:8085->8080/tcp, :::8085->8080/tcp xtomcat-
container
130c6271b442 mtomcat "catalina.sh run" 2 hours
ago Up 2 hours
0.0.0.0:8082->8080/tcp, :::8082->8080/tcp mtomcat-
container
f0cfdcc3d9f9 tomcat "catalina.sh run" 2 hours
ago Up 2 hours
0.0.0.0:8081->8080/tcp, :::8081->8080/tcp tomcat-
container
7
7