Intelliq Devops Soft
Intelliq Devops Soft
IntelliQ IT
DevOps Course
By
Mr. Sai Krishna (CorporateTrainer)
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 1
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Content Index
Introduction of Devops....................................................................................................... 3
GIT..................................................................................................................................... 10
Maven................................................................................................................................. 29
ANT.................................................................................................................................... 43
SVN.................................................................................................................................... 54
Jenkins................................................................................................................................ 88
Vagrant............................................................................................................................... 142
Docker................................................................................................................................ 153
Docker Swarm.................................................................................................................... 187
Kubernetes.......................................................................................................................... 194
Ansible................................................................................................................................ 207
Nagios................................................................................................................................. 235
Agile Scrum........................................................................................................................ 241
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 2
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
DevOps
Introduction of Devops
DevOps is the combination of cultural philosophies, practices, and tools that increases an organization’s ability
to deliver applications and services at high velocity: evolving and improving products at a faster pace than
organizations using traditional software development and infrastructure management processes. This speed
enables organizations to better serve their customers and compete more effectively in the market.
DevOps is the practice of operations and development engineers participating together in the entire
service lifecycle, from design through the development process to production support.
Toolchains
As DevOps is intended to be a cross-functional mode of working, those that practice the methodology use
different sets of tools—referred to as "toolchains"—rather than a single one.These toolchains are expected to fit
into one or more of the following categories, reflective of key aspects of the development and delivery process.
1. Coding – code development and review, source code management tools, code merging
2. Building – continuous integration tools, build status
3. Testing – continuous testing tools that provide feedback on business risks
4. Packaging – artifact repository, application pre-deployment staging
5. Releasing – change management, release approvals, release automation
6. Configuring – infrastructure configuration and management, infrastructure as code tools
7. Monitoring – applications performance monitoring, end-user experience
There are different interpretations of these toolchains (e.g. Plan, Create, Verify, Package, Release, Configure,
and Monitor.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 3
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Benefits of DevOps
Speed:
Move at high velocity so you can innovate for customers faster, adapt to changing markets better, and grow
more efficient at driving business results. The DevOps model enables your developers and operations teams to
achieve these results. For example, microservices and continuous delivery let teams take ownership of services
and then release updates to them quicker.
Rapid Delivery:
Increase the frequency and pace of releases so you can innovate and improve your product faster. The quicker
you can release new features and fix bugs, the faster you can respond to your customers’ needs and build
competitive advantage. Continuous integration and continuous delivery are practices that automate the software
release process, from build to deploy.
Reliability:
Ensure the quality of application updates and infrastructure changes so you can reliably deliver at a more rapid
pace while maintaining a positive experience for end users. Use practices like continuous
integration and continuous delivery to test that each change is functional and safe. Monitoring and
logging practices help you stay informed of performance in real-time.
Scale:
Operate and manage your infrastructure and development processes at scale. Automation and consistency help
you manage complex or changing systems efficiently and with reduced risk. For example, infrastructure as
code helps you manage your development, testing, and production environments in a repeatable and more
efficient manner.
Improved Collaboration:
Build more effective teams under a DevOps cultural model, which emphasizes values such as ownership and
accountability. Developers and operations teams collaborate closely, share many responsibilities, and combine
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 4
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
their workflows. This reduces inefficiencies and saves time (e.g. reduced handover periods between developers
and operations, writing code that takes into account the environment in which it is run).
Security:
Move quickly while retaining control and preserving compliance. You can adopt a DevOps model without
sacrificing security by using automated compliance policies, fine-grained controls, and configuration
management techniques. For example, using infrastructure as code and policy as code, you can define and then
track compliance at scale.
Karl Hoods, CIO of the charity Save the Children UK defines it as a way of “removing the barriers to deliver
code more effectively".
That's code that builds machines, or code that we deploy. It enables us to move an awful lot quicker, so it’s
about making us more efficient and effective when it comes to development and deployment.
Whereas previously, developers and engineers could only evaluate their own work, the DevOps culture means
that they can both instantly evaluate the scope of the entire system and assess the impact of those changes,
explains Alex Mathews, EMEA technical manager at security software vendor Positive Technologies.
The general consensus is that organizations that are using software – particularly the development of apps - to
innovate in their sectors, should be looking at implementing a DevOps culture.
A company offering personal training that was once manually booked and has since adopted an IT service to
allow scheduling by smartphone would not at that point need DevOps. If they were to develop the service to
match demand for sessions with personal trainers available near you, then DevOps would become relevant
It enables the business to innovate and test out new ideas quicker than before. Subsequently the business can
deliver features and bring on new revenue streams faster, achieving the agility needed to respond immediately
to marketplace opportunity, events and trends
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 5
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
stakeholders, enhance collaboration, automate your CI&CD pipeline, and integrate customer feedback across the
process of development. For safety-critical developers, it offers end-to-end traceability and an automatically
recorded audit trail to bridge the gap between DevOps and auditors or compliance officers.
When one DevOps team owns the entire lifecycle, a single team becomes responsible for all aspects. They still
rely on the support of other organizational units, but the ownership and work stay within the same team. This
results in a better quality of the software and maintenance since the DevOps teams truly understand the
problems and why something has been developed a certain way.
By allowing the team to adapt towards the needs of the products that they maintain, the teams can come up with
better ideas for improvement and maintenance due to their previous experience.
When the entire application lifecycle is fully agile, organizations can achieve even quicker time to market for
new functionality and products.
The QA and dev need to sit together and identify the areas affected due to a particular build and execute those
related test cases plus a sanity test pass.
Strategy around testing new features need to be formalized and the interim builds can be supplied to QA who
would, in turn, create test scripts and run these automation tests on the interim builds till the code becomes
stable enough to be deployed onto the Production environment.
Continuous deployment (CD) lets operations teams automatically release code changes and deploy them to
production in short cycles, reliably and repeatedly. The use of containers has changed what’s possible when it
comes to CD.
Devops replaces the change control bureaucracy and firefighting that systems administrators are accustomed to
with automated continuous deployment and infrastructure as code. The sysadmin becomes an operations
engineer, using new tools like Puppet and Chef (and Ansible and Salt and Vagrant and Docker) to design and
rapidly spin up standardized, preconfigured systems in a public or private cloud. As a result, wait times go
down and reliability goes up.
The Operations team has quite a significant role in the DevOps environment. A huge chunk of DevOps involves
configuring, managing, provisioning and monitoring servers. Something that’s perfect for an individual from
operations background.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 7
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Learning DevOps enables you to find better solutions for your infrastructure, without worrying about your
servers going down or you having to configure new changes manually on all the servers.
Many of the DevOps automation tools like Puppet, Docker, Kubernetes, Jenkins etc are all handled by
operations team.
Devloper/Engineer — those who not only “code,” but gain the operations knowledge needed to support the
application in production, with the help of…
Operations — those who work with developers on production needs and help support the application in
production. This role may lessen over time as developers become more operations aware, or it may remain a
dedicated role.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 8
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Product Owner/Product Manager — the “owner” of the application in development that specifies what
should be done each iteration, prioritizing the list of “requirements.”
Designer — studies how users interact with the software and systematically designs ways to improve that
interaction. For user-facing applications this also includes visual design.
These are roles that are not always needed and sometimes be fulfilled partially by shared, but designated to the
team staff:
Tester — staff that helps with the effort ensure the software does what was intended and functions properly.
Architect — in large organization, the role or architect is often used to ensure that individual teams are
aligning with the larger organization’s goals and strategy, while also acting as a consultative enabler to help
teams be successful and share knowledge.
Data scientist — if data analysis is core to the application being developed, getting the right analysis and
domain skills will be key.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 9
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
GIT (--fast-version-control)
Git is a free and open source distributed version control system designed to handle everything from small to
very large projects with speed and efficiency.
Git is easy to learn and has a tiny footprint with lightning fast performance. It outclasses SCM tools like
Subversion, CVS, Perforce, and ClearCase with features like cheap local branching, convenient staging areas,
and multiple workflows.
Version Controlling
This is the process of preserving older and latest versions of the code. All the developers upload their code into
the VCS. The VCS's accept the code uploads coming from various developers and create one integrated project
out of those uploads. The next time when developers download the code from the VCS they will find the code
created by the entire team. Process of uploading into VCS is called "cehckin" and downloading from VCS is
called "checkout"
VCS's also preserve the different versions of the code so that the developers can swith between any version
based on requirement.VCS's also track who is making what kind of changes VCS's are of two types
1. Centralised Version Controlling
2. Distributred Version Controlling
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 10
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Distributred Version Controlling
Here a local repository is installed on every developers machine where version controlling happens at the level
of the individual developer.Later from the LR the code is uploaded to the remote repository where version
controlling happens at the level of the complete team.
Configuration:
Setting username and email globally for all users
git config --global user.name "sai krishna"
git config --global user.email "[email protected]"
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 11
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
To see the list of all default configuration
git config --global --list
Local Repo:
Git when working on the local machine uses three sections.
1. Working directory (workspace)
2. Stagging Area
3. Local Repository
Working directory
Initially all the files created by the developers are stroed in a folder called working directory and these files are
initially called untracked files.
Stagging Area
Files from working directory are moved to an intermediate memory area called stagging area.
The files present here are called stagged files.
Local Repository
All files from stagging area will be moved into the local repository and this is where version controlling
happens.These files are called commited files
Basic commands
1. To initilise the working dir to accept git commands. Open git bash
cd path_of_working_dir
git init
The above command will create a hidden folder called .git
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 12
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
where it stores some configuration files for maintianing the local repository
2. To send file from working dir to stagging area
git add filename
To send multiple files into stagging area
git add file1 file2 file3
To send all files and fodlers into the stagging area
git add .
3. To unstage files ie bring files back from stagging to untracked section
git rm --cached filename
(or)
git reset filename
4. To send files from stagging to local repository
git commit -m "Some commit message"
5. To see the status of the untracked and stagging section
git status
6. To see the total commits that are done in LR
git log
To see the commit history in a simplified format
git log --oneline
(In practice, some commits have more than one parent. To see a more representative log, use a command
like git log --oneline --graph --decorate.)
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 13
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
git reflog doesn't traverse HEAD's ancestry at all. The reflog is an ordered list of the commits that HEAD has
pointed to: it's undo history for your repo. The reflog isn't part of the repo itself (it's stored separately to the
commits themselves) and isn't included in pushes, fetches or clones; it's purely local.
Aside: understanding the reflog means you can't really lose data from your repo once it's been committed. If you
accidentally reset to an older commit, or rebase wrongly, or any other operation that visually "removes"
commits, you can use the reflog to see where you were before and git reset --hard back to that ref to restore
your previous state. Remember, refs imply not just the commit but the entire history behind it.
.gitignore
This is a special file where we can store the private filenames. Any filename that is mentioned in .gitignore will
not longer be accessed by git
1. Create few files
touch file1 file2 file3 file4
2. Check the status of git
git status
It will show all the above 4 files as untracked file
3. Create a hidden file .gitignore and enter the above filenames
cat > .gitignore
file1
file2
file3
file4
To come out of cat command press ctrl+d (EOF)
4. Check the status of git
git status
It will not longer show the above created four files as untracked
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 14
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Git Branching
This is a feature of git using which the developers can create seperate functionalities of code on different
branches and later merge them with the master branch.This will help in creating the code in an unclutterred way
1. To see the list of all branches
git branch
To see all branches (local and remote)
git branch -a
2. To create a branch
git branch branchname
3. To move into a branch
git checkout branchname
4. To create a branch and also move into it
git checkout -b branchname
5. To merge a brnach with master
First move to master
git checkout master
git merge branchname
6. To delete a branch that is merged
git branch -d branchname
This is also called soft delete
7. To delete a branch that is not merged
git branch -D branchname
This is also called hard delete
Note: whenever a branch is created whatever is the commit history of the parent branch will be copied to the
newly created branch
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 15
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Note: Irrespective of where a file is created or modified that file belongs to that branch form where it is
commited
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 16
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
git clone
This will download the entire remote repository from git hub into individual developers machine irresepective
of whether that code is already present or not
Syntax
git clone remote_repo_url
git fetch
This will work only when there are modifications in the code between the local repository and remote
repository
git fetch will download the modified files and place them on a remote branch.We can go to that remote branch
check if those changes are accptable or not and if they are acceptable we can merge them with master
1. Create some modifications to any file on github
Open github.com
Click on our remote repository
click on any file that we want to modify
Click on Edit icon
Make some changes--->click on commit changes
2. In git bash
git fetch
3. Check the modified file on master branch
We will not see any modifications
4. The modifications will be on the remote branch
Move to the remote branch
git branch -a
git checkout -b remotes/origin/master
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 17
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
5. View the modified file
If the changes are accpetable merge with master
git checkout master
git merge remotes/origin/master
git pull:
This will also work only when there are modifications between the local repository and the remote repository.
But it will directly merge the modified files with master branch
1. Open github.com
2. Make some changes to a file--->commit changes
3. In git bash
git pull
The modified files can be directly seen on the master branch
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 18
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
git checkout -b sprint-1
touch f3
git add .
git commit -m "c"
touch f4
git add .
git commit -m "d"
3. Move back to master and create few more commits
git checkout master
touch f5
git add .
git commit -m "e"
touch f6
git add .
git commit -m "f"
4. Merge sprint-1 with master
git merge sprint1
5 Delete sprint-1 branch
git branch -d sprint-1
6 Check commit history of master
git log –oneline
git rebase:
This is used for performing a fastforward merge ie the commits coming from the branch are added to the top of
the master branch.This is helpful when we want the commits coming from a branch to be reflected as the latest
working version of code on master.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 19
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
1. On the master create few commits
touch f1
git add .
git commit -m "a"
touch f2
git add .
git commit -m "b"
2. Create a new branch and create few commits on it
git checkout -b sprint-1
touch f3
git add .
git commit -m "c"
touch f4
git add .
git commit -m "d"
3. Move back to master and create few more commits
git checkout master
touch f5
git add .
git commit -m "e"
touch f6
git add .
git commit -m "f"
4. Rebase sprint-1 with master
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 20
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
git checkout sprint-1
git rebase master
git checkout master
git merge sprint-1
Git Squash
Squash is merging of commits to make multiple commits to make it look like a single commit.
git rebase -i HEAD~4
The above command will open in vi editor
where the complete commit history is shown
Remove the pick word and replace it with squash
Save and quit esc : wq Enter
Check the commit history
git log --oneline
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 21
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Modifing exisiting commits
Whenever we modify a file or create new files generally we create a new commit.Instead we can put the
modifications in the existing commit itself rather than creating a new commit.
This can be done using git amend command
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 22
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
git add .
6. Commit it to local repositry as an exisiting commmit
git commit --amend -m "c"
7. Check the commit history
git log --oneline
We will see that new commit is not created the changes are
pushed into the exisiting "c" commit
Note: git amend actually creates a new commit.
The older "c" commit becomes an orphaned commit which Can not be see using git log
We can use "git reflog" for seeing the entire commit history.ie active and orphaned commits
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 23
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
git checkout -b sprint-1
3. Create some commits here
touch f3
git add .
git commit -m "c
touch f4
git add .
git commit -m "d"
touch f5
git add .
git commit -m "e"
4. Check the commit history on sprint-1 branch
git log --oneline
5. Identify the commits that we want from sprint-1 branch and move back to master branch
git checkout master
git cherry-pick commit_id1 commit_id2
6. Check the commit history on master
git log --oneline
git stash
This is a feature of git which is used for leaving unfinished work and start a new functionality related coding.
Further command nof git should not touch the unfinished files
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 24
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
2. To stash the files present in stagging area and untracked section
git stash -u
3. To stash the files present in stagging area, untracked section and also the .gitignore
git stash -a
4. To see the list of all stashes that we have done
git stash list
5. To unstash the latest stash
git stash pop
6. To unstash any older stash
git stash pop stash{stashno}
Eg: To unstash the second last stash
git stash pop stash{1}
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 25
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
cat > .gitignore
f3
f4
f5
Press Ctrl+d to come out of cat command
5. Since f3, f4, f5 are put in .gitignore git status will no longer
show them as untracked files but it will show .gitignore as untracked file.ie further commands of git will send
this .gitignore into stagging area and also in local and remote repositories.If we want ot avoid that and
.gitignore should not be accessed by git
git stash –a
git squash:
One very nice feature of Git is the ability to rewrite the history of commit.
The principal reason for doing this is that a lot of such history is relevant only for the developer who generated
it, so it must be simplified, or made more nice, before submitting it to a shared repository.
Squashing a commit means, from an idiomatic point of view, to move the changes introduced in said commit
into its parent so that you end with one commit out of twos.
If you repeat this process multiple times, you can reduce n commit to a single one.
Use git rebase -i <after-this-commit> and replace "pick" on the second and subsequent commits with "squash"
or "fixup", as described in the manual.
In this example, <after-this-commit> is either the SHA1 hash or the relative location from the HEAD of the
current branch from which commits are analyzed for the rebase command. For example, if the user wishes to
view 5 commits from the current HEAD in the past the command is git rebase -i HEAD~5
Tagging in Git
Tags are used for placing bookmarks on commits. They are to specify info related to who tagged , when it was
tagged and why it was tagged. Generally used for releases. This helps in understanding what are the commits
that are related to specific releases
Tags are of two types
1. Light weight tags
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 26
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
2. Annoted tags
git diff
This is used for finding the difference between 2 commits or it can be used for finding the difference between
a commit and a file yet to be commited
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 27
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
2. To find diff between latest commit and a file
git diff HEAD filename
git revert:
Given one or more existing commits, revert the changes that the related patches introduce, and record some new
commits that record them. This requires your working tree to be clean (no modifications from the HEAD
commit).
Note: git revert is used to record some new commits to reverse the effect of some earlier commits (often only a
faulty one). If you want to throw away all uncommitted changes in your working directory, you should see git-
reset[1], particularly the --hard option. If you want to extract specific files as they were in another commit, you
should see git-checkout[1], specifically the git checkout <commit> -- <filename> syntax. Take care with these
alternatives as both will discard uncommitted changes in your working directory.
usage
Git revert <commit-id>
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 28
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Introduction
Maven is a project management and comprehension tool that provides developers a complete build lifecycle
framework. Development team can automate the project's build infrastructure in almost no time as Maven uses
a standard directory layout and a default build lifecycle.
In case of multiple development teams environment, Maven can set-up the way to work as per standards in a
very short time. As most of the project setups are simple and reusable, Maven makes life of developer easy
while creating reports, checks, build and testing automation setups.
Objective
The primary goal of Maven is to provide developer with the following −
• A comprehensive model for projects, which is reusable, maintainable, and easier to comprehend.
Maven project structure and contents are declared in an xml file, pom.xml, referred as Project Object Model
(POM), which is the fundamental unit of the entire Maven system. In later chapters, we will explain POM in
detail.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 29
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
A Build Lifecycle is Made Up of Phases:
Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a
stage in the lifecycle.
For example, the default lifecycle comprises of the following phases (for a complete list of the lifecycle
phases, refer to the Lifecycle Reference):
Validate:
validate the project is correct and all necessary information is available
Compile:
compile the source code of the project
Test:
Test the compiled source code using a suitable unit testing framework. These tests should not require the code
be packaged or deployed
Package:
Take the compiled code and package it in its distributable format, such as a JAR.
Verify:
run any checks on results of integration tests to ensure quality criteria are met
Install:
install the package into the local repository, for use as a dependency in other projects locally
Deploy:
Deploy done in the build environment, copies the final package to the remote repository for sharing with
other developers and projects.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 30
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
These lifecycle phases (plus the other lifecycle phases not shown here) are executed sequentially to complete
the default lifecycle. Given the lifecycle phases above, this means that when the default lifecycle is used,
Maven will first validate the project, then will try to compile the sources, run those against the tests, package
the binaries (e.g. jar), run integration tests against that package, verify the integration tests, install the verified
package to the local repository, then deploy the installed package to a remote repository.
Install in windows:
Install in Linux:
Open Linux terminal
Type ‘sudo apt-get install –y maven’
Configure:
Set M2_HOME:
1. Go to computer/pc properties
2. Go to Advanced system settings
3. Go to environment variables
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 31
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
4. Select system variables
5. Click on New Variable name=”M2_HOME” and variable value=”C:\Users\nagesh\Downloads\apache-
maven-3.5.4-bin\apache-maven-3.5.4”. note: copy value before bin
Include maven in path:
1. Go to computer/pc properties
2. Go to Advanced system settings
3. Go to environment variables
4. Select system variables
6. Click on path variable if already exist otherwise click on New Variable name=”path” variable value=”;
C:\Users\nagesh\Downloads\apache-maven-3.5.4-bin\apache-maven-3.5.4\bin”
Note: maven is based on java so we install java and set the JAVA_HOME and include java path in path
variable
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 32
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Note: it is the version of the artifact
Define value for property 'package' intelliqgroup: : intelliq.com
Define value for property 'package' mygroup: : intelliq.com
Confirm properties configuration:
groupId: mygroup
artifactId: intelliq
version: 1.5
package: intelliq.com
Y: : y
Maven Dependencies
One of the core features of Maven is Dependency Management. Managing dependencies is a difficult task
once we've to deal with multi-module projects (consisting of hundreds of modules/sub-projects). Maven
provides a high degree of control to manage such scenarios.
Maven helps to avoid such requirements to discover all the libraries required. Maven does so by reading
project files (pom.xml) of dependencies, figure out their dependencies and so on.
We only need to define direct dependency in each project pom. Maven handles the rest automatically.
Note: go to projectdirectory (cd artifactid) then you find pom.xml file in this file all dependencies and plugins
are configured based on our project requirement
<dependencies><dependency><groupId>org.scala-lang</groupId><artifactId>scala-
library</artifactId><version>${scala-version}</version></dependency><dependency><groupId>org.scala-
lang</groupId><artifactId>scala-compiler</artifactId><version>${scala-
version}</version></dependency><dependency><groupId>javax.servlet</groupId><artifactId>servlet-
api</artifactId><version>${servlet-api-
version}</version><scope>provided</scope></dependency><dependency><groupId>org.fusesource.scalate</g
roupId><artifactId>scalate-page_2.10</artifactId><version>${scalate-
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 33
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
version}</version></dependency><dependency><groupId>com.sun.jersey</groupId><artifactId>jersey-
server</artifactId><version>${jersey-
version}</version></dependency><dependency><groupId>ch.qos.logback</groupId><artifactId>logback-
classic</artifactId><version>${logback-
version}</version><scope>runtime</scope><optional>true</optional></dependency>
<!-- testing -->
<dependency><groupId>org.fusesource.scalate</groupId><artifactId>scalate-
test_2.10</artifactId><version>${scalate-version}</version><scope>test</scope>
</dependency>
</dependencies>
Note:
By default minium reqiured dependencies are added to run the project and type dependencies are based on
project type.
If we required some more libraries to build our project then add all necessary dependencies into these
depemdecies section. Ex . our project is connected to database then add mysql dependencies in dependency
section.
You can also previous maven project by adding that project property details in dependency section
When we build the project these all dependencies library files downloaded into resources section and add to
classpath variable
Maven repositories
Artifact Repositories
A repository in Maven holds build artifacts and dependencies of varying types.
There are exactly two types of repositories: local and remote. The local repository is a directory on the
computer where Maven runs. It caches remote downloads and contains temporary build artifacts that you
have not yet released.
Remote repositories refer to any other type of repository, accessed by a variety of protocols such
as file:// and http://. These repositories might be a truly remote repository set up by a third party to provide
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 34
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
their artifacts for downloading (for example, repo.maven.apache.org and uk.maven.org house Maven's central
repository). Other "remote" repositories may be internal repositories set up on a file or HTTP server within
your company, used to share private artifacts between development teams and for releases.
Local and remote repositories are structured the same way so that scripts can run on either side, or they can be
synced for offline use. The layout of the repositories is completely transparent to the Maven user, however.
Using Repositories
In general, you should not need to do anything with the local repository on a regular basis, except clean it out
if you are short on disk space (or erase it completely if you are willing to download everything again).
For the remote repositories, they are used for both downloading and uploading (if you have the permission to
do so).
Building Offline
If you are temporarily disconnected from the internet and you need to build your projects offline, you can use
the offline switch on the CLI:
1. mvn -o package
Many plugins honor the offline setting and do not perform any operations that connect to the internet. Some
examples are resolving Javadoc links and link checking the site.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 35
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Uploading to a Remote Repository
While this is possible for any type of remote repository, you must have the permission to do so. To have
someone upload to the central Maven repository, see Repository Center.
Internal Repositories
When using Maven, particularly in a corporate environment, connecting to the internet to download
dependencies is not acceptable for security, speed or bandwidth reasons. For that reason, it is desirable to set
up an internal repository to house a copy of artifacts, and to publish private artifacts to.
Such an internal repository can be downloaded using HTTP or the file system (with a file:// URL), and
uploaded to using SCP, FTP, or a file copy.
As far as Maven is concerned, there is nothing special about this repository: it is another remote
repository that contains artifacts to download to a user's local cache, and is a publish destination for artifact
releases.
Additionally, you may want to share the repository server with your generated project sites. For more
information on creating and deploying sites, see Creating a Site.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 36
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
1. <project>
2. ...
3. <repositories>
4. <repository>
5. <id>my-internal-site</id>
6. <url>http://myserver/repo</url>
7. </repository>
8. </repositories>
9. ...
10. </project>
If your internal repository requires authentication, the id element can be used in your settings file to specify
login information.
<repositories><repository><id>repo1.maven</id><name>Maven Central
Repo</name><url>http://repo1.maven.org/maven2/</url></repository><repository><id>fusesource.m2</id><n
ame>FuseSource Community Release
Repository</name><url>http://repo.fusesource.com/nexus/content/repositories/public</url><snapshots><enabl
ed>false</enabled></snapshots><releases><enabled>true</enabled></releases></repository><repository><id>
fusesource.m2-snapshot</id><name>FuseSource Community Snapshot
Repository</name><url>http://repo.fusesource.com/nexus/content/repositories/snapshots</url><snapshots><en
abled>true</enabled></snapshots><releases><enabled>false</enabled></releases></repository><repository><
id>java.net.m2</id><name>java.net Maven 2
Repo</name><url>http://download.java.net/maven/2</url></repository><repository><id>openqa-
releases</id><name>OpenQA
Releases</name><url>http://archiva.openqa.org/repository/releases</url><releases><enabled>true</enabled><
/releases><snapshots><enabled>false</enabled></snapshots></repository><repository><id>glassfish-repo-
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 37
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
archive</id><name>Nexus repository collection for
Glassfish</name><url>http://maven.glassfish.org/content/groups/glassfish</url><snapshots><updatePolicy>ne
ver</updatePolicy></snapshots></repository><repository><id>scala</id><name>Scala
Tools</name><url>http://scala-tools.org/repo-
releases</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshot
s></repository><repository><id>snapshots.scala-tools.org</id><name>Scala-Tools Maven2 Snapshot
Repository</name><url>http://scala-tools.org/repo-snapshots</url><snapshots><enabled>true</enabled>
<!--updatePolicy>never</updatePolicy-->
<checksumPolicy>fail</checksumPolicy></snapshots><releases><enabled>true</enabled>
<!--updatePolicy>never</updatePolicy-->
<checksumPolicy>fail</checksumPolicy></releases></repository><repository><id>apache.snapshots</id><
name>Apache Development Snapshot
Repository</name><url>https://repository.apache.org/content/repositories/snapshots</url><releases><enable
d>false</enabled></releases><snapshots><enabled>true</enabled></snapshots></repository></repositorie>
Maven Plugins:
Maven is actually a plugin execution framework where every task is actually done by plugins. Maven Plugins
are generally used to −
A plugin generally provides a set of goals, which can be executed using the following syntax −
mvn [plugin-name]:[goal-name]
For example, a Java project can be compiled with the maven-compiler-plugin's compile-goal by running the
following command.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 38
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
mvn compiler:compile
Plugin Types:
Maven provided the following two types of Plugins
Build plugins
They execute during the build process and should be configured in the <build/> element of pom.xml.
Reporting plugins
They execute during the site generation process and they should be configured in the <reporting/> element of
the pom.xml.
Following is the list of few common plugins
clean
compiler
surefire
jar
war
javadoc
antrun
Runs a set of ant tasks from any phase mentioned of the build.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 39
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
List of plugins added to our project:
<plugins><plugin><groupId>net.alchim31.maven</groupId><artifactId>scala-maven-
plugin</artifactId><version>${scala-plugin-
version}</version><executions><execution><goals><goal>compile</goal><goal>testCompile</goal></goals>
</execution></executions><configuration><jvmArgs><jvmArg>-Xmx1024m</jvmArg></jvmArgs><args>
<!-- arg>-unchecked</arg -->
<arg>-deprecation</arg></args><scala-version>${scala-version}</scala-
version><recompileMode>incremental</recompileMode></configuration></plugin><plugin><artifactId>mave
n-surefire-plugin</artifactId><version>${surefire-plugin-
version}</version><configuration><forkMode>once</forkMode>
<!-- these settings are mandatory to avoid SureFire giving a bogus system property to the web container -->
<useSystemClassLoader>false</useSystemClassLoader><useManifestOnlyJar>false</useManifestOnlyJar><in
cludes><include>**/*Test.*</include></includes></configuration></plugin><plugin><artifactId>maven-war-
plugin</artifactId><version>${war-plugin-
version}</version><configuration><attachClasses>true</attachClasses></configuration></plugin><plugin><gr
oupId>org.mortbay.jetty</groupId><artifactId>jetty-maven-plugin</artifactId><version>${jetty-plugin-
version}</version><configuration><webAppConfig><contextPath>/</contextPath></webAppConfig><system
Properties>
<!-- enable easy JMX connection to JConsole -->
<systemProperty><name>com.sun.management.jmxremote</name><value/></systemProperty><systemProper
ty><name>scalate.editor</name><value>${scalateEditor}</value></systemProperty><systemProperty><name
>scalate.workdir</name><value>${scalate.workdir}</value></systemProperty><systemProperty><name>scal
ate.package.resources</name><value>${scalate.package.resources}</value></systemProperty><systemPropert
y><name>scalate.mode</name><value>${scalate.mode}</value></systemProperty></systemProperties><scan
IntervalSeconds>0</scanIntervalSeconds></configuration></plugin><plugin><groupId>org.codehaus.mojo</g
roupId><artifactId>tomcat-maven-plugin</artifactId><version>${tomcat-plugin-
version}</version><configuration><path>/</path><systemProperties>
<!-- enable easy JMX connection to JConsole -->
<com.sun.management.jmxremote/>
<!-- Scalate console configuration -->
<scalate.mode>${scalate.mode}</scalate.mode><scalate.editor>${scalateEditor}</scalate.editor><scalate.w
orkdir>${scalate.workdir}</scalate.workdir><scalate.package.resources>${scalate.package.resources}</scal
ate.package.resources></systemProperties></configuration></plugin><plugin><groupId>org.fusesource.scal
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 40
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
ate</groupId><artifactId>maven-scalate-plugin_2.10</artifactId><version>${scalate-
version}</version><executions><execution><goals><goal>precompile</goal></goals></execution></execu
tions></plugin></plugins>
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 42
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Ant (Build Tool)
ANT stands for Another Neat Tool. It is a Java-based build tool from Apache. Before going into the details of
Apache Ant, let us first understand why we need a build tool in the first place.
• Ant is platform neutral and can handle platform specific properties such as file separators.
• Ant can be used to perform platform specific tasks such as modifying the modified time of a file using
'touch' command.
• Ant scripts are written using plain XML. If you are already familiar with XML, you can learn Ant pretty
quickly.
• Ant can be easily invoked from the command line and it can integrate with free and commercial IDEs.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 43
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Configuring ANT:
Apache Ant Ant is distributed under the Apache Software License, a fully-fledged open source license certified
by the open source initiative.
The latest Apache Ant version, including its full-source code, class files, and documentation can be found
at http://ant.apache.org.
• Ensure that the JAVA_HOME environment variable is set to the folder where your JDK is installed.
• Unzip the zip file to a convenient location c:\folder. using Winzip, winRAR, 7-zip or similar tools.
• Create a new environment variable called ANT_HOME that points to the Ant installation folder, in this
case c:\apache-ant-1.8.2-bin folder.
• Append the path to the Apache Ant batch file to the PATH environment variable. In our case this would
be the c:\apache-ant-1.8.2-bin\bin folder.
C:\>ant -version
Apache Ant(TM) version 1.8.2 compiled on December 20 2010
If you do not see the above output, then please verify that you have followed the installation steps properly.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 44
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Using Build.xml
Typically, Ant's build file, called build.xml should reside in the base directory of the project. However there is
no restriction on the file name or its location. You are free to use other file names or save the build file in some
other location.
For this exercise, create a file called build.xml anywhere in your computer with the following contents in it −
</target>
</project>
Note that there should be no blank line(s) or whitespace(s) before the xml declaration. If you allow them, the
following error message occurs while executing the ant build -
All build files require the project element and at least one target element.
name
default
The default target for the build script. A project may contain any number of targets. This attribute specifies
which target should be considered as the default. (Mandatory)
Basedir
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 45
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
The base directory (or) the root folder for the project. (Optional)
A target is a collection of tasks that you want to run as one unit. In our example, we have a simple target to
provide an informational message to the user.
Targets can have dependencies on other targets. For example, a deploy target may have a dependency on
the package target, the package target may have a dependency on the compile target and so forth.
Dependencies are denoted using the depends attribute. For example −
....
</target>
....
</target>
....
</target>
....
</target>
name
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 46
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
The name of the target (Required)
depends
Comma separated list of all targets that this target depends on. (Optional)
if
Allows the execution of a target based on the trueness of a conditional attribute. (optional)
unless
Adds the target to the dependency list of the specified Extension Point. An Extension Point is similar to a
target, but it does not have any tasks. (Optional)
The echo task in the above example is a trivial task that prints a message. In our example, it prints the
message Hello World.
To run the ant build file, open up command prompt and navigate to the folder where the build.xml resides, and
type ant info. You could also type ant instead. Both will work, because info is the default target in the build
file. You should see the following output −
C:\>ant
Buildfile: C:\build.xml
BUILD SUCCESSFUL
Total time: 0 seconds
C:\>
Ant build files are written in XML, which does not allow declaring variables as you do in your favorite
programming language. However, as you may have imagined, it would be useful if Ant allowed declaring
variables such as project name, project source directory, etc.
Ant uses the property element which allows you to specify properties. This allows the properties to be
changed from one build to another or from one environment to another.
By default, Ant provides the following pre-defined properties that can be used in the build file −
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 47
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Sr.No. Properties & Description
1 ant.file
2 ant.version
3 Basedir
The basedir of the build, as specified in the basedir attribute of the projectelement.
4 ant.java.version
5 ant.project.name
The name of the project, as specified in the name atrribute of the projectelement.
6 ant.project.default-target
7 ant.project.invoked-targets
Comma separated list of the targets that were invoked in the current project.
8 ant.core.lib
9 ant.home
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 48
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
The home directory of Ant installation.
10 ant.library.dir
The home directory for Ant library files - typically ANT_HOME/lib folder.
Ant also makes the system properties (Example: file.separator) available to the build file.
In addition to the above, the user can define additional properties using the propertyelement. The following
example shows how to define a property called sitename −
</target>
</project>
Running Ant on the above build file produces the following output −
C:\>ant
Buildfile: C:\build.xml
BUILD SUCCESSFUL
Total time: 0 seconds
C:\>
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 49
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
CLEAN:
In the clean stage ANT will delete the pervious builds.
INIT: in the init stage ANT will recreate the folder structure
COMPILE: in compile stage .java files are converted into .class files
This .class files are also called as Byte code. They can be execute any o/s
Build:
In this stage .class files archive in to a single jar file or war file
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 51
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Now, Ant is integrated with Jenkins. You can use Ant in the build process. While configuring a job, in the build
option select invoke Ant and choose the Ant version. In my case, I have given the name ant so there are two
options available default and ant. Select advance option and you can configure extra parameters. I have chosen
the build file build.xml. So when ever Ant is executed it will read from build.xml file.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 52
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
You can put your build.xml file along with git repository. So whenever you want to test some code you can
read from the build.xml file and define different build.xml file for different repository.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 53
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
SVN
Apache Subversion which is often abbreviated as SVN, is a software versioning and revision control system
distributed under an open source license. SVN system that is needed to maintain the current and historical
versions of files such as source code, web pages, and documentations.
Prerequisites
Before proceeding with this tutorial, you should have a basic understanding on simple terminologies like
programming language, source code, documents, etc. Because using SVN to handle all levels of software
projects in your organization, it will be good if you have a working knowledge of software development and
software testing processes.
VCS is a software that helps software developers to work together and maintain a complete history of their
work.
• Repository: A repository is the heart of any version control system. It is the central place where
developers store all their work. Repository not only stores files but also the history. Repository is
accessed over a network, acting as a server and version control tool acting as a client. Clients can
connect to the repository, and then they can store/retrieve their changes to/from repository. By storing
changes, a client makes these changes available to other people and by retrieving changes, a client takes
other people's changes as a working copy.
• Trunk: The trunk is a directory where all the main development happens and is usually checked out by
developers to work on the project.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 54
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
• Tags : The tags directory is used to store named snapshots of the project. Tag operation allows to give
descriptive and memorable names to specific version in the repository.
Revision: 13
• Branches: Branch operation is used to create another line of development. It is useful when you want
your development process to fork off into two different directions. For example, when you release
version 5.0, you might want to create a branch so that development of 6.0 features can be kept separate
from 5.0 bug-fixes.
• Working copy: Working copy is a snapshot of the repository. The repository is shared by all the teams,
but people do not modify it directly. Instead each developer checks out the working copy. The working
copy is a private workplace where developers can do their work remaining isolated from the rest of the
team.
• Commit changes: Commit is a process of storing changes from private workplace to central server.
After commit, changes are made available to all the team. Other developers can retrieve these changes
by updating their working copy. Commit is an atomic operation. Either the whole commit succeeds or is
rolled back. Users never see half finished commit.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 55
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always
start up with the server boots.
# ...
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 56
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
<Location /svn>
DAV svn
#SVNPath /var/lib/svn
SVNParentPath /var/lib/svn
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 57
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
# you don't need the fine-grained control, don't configure it.
# you are using https. See the 'htpasswd' command to create and
# 'auth_basic' and 'authn_file' modules, which you will need for this
AuthType Basic
AuthUserFile /etc/apache2/dav_svn.passwd
#AuthzSVNAccessFile /etc/apache2/dav_svn.authz
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 58
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
#
Require valid-user
</Location>
When you’re done, run the commands below to create a SVN Repository in the /var/lib/svn directory….
Restart Apache2
http://server-public-ip/svn/repository
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 59
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
SVN Lifecycle
Create Repository:
The repository is a central place where developers store all their work. Repository not only stores files, but also
the history about changes.Which means it maintains a history of the changes made in the files.
The 'create' operation is used to create a new repository.Most of the times this operation is done only once.
When you create a new repository, your VCS will expect you to say something to identify it, such as where
you want it to be created, or what name should be given to the repository.
Checkout
'Checkout' operation is used to create a working copy from the repository. Working copy is a private
workplace where developers do their changes, and later on, submit these changes to the repository.
Update
As the name suggests, 'update' operation is used to update working copy. This operation synchronizes the
working copy with the repository. As repository is shared by all the teams other developers can commit their
changes and your working copy becomes older.
Let us suppose Tom and Jerry are the two developers working on a project. Both check out the latest version
from the repository and start working. At this point, their working copies are completely synchronized with the
repository. Jerry completes his work very efficiently and commits his changes to the repository.
Now Tom's working copy is out of date. Update operation will pull Jerry’s latest changes from the repository
and will update Tom's working copy.
Perform Changes
After the checkout, one can do various operations to perform changes. Edit is the most common operation. One
can edit the existing file to add/remove contents from the file.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 60
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
One can add files/directories. But immediately these files/directories do not become a part of the repository,
instead they are added to the pending change-list and become a part of the repository after the commit
operation.
Similarly one can delete files/directories. Delete operation immediately deletes file from the working copy, but
actual deletion of the file is added to the pending change-list and changes are made to the repository after the
commit operation.
'Rename' operation changes the name of the file/directory. 'Move' operation is used to move files/directories
from one place to another in a repository tree.
Review Changes
When you check out the working copy or update the working copy, then your working copy is completely
synchronized with the repository. But as you do changes to your working copy, it becomes newer than the
repository. And it is a good practice to review your changes before the 'commit' operation.
'Status' operation lists the modifications that have been made to the working copy. As we have mentioned
before, whenever you do changes in the working copy all these changes become a part of the pending change-
list. And the 'status' operation is used to see the pending change-list.
'Status' operation only provides a list of changes but not the details about them. One can use diff operation to
view the details of the modifications that have been made to the working copy.
Fix Mistakes
Let us suppose one has made changes to his working copy, but now, he wants to throw away these changes. In
this situation, 'revert' operation will help.
Revert operation reverts the modifications that have been made to the working copy. It is possible to revert one
or more files/directories. Also it is possible to revert the whole working copy. In this case, the 'revert' operation
will destroy the pending change-list and will bring the working copy back to its original state.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 61
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Resolve Conflicts:
Conflicts can occur at the time of merging. 'Merge' operation automatically handles everything that can be
done safely. Everything else is considered as conflict. For example, "hello.c" file was modified in branch and
deleted in another branch. Such a situation requires a person to make the decision. The 'resolve' operation is
used to help the user figure out things and to inform VCS about the ways of handling the conflicts.
Commit Changes
'Commit' operation is used to apply changes from the working copy to the repository. This operation modifies
the repository and other developers can see these changes by updating their working copy.
Before commit, one has to add files/directories to the pending change-list. This is the place where changes wait
to be committed. With commit, we usually provide a log message to explain why someone made changes. This
log message becomes a part of the history of the repository. Commit is an atomic operation, which means
either the entire commit succeeds or it is rolled back. Users never see half-finished commit.
Checkout process
Subversion provides the checkout command to check out a working copy from a repository. Below command
will create a new directory in the current working directory with the name project_repo. Don't bother about the
repository URL, as most of the time, it is already provided by the subversion administrator with appropriate
access.
-----------------------------------------------------------------------
ATTENTION! Your password for authentication realm:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 62
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Subversion Repository
You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/home/ubuntu/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
Checked out revision 0.
admin checks out the latest version of the repository and starts working on a project. He creates array.c file
inside the trunk directory.
cd project_repo/trunk/
cat array.c
#include <stdio.h>
#define MAX 16
int main(void) {
int i, n, arr[MAX];
scanf("%d", &n);
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 63
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
printf("\n");
return 0;
make array
cc array.c -o array
./array
Enter the total number of elements: 5
Enter the elements
1
2
3
4
5
Array has following elements
|1| |2| |3| |4| |5|
He compiled and tested his code and everything is working as expected, now it is time to commit changes.
svn status
? array.c
? array
Subversion is showing '?' in front of filenames because it doesn't know what to do with these files.
Before commit, admin needs to add this file to the pending change-list.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 64
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Let us check it with the 'status' operation. Subversion shows A before array.c, it means, the file is successfully
added to the pending change-list.
snv status
? array
A array.c
To store array.c file to the repository, use the commit command with -m option followed by commit message.
If you omit -m option Subversion will bring up the text editor where you can type a multi-line message.
Now array.c file is successfully added to the repository, and the revision number is incremented by one
Note: if you get any error it is not working copy then execute belo command
Note: if you got any error linke it is not a working copy the execute command in
svn/trk(sudo svn co --force http://svn-server-ip/svn/repository/ .)
admin already added array.c file to the repository. Tom also checks out the latest code and starts working.
A project_repo/trunk
A project_repo/trunk/array.c
A project_repo/branches
A project_repo/tags
Checked out revision 2.
But, he found that someone has already added the code. So he is curious about who did that and he checks the
log message to see more details using the following command:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 65
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
svn log
------------------------------------------------------------------------
r2 | jerry | 2013-08-17 20:40:43 +0530 (Sat, 17 Aug 2013) | 1 line
Initial commit
------------------------------------------------------------------------
r1 | jerry | 2013-08-04 23:43:08 +0530 (Sun, 04 Aug 2013) | 1 line
When Tom observes admin’s code, he immediately notices a bug in that. admin was not checking for array
overflow, which could cause serious problems. So Tom decides to fix this problem. After
modification, array.c will look like this.
#include <stdio.h>
#define MAX 16
int main(void)
int i, n, arr[MAX];
scanf("%d", &n);
if (n > MAX) {
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 66
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
fprintf(stderr, "Number of elements must be less than %d\n", MAX);
return 1;
scanf("%d", &arr[i]);
printf("\n");
return 0;
Tom wants to use the status operation to see the pending change-list.
svn status
M array.c
array.c file is modified, that's why Subversion shows M letter before file name. Next Tomcompiles and tests
his code and it is working fine. Before committing changes, he wants to double-check it by reviewing the
changes that he made.
svn diff
Index: array.c
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 67
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
===================================================================
--- array.c (revision 2)
+++ array.c (working copy)
@@ -9,6 +9,11 @@
printf("Enter the total number of elements: ");
scanf("%d", &n);
+ if (n > MAX) {
+ fprintf(stderr, "Number of elements must be less than %d\n", MAX);
+ return 1;
+ }
+
printf("Enter the elements\n");
Tom has added a few lines in the array.c file, that's why Subversion shows + sign before new lines. Now he is
ready to commit his changes.
Sending trunk/array.c
Transmitting file data .
Committed revision 3.
admin had committed the first version of the code. But he thinks that he should write two functions to accept
input and to display array contents. After modification, array.c looks as follows.
#include <stdio.h>
#define MAX 16
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 68
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
}
printf("\n");
}
int main(void) {
int i, n, arr[MAX];
return 0;
}
admin compiles and tests his code and is ready to commit changes. Before that, he wants to review the changes
using the following command.
svn diff
Index: array.c
===================================================================
--- array.c (revision 2)
+++ array.c (working copy)
@@ -2,6 +2,24 @@
#define MAX 16
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 69
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
+void display(int *arr, int n)
+{
+ int i;
+
+ for (i = 0; i < n; ++i)
+ printf("|%d| ", arr[i]);
+
+ printf("\n");
+}
+
int main(void)
{
int i, n, arr[MAX];
@@ -10,15 +28,10 @@
scanf("%d", &n);
return 0;
}
For the new added lines, Subversion shows + sign before line and for removed line it shows - sign. Now, Jerry
tries to commit the changes using the following command:
[jerry@CentOS trunk]$ svn commit -m "Add function to accept input and to display array
contents"
Sending trunk/array.c
svn: Commit failed (details follow):
svn: File or directory 'array.c' is out of date; try updating
svn: resource out of date; try updating
Subversion is not allowing to commit admin's changes, because Tom has already modified the repository
and Jerry's working copy is out of date. To avoid overwriting each other's changes, Subversion fails this
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 70
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
operation. admin must update working copy before committing his changes. So he uses update command as
shown below.
svn update
G array.c
Updated to revision 3.
Subversion is showing the letter G before filename, which means this file has been merged.
svn diff
Index: array.c
===================================================================
--- array.c (revision 3)
+++ array.c (working copy)
@@ -2,6 +2,24 @@
#define MAX 16
+
int main(void)
{
int i, n, arr[MAX];
@@ -15,15 +33,10 @@
}
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 71
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
+ accept_input(arr, n);
return 0;
}
Subversion is showing only admin's changes, but array.c file is merged. If you observe carefully, Subversion is
now showing revision number 3. In the previous output, it was showing revision number 2. Just review who
made changes in the file and for what purpose.
svn log
------------------------------------------------------------------------
r3 | tom | 2013-08-18 20:21:50 +0530 (Sun, 18 Aug 2013) | 1 line
Initial commit
------------------------------------------------------------------------
r1 | jerry | 2013-08-04 23:43:08 +0530 (Sun, 04 Aug 2013) | 1 line
Now admin's working copy is synchronized with the repository and he can safely commit his changes.
svn commit -m "Add function to accept input and to display array contents"
Sending trunk/array.c
Transmitting file data .
Committed revision 4.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 72
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Suppose admin accidently modifies array.c file and he is getting compilation errors. Now he wants to throw
away the changes. In this situation, 'revert' operation will help. Revert operation will undo any local changes to
a file or directory and resolve any conflicted states.
svn status
M array.c
cc array.c -o array
array.c: In function ‘main’:
array.c:26: error: ‘n’ undeclared (first use in this function)
array.c:26: error: (Each undeclared identifier is reported only once
array.c:26: error: for each function it appears in.)
array.c:34: error: ‘arr’ undeclared (first use in this function)
make: *** [array] Error 1
svn status
make array
cc array.c -o array
After the revert operation, his working copy is back to its original state. Revert operation can revert a single
file as well as a complete directory. To revert a directory, use -R option as shown below.
pwd
/home/jerry/project_repo
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 73
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Till now, we have seen how to revert changes, which has been made to the working copy. But what if you want
to revert a committed revision! Version Control System tool doesn't allow to delete history from the repository.
We can only append history. It will happen even if you delete files from the repository. To undo an old
revision, we have to reverse whatever changes were made in the old revision and then commit a new revision.
This is called a reverse merge.
Let us suppose Jerry adds a code for linear search operation. After verification he commits his changes.
svn diff
Index: array.c
===================================================================
--- array.c (revision 21)
+++ array.c (working copy)
@@ -2,6 +2,16 @@
#define MAX 16
Jerry is curious about what Tom is doing. So he checks the Subversion log messages.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 74
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
svn log
------------------------------------------------------------------------
r5 | tom | 2013-08-24 17:15:28 +0530 (Sat, 24 Aug 2013) | 1 line
After viewing the log messages, admin realizes that he did a serious mistake. Because Tom already
implemented binary search operation, which is better than the linear search; his code is redundant, and now
Jerry has to revert his changes to the previous revision. So, first find the current revision of the repository.
Currently, the repository is at revision 22 and we have to revert it to the previous revision, i.e. revision 21.
svn up
At revision 22.
SVN Branching
Branch operation creates another line of development. It is useful when someone wants the development
process to fork off into two different directions. Let us suppose you have released a product of version 1.0, you
might want to create new branch so that development of 2.0 can be kept separate from 1.0 bug fixes.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 75
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
In this section, we will see how to create, traverse and merge branch. admin is not happy because of the
conflict, so he decides to create a new private branch.
ls
branches tags trunk
svn status
A + branches/jerry_branch
Committed revision 9.
Now admin is working in his private branch. He adds sort operation for the array. Jerry's modified code looks
like this.
cd branches/jerry_branch/
cat array.c
#include <stdio.h>
#define MAX 16
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 76
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
flag = 0;
flag = 1;
temp = arr[j];
arr[j + 1] = temp;
int i;
scanf("%d", &arr[i]);
int i;
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 77
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
printf("\n");
int main(void)
scanf("%d", &n);
if (n >MAX) {
return 1;
accept_input(arr, n);
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 78
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
printf("Array has following elements\n");
display(arr, n);
bubble_sort(arr, n);
display(arr, n);
return 0;
admin compiles and tests his code and is ready to commit his changes.
make array
cc array.c -o array
./array
Meanwhile, over in the trunk, Tom decides to implement search operation. Tom adds code for search operation
and his code looks like this.
svn diff
Index: array.c
===================================================================
--- array.c (revision 10)
+++ array.c (working copy)
@@ -2,6 +2,27 @@
#define MAX 16
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 80
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
{
int i;
@@ -22,7 +43,7 @@
int main(void)
{
- int i, n, arr[MAX];
+ int i, n, ret, key, arr[MAX];
But Tom is curious about what admin has been doing in his private branch.
By viewing the Subversion's log message, Tom found that Jerry implemented 'sort' operation. Tom
implemented search operation using binary search algorithm, it always expects data in sorted order. But what if
the user provides data in an unsorted order? In that situation, binary search operation will fail. So he decides to
take Jerry's code to sort data before search operation. So he asks Subversion to merge code from admin's
branch into trunk.
cat array.c
#include <stdio.h>
#define MAX 16
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 82
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
flag = 0;
flag = 1;
temp = arr[j];
arr[j + 1] = temp;
low = 0;
high = n - 1;
return mid;
high = mid - 1;
else
low = mid + 1;
return -1;
int i;
scanf("%d", &arr[i]);
int i;
printf("\n");
int main(void)
scanf("%d", &n);
if (n > MAX) {
return 1;
accept_input(arr, n);
display(arr, n);
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 85
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
printf("Sorted data is\n");
bubble_sort(arr, n);
display(arr, n);
scanf("%d", &key);
if (ret < 0) {
return 1;
return 0;
After compilation and testing, Tom commits his changes to the repository.
make array
cc array.c -o array
./array
Enter the total number of elements: 5
Enter the elements
10
-2
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 86
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
8
15
3
Array has following elements
|10| |-2| |8| |15| |3|
Sorted data is
|-2| |3| |8| |10| |15|
Enter the element to be searched: -2
-2 element found at location 1
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 87
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Continuous Integration (Jenkins):
Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks
related to building, testing, and delivering or deploying software.
Jenkins can be installed through native system packages, Docker, or even run standalone by any machine with a
Java Runtime Environment (JRE) installed
Introduction
Why Jenkins?
Jenkins is a software that allows continuous integration. Jenkins will be installed on a server where the
central build will take place. The following flowchart demonstrates a very simple workflow of how Jenkins
works.
Along with Jenkins, sometimes, one might also see the association of Hudson. Hudson is a very popular open-
source Java-based continuous integration tool developed by Sun Microsystems which was later acquired by
Oracle. After the acquisition of Sun by Oracle, a fork was created from the Hudson source code, which brought
about the introduction of Jenkins.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 88
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
What is Continuous Integration?
Continuous Integration is a development practice that requires developers to integrate code into a shared
repository at regular intervals. This concept was meant to remove the problem of finding later occurrence of
issues in the build lifecycle. Continuous integration requires the developers to have frequent builds. The
common practice is that whenever a code commit occurs, a build should be triggered.
System Requirements:
JDK JDK 1.5 or above
Disk Space No minimum requirement. Note that since all builds will be stored on
the Jenkins machines, it has to be ensured that sufficient disk space is
available for build storage.
Java Container The WAR file can be run in any container that supports Servlet 2.4/JSP
2.0 or later.(An example is Tomcat 5).
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 89
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
CI-CD Stages
In this stage Jenkins is integrated with the remote version controlling system(git) in susch a way that
when ever developers make changes to the code it will detect those changes and download from the remote
repository
The code downloaded in the previous stage has to be converted into an artifact.This artifact can be in
the form of a jar,war,ear,exe file.This process is called as the build process and Jenkins will perform this step
with the help of plugins like ant,maven,ms build etc
The artifact created in the previous stage has to e deployed into QA servers.The testing servers might be
running on application servers like tomcat,jboss weblogic etc.The artifact has to deployed into these servers
where testers can access and test the application
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 90
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
4. Stage 4 (Continuous Testing)
The testers will prepare some automation testing programs using tools like selenium, tosca,codedui
etc.These testing programs will be uploaded by the testers into the git version controlling system.Jenkins should
download these programs and run them on the application that was deployed into the testing servers.If testing
fails jenkins will send automated notifiactions to the team memebers and developers should fix the defects and
upload the modified code into the git repository.Jenkins will again trigger the above 4 steps
If testing passes then jenkins will deploy the artifact into the production servers after taking approvals
from the team members.Once it is deployed into the prod servers the enduser/client can start accessing it.
Note: The first four stages are called Continuous Integration and the fifth stage is called continuous delivery
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 91
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
https://jenkins.io/download/
3 Install it
4 To open jenkins
localhost:8080
localhost:8080
4 Click on Managejenkins
6 Go to Git section
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 92
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Stage 1 (Continuous Download)
5 Click on Ok
7 Select Git
8 Enter the github url where developers have uploaded the code
https://github.com/selenium-saikrishna/maven.git
9 Click on Apply--->save
1 Open https://maven.apache.org/download.cgi
7 Go to Maven installations
12 Apply--->save
3 Go to Build section
8 Click on Apply--->save
9 Go to dashboard of jenkins
The above job will now create an artifact from the code that was downloaded in the previous stage.This
artifact comes in the format of a war file.
Configuring tomcat7:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 94
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
1 Open https://tomcat.apache.org/download-70.cgi
2 Go to binary distributions
5 Since jenkins and tomcat are running on the same machine and both use the 8080 port we should change the
port of either jenkins or tomcat
Open conf-->Openserver.xml
8080 to 8899
Open tomcatfolder
7 To start tomcat
localhost:8899
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 95
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
3 Go to Available section
7 Click on Configure
The artifacts created by Development job should be passed to Testing job so that the Testing job can deploy the
artifact into the prod environment
4 Go to Available Section
6 Install it
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 96
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
7 Open the dashboard of jenkins-->go to Development job
8 Click on Configure
13 Apply--->save
15 Click on Configure
16 Go to Build section
20 Apply--->save
5 Click on git
6 Enter github url where testers have uploaded the selenium testing programs
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 97
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
https://github.com/selenium-saikrishna/FunctionalTesting.git
9 Click on Apply--->save
This job will download the selenium testing programs from github and run them on the application that was
deployed in Stage no 3
The Development job should be linked with the Testing job so that once the Development is over it will start the
Testing
job.
7 Apply--->save
4 To start jenkins
4 Install tomcat7-admin
cd /etc/tomcat7
6 Restart tomcat7
ipaddress-of-linuxserver-where-jenkins-is-installed:8080
which java
Eg:
readlink -f /usr/bin/java
JAVA_HOME location
9 Go to GIT
which git
17 Enter MAVEN_HOME
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 101
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
To find this path
which mvn
readlink -f output-of-above-command
20 click on apply--->save
https://www.virtualbox.org/wiki/Downloads
https://www.vagrantup.com/downloads.html
vagrant --version
cd path_of_folder_where_vagrantfile_is_copied
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 102
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
7 vagrant up
Note1: installation and configuration of Jenkins in above vagrant is same as previous Linux servers since it is
also Linux server
Note2: ofter installing and configuring of Jenkins when the home page coming the functionalities of jenkins(ci-
cd) is same in any operating system.
5 enter no of instances as 3
12 Click on Create a new keypair-->enter some name for the key pair
Jenkins Management
To manage Jenkins, click on the ‘Manage Jenkins’ option from the left hand menu side.
So one can get the various configuration options for Jenkins by clicking the ‘Manage Jenkins’ option from the
left hand menu side.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 104
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 105
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Configure System
This is where one can manage paths to the various tools to use in builds, such as the JDKs, the versions of Ant
and Maven, as well as security options, email servers, and other system-wide configuration details. When
plugins are installed. Jenkins will add the required configuration fields dynamically after the plugins are
installed.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 106
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
instance to another, or archiving old build jobs, you will need to add or remove the corresponding build job
directories to Jenkins’s builds directory. You don’t need to take Jenkins offline to do this—you can simply use
the “Reload Configuration from Disk” option to reload the Jenkins system and build job configurations
directly.
Manage Plugin
Here one can install a wide variety of third-party plugins right from different Source code management tools
such as Git, Mercurial or ClearCase, to code quality and code coverage metrics reporting. Plugins can be
installed, updated and removed through the Manage Plugins screen.
System Information
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 107
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
This screen displays a list of all the current Java system properties and system environment variables. Here one
can check exactly what version of Java Jenkins is running in, what user it is running under, and so forth.
The following screenshot shows some of the name-value information available in this section.
System Log
The System Log screen is a convenient way to view the Jenkins log files in real time. Again, the main use of
this screen is for troubleshooting.
Load Statistics
This pages displays graphical data on how busy the Jenkins instance is in terms of the number of concurrent
builds and the length of the build queue which gives an idea of how long your builds need to wait before being
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 108
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
executed. These statistics can give a good idea of whether extra capacity or extra build nodes is required from
an infrastructure perspective.
Script Console
This screen lets you run Groovy scripts on the server. It is useful for advanced troubleshooting since it requires
a strong knowledge of the internal Jenkins architecture.
Manage nodes
Jenkins is capable of handling parallel and distributed builds. In this screen, you can configure how many
builds you want. Jenkins runs simultaneously, and, if you are using distributed builds, set up build nodes. A
build node is another machine that Jenkins can use to execute its builds.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 109
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Creating roles and assgning to users
5 install it
6 go to dashboard-->manage jenkins
10 apply-->save
11 go to dashboard of jenkins
16 for this employee in overall give read access and in view section give all access
17 go to project roles-->Give the role as developer and patter as Dev.* (ie developer role can access
18 similarly create another role as tester and assign the pattern as "Test.*"
20 apply--save
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 110
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
21 click on assign roles
24 go to item roles
27 apply-->save
If we login into jenkins as user1 we can access only the development related jobs and user2 can access only the
testing related jobs
Notifications in Jenkins:
whenever a jenkins job is executed we can send notifications to the team memebers.
2 Email notifications
Catlight Notifications
Cat light is a thried party client software which has to be installed on every team members machine.
1 Open https://catlight.io/downloads
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 111
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
3 Install it
of jenkins
A popup msg is displayed on the team members machine when the jenkins job is running.It will show the
status of the job as running/success/fail.
Email Notifications
3 click on Configure
8 click on apply--->save
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 112
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Triggering in Jenkins
3 Go to Build Triggers
6 Apply--->save
Scheduling the CI-CD to start whenever developer makes changes to the code and pushes into github
3 Go to Build Triggers
5 In Schedule section * * * * *
6 apply--->save
7 The developer should make some changes to the code and push in github
Server Maintanemce
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 113
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
The following are some of the basic activities you will carry out, some of which are best practices for Jenkins
server maintenance
URL Options
The following commands when appended to the Jenkins instance URL will carry out the relevant actions on
the Jenkins instance.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 114
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Set up Jenkins on the partition that has the most free disk-space – Since Jenkins would be taking source code
for the various jobs defined and doing continuous builds, always ensure that Jenkins is setup on a drive that has
enough hard disk space. If you hard disk runs out of space, then all builds on the Jenkins instance will start
failing.
Another best practice is to write cron jobs or maintenance tasks that can carry out clean-up operations to avoid
the disk where Jenkins is setup from becoming full.
Jenkins – Security:
In Jenkins you have the ability to setup users and their relevant permissions on the Jenkins instance. By default
you will not want everyone to be able to define jobs or other administrative tasks in Jenkins. So Jenkins has the
ability to have a security configuration in place.
Step 1 − Click on Manage Jenkins and choose the ‘Configure Global Security’ option.
Step 2 − Click on Enable Security option. As an example, let’s assume that we want Jenkins to maintain it’s
own database of users, so in the Security Realm, choose the option of ‘Jenkins’ own user database’.
By default you would want a central administrator to define users in the system, hence ensure the ‘Allow users
to sign up’ option is unselected. You can leave the rest as it is for now and click the Save button.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 115
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Step 3 − You will be prompted to add your first user. As an example, we are setting up an admin users for the
system.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 116
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Step 4 − It’s now time to setup your users in the system. Now when you go to Manage Jenkins, and scroll
down, you will see a ‘Manage Users’ option. Click this option.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 117
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Step 5 − Just like you defined your admin user, start creating other users for the system. As an example, we are
just creating another user called ‘user’.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 118
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Step 6 − Now it’s time to setup your authorizations, basically who has access to what. Go to Manage Jenkins
→ Configure Global Security.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 119
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Step 7 − If you don’t see the user in the user group list, enter the user name and add it to the list. Then give the
appropriate permissions to the user.
Click on the Save button once you have defined the relevant authorizations.
Note − For Windows AD authentication, one has to add the Active Directory plugin to Jenkins.
Jenkins – Backup:
Jenkins has a backup plugin which can used to backup critical configuration settings related to Jenkins. Follow
the steps given below to have a backup in place.
Step 1 − Click on Manage Jenkins and choose the ‘Manage Plugins’ option.
Step 2 − In the available tab, search for ‘Backup Plugin’. Click On Install without Restart. Once done, restart
the Jenkins instance
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 120
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Step 3 − Now when you go to Manage Jenkins, and scroll down you will see ‘Backup Manager’ as an option.
Click on this option.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 121
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 122
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Step 5 − Here, the main field to define is the directory for your backup. Ensure it’s on another drive which is
different from the drive where your Jenkins instance is setup. Click on the Save button.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 123
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Step 6 − Click on the ‘Backup Hudson configuration’ from the Backup manager screen to initiate the backup.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 124
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 125
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
To recover from a backup, go to the Backup Manager screen, click on Restore Hudson configuration.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 126
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
The list of backup’s will be shown, click on the appropriate one to click on Launch Restore to begin the
restoration of the backup.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 127
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
• Sometimes you might need several different environments to test your builds. This cannot be done by
a single Jenkins server.
• If larger and heavier projects get built on a regular basis then a single Jenkins server cannot simply
handle the entire load.
To address the above stated needs, Jenkins distributed architecture was introduced.
Jenkins uses a Master-Slave architecture to manage distributed builds. In this architecture, Master and Slave
communicate through TCP/IP protocol.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 128
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Jenkins Master
Your main Jenkins server is the Master. The Master’s job is to handle:
Jenkins Slave
A Slave is a Java executable that runs on a remote machine. Following are the characteristics of Jenkins Slaves:
Now let us look at an example in which Jenkins is used for testing in different environments like: Ubuntu,
MAC, Windows etc.
• Jenkins checks the Git repository at periodic intervals for any changes made in the source code.
• Each builds requires a different testing environment which is not possible for a single Jenkins server.
In order to perform testing in different environments Jenkins uses various Slaves as shown in the
diagram.
• Jenkins Master requests these Slaves to pe
Configure on slave:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 129
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Eg. Sudo chmod 777 slave.jar
5 create one newdir
Eg. Mkdir workspace
6 give full permissions to workspace
Eg. Sudo chmod 777 workspace
7 setup project based infrastrature that is what packages are rquired to execute project like git maven
8 set the password for user
Eg. Sudo passwd ubuntu
9 make password authendication no to yes in ssh configuration
Sudo vim /etc/ssh/sshd_config
Goto password authendication pattern and make yes to no and save (escape and :wq)
10 restart ssh service (sudo service ssh restart)
Configure on master:
BuildPipeline
This is a plugin jenkins which is used to get a better graphical view of the jobs.
1 Open the dashboard of jenkins--->Manage jenkins
2 Click on Manage Plugins--->Go to Available Section
3 Search for "BuildPipeline" plugin-->install it
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 130
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
4 Go to dashboard of jenkins--->Go to the location where all the jobs are listed--->Click on + icon
5 Enter some view name--->Select Build pipeline view
6 Go to Upstream / downstream config and select the initial job as development--->save
Code as Pipeline
This is a programatic way for perfroming CI-CD through jenkins.
We use a file called Jenkinsfile which is created using "groovy".
This jenkinsfile will be part of the code base that is created by the developer.
Whenever the developer makes any modifications to the code
the jenkinsfile will immediately trigger the CI-CD
Pipeline
Jenkins Pipeline (or simply "Pipeline" with a capital "P") is a suite of plugins which supports implementing and
integrating continuous delivery pipelines into Jenkins.
A continuous delivery (CD) pipeline is an automated expression of your process for getting software from
version control right through to your users and customers. Every change to your software (committed in source
control) goes through a complex process on its way to being released. This process involves building the
software in a reliable and repeatable manner, as well as progressing the built software (called a "build") through
multiple stages of testing and deployment.
The definition of a Jenkins Pipeline is written into a text file (called a Jenkinsfile) which in turn can be
committed to a project’s source control repository. This is the foundation of "Pipeline-as-code"; treating the CD
pipeline a part of the application to be versioned and reviewed like any other code.
Creating a Jenkinsfile and committing it to source control provides a number of immediate benefits:
• Automatically creates a Pipeline build process for all branches and pull requests.
• Code review/iteration on the Pipeline (along with the remaining source code).
• Audit trail for the Pipeline.
• Single source of truth for the Pipeline, which can be viewed and edited by multiple members of the
project.
While the syntax for defining a Pipeline, either in the web UI or with a Jenkinsfile is the same, it is generally
considered best practice to define the Pipeline in a Jenkinsfile and check that in to source control.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 131
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Declarative versus Scripted Pipeline syntax:
A Jenkinsfile can be written using two types of syntax - Declarative and Scripted.
Declarative and Scripted Pipelines are constructed fundamentally differently. Declarative Pipeline is a more
recent feature of Jenkins Pipeline which:
Many of the individual syntactical components (or "steps") written into a Jenkinsfile, however, are common to
both Declarative and Scripted Pipeline.
Why Pipeline?
Jenkins is, fundamentally, an automation engine which supports a number of automation patterns. Pipeline adds
a powerful set of automation tools onto Jenkins, supporting use cases that span from simple continuous
integration to comprehensive CD pipelines. By modeling a series of related tasks, users can take advantage of
the many features of Pipeline:
• Code: Pipelines are implemented in code and typically checked into source control, giving teams the
ability to edit, review, and iterate upon their delivery pipeline.
• Durable: Pipelines can survive both planned and unplanned restarts of the Jenkins master.
• Pausable: Pipelines can optionally stop and wait for human input or approval before continuing the
Pipeline run.
• Versatile: Pipelines support complex real-world CD requirements, including the ability to fork/join,
loop, and perform work in parallel.
• Extensible: The Pipeline plugin supports custom extensions to its DSL and multiple options for
integration with other plugins.
While Jenkins has always allowed rudimentary forms of chaining Freestyle Jobs together to perform sequential
tasks, Pipeline makes this concept a first-class citizen in Jenkins.
Building on the core Jenkins value of extensibility, Pipeline is also extensible both by users with Pipeline
Shared Libraries and by plugin developers.
The flowchart below is an example of one CD scenario easily modeled in Jenkins Pipeline:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 132
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Pipeline concepts:
The following concepts are key aspects of Jenkins Pipeline, which tie in closely to Pipeline syntax (see
the overview below).
Pipeline
A Pipeline is a user-defined model of a CD pipeline. A Pipeline’s code defines your entire build process, which
typically includes stages for building an application, testing it and then delivering it.
Node
A node is a machine which is part of the Jenkins environment and is capable of executing a Pipeline.
Stage
A stage block defines a conceptually distinct subset of tasks performed through the entire Pipeline (e.g. "Build",
"Test" and "Deploy" stages), which is used by many plugins to visualize or present Jenkins Pipeline
status/progress. [6]
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 133
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Step
A single task. Fundamentally, a step tells Jenkins what to do at a particular point in time (or "step" in the
process). For example, to execute the shell command make use the sh step: sh 'make'. When a plugin extends
the Pipeline DSL, that typically means the plugin has implemented a new step.
The following Pipeline code skeletons illustrate the fundamental differences between Declarative Pipeline
syntax and Scripted Pipeline syntax.
Be aware that both stages and steps (above) are common elements of both Declarative and Scripted Pipeline
syntax.
In Declarative Pipeline syntax, the pipeline block defines all the work done throughout your entire Pipeline.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 134
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Execute this Pipeline or any of its stages, on any available agent.
In Scripted Pipeline syntax, one or more node blocks do the core work throughout the entire Pipeline. Although
this is not a mandatory requirement of Scripted Pipeline syntax, confining your Pipeline’s work inside of
a node block does two things:
1. Schedules the steps contained within the block to run by adding an item to the Jenkins queue. As soon as
an executor is free on a node, the steps will run.
2. Creates a workspace (a directory specific to that particular Pipeline) where work can be done on files
checked out from source control.
Caution: Depending on your Jenkins configuration, some workspaces may not get automatically
cleaned up after a period of inactivity.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 135
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Execute this Pipeline or any of its stages, on any available agent.
Defines the "Build" stage. stage blocks are optional in Scripted Pipeline syntax. However,
implementing stage blocks in a Scripted Pipeline provides clearer visualization of each `stage’s subset of
tasks/steps in the Jenkins UI.
Pipeline example
Here is an example of a Jenkinsfile using Declarative Pipeline syntax - its Scripted syntax equivalent can be
accessed by clicking the Toggle Scripted Pipeline link below:
pipeline is Declarative Pipeline-specific syntax that defines a "block" containing all content and instructions
for executing the entire Pipeline.
agent is Declarative Pipeline-specific syntax that instructs Jenkins to allocate an executor (on a node) and
workspace for the entire Pipeline.
stage is a syntax block that describes a stage of this Pipeline. Read more about stage blocks in Declarative
Pipeline syntax on the Pipeline syntax page. As mentioned above, stage blocks are optional in Scripted
Pipeline syntax.
steps is Declarative Pipeline-specific syntax that describes the steps to be run in this stage.
sh is a Pipeline step (provided by the Pipeline: Nodes and Processes plugin) that executes the given shell
command.
junit is another a Pipeline step (provided by the JUnit plugin) for aggregating test reports.
node is Scripted Pipeline-specific syntax that instructs Jenkins to execute this Pipeline (and any stages
contained within it), on any available agent/node. This is effectively equivalent to agent in Declarative
Pipeline-specific syntax.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 137
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
}
Stage(‘continious build’)
{
Sh ‘mvn package’
}
Stage(‘continious deployement’)
{
Sh ‘scp artifact-ghenerated-location-on-dev username@qa-ip-address:qa-server-tomcat-webapps-location’
}
Stage(‘continious testing’)
{
Git ‘selenium-developer-git-repo-id’
}
}
Catch(exception E)
{
Send notification
}
Stage(‘continious delivery’)
{
Sh ‘scp artifact-ghenerated-location-on-dev username@prod-server-ip:qa-server-tomcat-webapps-location’
}
}
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 138
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
CI-CD using Declarative Pipeline:
Pipeline
{
Agent any
{
stages
{
Stage(‘continious download’)
{
Steps
{
Git ‘developers-id’
}
}
Stage(‘continious build’)
{
Steps
{
Sh ‘mvn package’
}
}
Stage(‘continious deployement’)
{
Steps
{
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 139
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Sh ‘scp artifact-ghenerated-location-on-dev username@qa-ip-address:qa-server-tomcat-webapps-location’
}
}
Stage(‘continious testing’)
{
Steps
{
Git ‘selenium-developer-git-repo-id’
}
}
}
Post
{
Success
{
Stage(‘continious delivery’)
{
Steps
{
Sh ‘scp artifact-ghenerated-location-on-dev username@prod-server-ip:qa-server-tomcat-webapps-location’
}
}
}
Failure
{
Send notification
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 140
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
}
}
}
}
BlueOcean Plugin
This is a new UI for Jenkins which will become the default interface of Jenkins in the coming months.This is
most useful for creating pipeline project
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 141
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Below is the general process that I’ve adopted after learning the fundamentals and working through some trial
and error. Follow these steps, editing any necessary information specific to your individual needs, and you
should be up and running with Vagrant in about 10 minutes or less!
1. Install VirtualBox
2. Install Vagrant
Note: the steps below are outlined as if the sample Vagrant file included in this post is used in its entirety —
meaning all file paths and constants referenced in that file will also be referenced throughout the instructions.
Please substitute as needed.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 142
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
1. Install VirtualBox
To grab the latest version of VirtualBox, head on over to the download pageand select the version appropriate for
your operating system. Download and install, following the prompts as you would any other program. And while
my article focuses mainly on my experiences with this workflow on OS X, the same principles and
concepts should apply to Windows. Once installed, let’s move our attention to Vagrant.
2. Install Vagrant
Now that VirtualBox is installed, let’s focus on getting Vagrant installed to your machine. Again, head over to
their download page and grab the version appropriate for your operating system. Much like above, download and
install, following the prompts as you would any other program.
Personally, I find that keeping directories for each Vagrant instance within my local Home directory is an easy to
remember and easy to manage experience.
For example, I’ve created a directory titled “new-vm” in my Home directory. This is the exact same value for
the VM_NAME constant found in the sample Vagrantfile in step 4. I then added the Vagrantfile specific to this
VM within that directory for provisioning.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 143
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
The first command changes to my Home directory and then creates the “new-vm” directory within Home. The
second command changes to the newly created directory and then creates the Vagrantfile within that new
directory.
~/new-vm/Vagrantfile
Now it’s time to review the sample Vagrantfile below, and make appropriate edits for your specific needs.
Sample Vagrantfile
The next step is to add some instructions within your Vagrantfile for Vagrant to execute during the virtual
machine provisioning process. To help expedite this process, and set a handful of the typical default items, below
is a sample Vagrantfile that will get you set up with a Ubuntu Linux development enviornment with Node.js and
Git. This file works through:
1. Setting several constants around Linux OS, directories, users, and networking between host/guest machines
2. Provisioning a virtual machine through VirtualBox, with 1 CPU, 512MB of memory, and 40GB of storage
space
3. Installing latest Git, Node 6.x, latest npm, and updating Ubuntu
Sample:
# encoding: utf-8
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Box / OS
VAGRANT_BOX = 'ubuntu/trusty64'
# Memorable name for your
VM_NAME = 'new-vm'
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 144
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
# VM User — 'vagrant' by default
VM_USER = 'vagrant'
# Username on your Mac
MAC_USER = 'John'
# Host folder to sync
HOST_PATH = '/Users/' + MAC_USER + '/' + VM_NAME
# Where to sync to on Guest — 'vagrant' is the default user name
GUEST_PATH = '/home/' + VM_USER + '/' + VM_NAME
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 145
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
SHELL
end
Now that you have reviewed this sample Vagrantfile, there are two paths you can choose to continue:
cd ~/new-vm
rm -r Vagrantfile
vagrant init
With your Vagrantfile in place, it’s time to provision your virtual machine!
cd ~/new-vm
vagrant up
During this process Vagrant will download ubuntu/trusty64 directly from Hashicorp’s Atlas and then provision
the virtual machine as specified in your Vagrantfile. Depending upon your Internet connection and computer
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 146
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
speed, the entire process should take around 3 to 5 minutes to complete. Once the virtual machine is provisioned,
you can log into your virtual machine with the following command:
vagrant ssh
This command will take care of connecting you directly to your VM via SSH. It handles the username and
password — which, by default, are both vagrant/vagrant.
The above, “vagrant up” and “vagrant ssh” will more than likely be the two de facto commands you’ll use for
initializing and accessing your VM. Below are a few more useful commands that will come in handy.
Sometimes we need to turn on, turn off, pause, or destroy our Vagrant managed virtual machines, especially after
rebooting or testing out new features, etc.
vagrant up
vagrant suspend
vagrant halt
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 147
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
To destroy your VM, navigate to the directory with your Vagrantfile:
vagrant destroy
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.ssh.insert_key = false
end
# control
app.vm.hostname = "control"
app.vm.box = "ubuntu/trusty64"
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 148
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
end
# Load Balancer.
app.vm.hostname = "lb"
app.vm.box = "ubuntu/trusty64"
end
# Application server 1.
app.vm.hostname = "orc-app1.dev"
app.vm.box = "ubuntu/trusty64"
end
# Application server 2.
app.vm.hostname = "orc-app2.dev"
app.vm.box = "ubuntu/trusty64"
# Database server.
db.vm.hostname = "orc-db.dev"
db.vm.box = "ubuntu/trusty64"
end
end
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.ssh.insert_key = false
end
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 150
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
# manager
app.vm.hostname = "Slave"
app.vm.box = "ubuntu/trusty64"
end
end
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.ssh.insert_key = false
end
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 151
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
# control
app.vm.hostname = "Jenkins"
app.vm.box = "ubuntu/trusty64"
end
# Load Balancer.
app.vm.hostname = "QA"
app.vm.box = "ubuntu/trusty64"
end
# Application server 1.
app.vm.hostname = "Prod"
app.vm.box = "ubuntu/trusty64"
end
end
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 152
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Virtualization
This is a process where it is posssible to run multiple OS's on one server. This is done thorugh an applcation
called hypervisor.
On the server(baremetal) we first install the Host OS and on top of it we install the hypervisor s/w(Vmware
esxi,Citrix xen,Microsoft Hyper-v etc).On the hypevisor we can install the Guest os and on the guest os we
install the appllications that we require.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 153
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
The problem with the above architecture is the applications running on the guest os have to pass through
multiple layers in order to access the h/w resources.also it is not possible to aalocate h/w resources dynamically
to the VM's depending on their requirement.
Docker Containarization
In docker we have a bare metal on top of which host OS is installed and on the host OS we install a s/w
application called "Docker engine".On the docker engine we can run any application as a container.The
advantage of this process is these applications have to pass through less number of layers to access the hardware
resources
Also docker engine can dynamically allocate h/w resources to individual contianers depending on how many
process are running on it
Through docker we achive what is called "process isolation" ie we seperate the application from its dependency
on the underlying OS and we create application running only on docker engine.These applications can then be
deployed on any OS where docker is running.
Docker can be installed only on Windows 10 Prof 64 bit version or Windows 2016 Server Edition
1 Open https://docs.docker.com/docker-for-windows/install/
Note: docker when installed on windows activates an application called Hyper-v.This application will not allow
any other virtualization s/w to run
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 154
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Installing docker on Linux
1 Open get.docker.com
sh get-docker.sh
An image is a collection of bin/lib that are necessary for an application to run. All the docker images are present
in the cloud site of docker called hub.docker.com
A Container is a running instance of the image. It is the indivdual application or process that docker has created
in our user space
Docker Components
Dcoker Host: This is the machine where docker is installed and all the docker images are downloaded.
Docker Client: This is the terminal of docker where we can fire the docker commands
Docker Deamon: This is a background preocess which takes the commands fired by docker client and sends
them to the docker images or contianers or docker registry
Docker Registry: This is the cloud site of docker where all the docker images are present. hub.docker.com
We can also create a private registry whcih can be accessed only by our organisation
1 To downlaod an image
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 155
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
docker pull image_name
docker images
or
docker image ls
docker container ls
docker ps -a
14 To restart a container
docker rm container_name/container_id
docker rm -f container_name/container_id
-it Used for opening an interactive terminal in the container where we can fire linux commands
-p Used for port mapping.It will link the container port with the docker host port.Container port is called
internal port and docker host port is called external port
Eg: -p 8080:80
Here 8080 will be docker host port and 80 will be container port
-P Used for automatic port mapping ie the internal port of container will be mapped with a port on docker
host and this external port will be greater than 30000
--volumes-from Used for creating reusable volumes that can be shared between containers
docker network ls
25 To delete a network
ctrl+p,ctrl+q
docker volume ls
33 To remove a volume
A container is a standard unit of software that packages up code and all its dependencies so the application runs
quickly and reliably from one computing environment to another
Options:
UseCase1:
Start an nginx container in detached mode and name it webserver. Map the external port of docker host 8080
with internal port 80 of container
ipaddress-of-dockerhost:8080
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 160
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
UseCase2:
Start a tomcat container and publish the port numbers,and git it a name mytomcat
1 Start tomcat
UseCase 3:
Start an ubuntu container and go into its interactive terminal. Fire some linux commands in it
exit
UseCase4:
Start mysql as a container. Go into its interactive terminal and login into the database,Create some sql tables
mysql -u root -p
Enter password
show databases;
use dbname;
Open
https://justinsomnia.org/2009/04/the-emp-and-dept- tables-for-mysql/
We can create our own docker images and save them in hub.docker.com or in our private docker registry
UseCase5:
Start a container frm this new image and we should find git
installed on it
2 In the container
apt-get update
exit
git preinstalled on it
In the container
git --version
Docker Volumes
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 163
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Since docker containers are for temporary usage, once the container is removed all the data stored in the
container will be lost.To preserve the data we can use docker volumes
UseCase6:
Stop and remove the container,we should still be able to access the files
1 Create a directory
mkdir /intelliq
In the container
cd intelliq
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 164
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
exit
docker rm myubuntu
cd path-of-source-folder
Share the volume or space from one container to another container as like shared memory
UseCase7:
Create a directory /intelliq and mount it on centos container c1. Create some files in the intelliq folder in the c1
container
These two containers should use the voulmes that are used by c1
1 Create a directory
mkdir /intelliq
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 165
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
docker run -it --name c1 -v /intelliq centos
In the c1 container
cd intelliq
3 Start another centos container c2 and this should use the volumes used by c1
In the c2 container
cd intelliq
4 Start another centos container c3 and this should use the volumes used by c2
In the c3 container
cd intelliq
5 Go into any of the three containers and we will see all the files created by all the three contaieners
docker attach c1
cd intelliq
ls
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 166
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Linking of Docker containers
1 --link option
2 Docker compose
3 Docker networking
--link option:
UseCase 8:
In c2 container
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 167
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Use case9:
Create a mysql container and link it with wordpress container.Once the linking is done a developer should be
able to create a wordpress website.
ipaddress-of-dockerhost:8080
UseCase 10:
ipaddress-of-dockerhost:5050
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 168
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
docker run -d --name prodserver –link jenkinsserver:jenkins -p 7070:8080 tomcat
ipaddress-of-dockerhost:6060
ipaddress-of-dockerhost:7070
UseCase11:
Start a jenkins container and link it with an ubuntu contianer.Make this ubuntu as a slave
ipaddress-of-dockerhost:8080
apt-get update
wget http://ipaddress-of-jenkinsserver:8080/jnlpJars/slave.jar
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 169
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Creating QA environment
Usecase12
Start 2 selenium node containers and link them with the selenium hub container
2 Start a node which has firefox installed on it and link with hub container
3 Start another node which has chrome installed on it and link with hub container
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 170
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Docker Compose
This is a feature of docker where we can create an architecture of multiple contianers according to the
requirmenets of the devlopment team, Qa team etc
All the containers that we want to start and link are given in the compose file in the form of services. All these
services can be started or stopped using one single command
chmod +x /usr/local/bin/docker-compose
docker-compose --version
Sample.yml file:
---
intelliq:
- trainers:
- sai:
- Course: Devops
- fee: 12000
- sheshi:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 171
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
- Course: AWS
- fee: 10000
- coordinator:
- shailaja
...
UseCase 13:
Create a docker compose file for linking a wordpress contianer with mysql contianer
vim docker-compose.yml
---
version: '3'
services:
intelliq-mysql:
image: mysql:5
environment:
MYSQL_ROOT_PASSWORD: intelliq
intelliq-wordpress:
image: wordpress
ports:
- 5050:80
...
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 172
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Save and quit(:wq)
docker-compose up -d
docker-compose stop
UseCase 14:
Create docker compose file for starting a jenkins contianer and link with two tomcat containers so that we can
implement CI-CD
vim docker-compose.yml
version: '3'
services:
jenkinsserver:
image: jenkins
ports:
- 6600:8080
qaserver:
image: tomcat
ports:
- 7700:8080
links:
- jenkinsserver
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 173
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
prodserver:
image: tomcat
ports:
- 8800:8080
links:
- jenkinsserver
docker-compose up -d
ipaddress-of-dockerhost:6600
ipaddress-of-docker-host:7700
ipaddress-of-docker-host:8800
UseCase15:
Create a docker compose file for setup of the QA environment.Create seelnium hub container and link it with
two node contianers
vim docker-compose.yml
version: '3'
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 174
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
services:
hub:
image: selenium/hub
ports:
- 4444:4444
firefox:
image: selenium/node-firefox-debug
ports:
- 5901:5900
environment:
HUB_HOST: hub
links:
- hub
chrome:
image: selenium/node-chrome-debug
ports:
- 5902:5900
environment:
HUB_HOST: hub
links:
- hub
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 175
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Dockerfile
This is a simple text file which is used for creating dockerimages. It uses a syntax called GO which has certain
predefined keywords
FROM This is generally the first statement in dockerfile and it is used to specify the base image from which
we are creating out dockerimages
MAINTAINER: This is the name of the person or the organisation that has created this dockerfile
CMD: This is the default instruction that gets executed when the container is started
ENTRYPOINT: This is used to pass arguments to the CMD instruction and it can also be used to specify
the default process that should be initiated when a container starts
RUN: This is used for package management ie installing or uninstalling s/w using apt or yum package
managements
ADD: This is used to copy files from the host machine to the docker container or to download some files from
a remote url
EXPOSE: This is used for specifing what internalport of the container has to exposed to the outside world
USER: This is used to specify the default user credentials through which we want to login into a container
WORKINGDIR: This is used to specify the directory where the CMD instruction should be executed
VOLUME: Used for attaching volumes to the docker container. This will become the default volume for the
container
Create dockerfile from ubuntu base image, specify the maintainer and give the default instruction to
execute
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 176
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
vim dockerfile
FROM ubuntu
MAINTAINER intelliq
CMD ["date"]
. represents current working dir ie it will read the dockerfile present in the current working dir and create an
image
Create a dockerfile from ubuntu base image and make the default process as reading /etc/passwd
vim dockerfile
FROM ubuntu
MAINTAINER intelliq
ENTRYPOINT ["/bin/cat"]
CMD ["/etc/passwd"]
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 177
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
docker build -t myubuntu .
vim dockerfile
FROM centos
MAINTAINER intelliq
git --version
CacheBusting
Docker will read the cache(memory) to check which instructions we executed previously. It will not execute the
commands that are already executed but reads the info from the cache. Only the new instructions will be
executed
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 178
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Example
FROM ubunut
The above docker file updates the apt repository and installs git on it.Now after a period of time if we update the
apt repository by adding some more statements like
Only the above new instruction gets executed. This might result in installing maven and tree from a repository
that was update long back.To overcome this problem we can use cache busting uisng &&
Create a dockerfile for installing packages and updating the apt repository using cache busting
vim dockerfile
FROM ubuntu
MAINTAINER intelliq
Create a dockerfile from jenkins baseimage and make the default user as root and also install git and
maven
vim dockerfile
FROM jenkins
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 179
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
MAINTAINER intelliq
USER root
Start this as a contaier and we will see that root is the default user and git and maven are installed
whoami
git --version
mvn --version
vim dockerfile
FROM ubuntu
MAINTAINER intelliq
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 180
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
ADD http://mirrors.jenkins.io/war-stable/latest/jenkins.war /root
Start a container
cd root
Create a dcokerfile from jenkins baseimage and make bash as the default process ie it we start this
contianer it should automatically go into the terminal of the container
1 vim dockerfile
FROM jenkins
MAINTAINER intelliq
ENTRYPOINT ["/bin/bash"]
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 181
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
We will directly go into the terminal of the container
Public registry:
Public registry is hub.docker.com and this is maintianed by docker community. To upload images in this public
registry we should create an account in the hub.docker.com
1 Open hub.docker.com
exit
docker login
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 182
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Enter username and password
Note: do you want to push to docker registry the image must be taged with account name/id..(ex. intelliq/httpd-
centos)
Private Registry:
This is a local docker registry that is maintained by individual organisations and only the organization team
memebers can access it
This local registry can be create by using a docker image called "registry"
UseCase:
Docker Networking
1 Bridge
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 183
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
2 Hostonly
3 None or Null
4 Overlay
For containers to communincate with each other or with the outside world we can use docker networks
Bridge Network: Bridge network is the default network of docker containers that are running on a single
docker host
Host network: Host only network is used to create container that can communicate only with the host machine
None or Null Network: None network is used for creating isolated contianers ie these containers cannot
communicate with the host machine or with other containers
Overlay network: Overlay network is used when contianers are running in a distributed network ie multiple
containers are running on multiple docker hosts and all these containers are communicate with each other(eg
docker swarm,docker stack etc)
UseCase:
c1 and c2 should be on intelliq1 network so they will be ablt to ping to each other
Now assign c2 to intelliq2 network ie c2 is present on both intelliq1 and intelliq2 network
Beacuse c2 is present on both the networks it should ping to both c1 nad c3 but c1 and c3 should not be able to
communicate with each other
1 Create 2 networks
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 184
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
2 Start a busybox container c1 on intelliq1 network
docker inspect c1
In the c2 container
docker inspect c2
In the c3 container
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 185
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
8 Since c2 is running on both intelliq1 and intelliq2 networks it will ping to both c1 and c3
docker attach c2
9 Go into c1 container
docker attach c1
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 186
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Docker Swarm
This is a tool of docker for performing container orchestration.
When we want to run multiple contianers in a distributed network we want a single service to run on all of them
we can used docker swarm
Advantages:
Autoscalling of contianers
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 187
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Install docker on all of them
The main machine where we create the swarm is called as manager and the rest of machines are called workers
This machine now becomes the manager and it also displays the command that should be used for workers to
join swarm
docker node ls
docker service ls
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 188
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
To see the list of nodes on which the webserver service is running
Eg
The above command will show the output in JSON file format
We can increase or decrease the number of replicas on which a service is running based on the business
requirement.This can be done in swarm without having any downtime
To see the list of nodes on which these 6 mysql replicas are running
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 189
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
docker service ps mysql
Swarm can update any service running without having any downtime. It achives this task by performing the
updates in a rolling manner ie it will first update on one replica and once the update is totally done on it it will
move to another replica.
If we run "docker service ps mydb" we will see that all the containers with redis:3 are shut down and in its
place redis:4 containers are running
If we run "docker service ps mydb" we will see that all the containers with redis:4 are shut down and in its
place redis:3 containers are running
Start tomcat with 5 replicas in the swarm. Drain a worker from swarm and check if all the 5 replicas of tomcat
are running or not
docker node ls
5 We will still see all the 5 replicas of tomcat running on manager and other workers
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 191
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
docker swarm join-token worker
Bydefault swarm uses overlay network ie all the services that we start in swarm will be using overlay network
and they can communicate with each other.
If we want different services in swarm to run on different overlay networks we can create those overlay
networks and assign them to the services in swarm
Sceanrios
Docker Stack
A stack is a group of interrelated services that share dependencies with each other and they can be scaled or
orchestrated together.
docker stack ls
To remove a stack
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 193
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Kubernetes
This is the container archestration tool similar to docker swarm. By using this kubernets we can handled
scenario like load balancing, scaling, failover scenarios, rolling updates.....etc.
Node:
This is machine which is part of kubernets cluster which take care of Container archestration it can be master or
slave.
Cluster:
This is the combination of multiple nodes. master machine is where the kubernet service is deployed.
Slave machine take load and perform container archestration
Master has “kube-api” server which is responsible for managing nodes
Slave has “kubelet” which accepts load from manager
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 194
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Kubectl:
Kubectl is an application which is used running kubernets commands
Kubeadmin:
Kubeadmin is used for setting master and slave in the kubernets cluster.
Kubernets setup
1. Open https://labs.play-with-k8s.com/
2 Login using github credentials or dockerhub crendentials
3 click on add new instance (create 3 such instances)
One is for master and two is for slave
4 go to node master it is the node1
5 To initialize the kubernets on master
kubeadm init --apiserver-advertise-addr $(hostname -i)
6 To create cluster responsible for managing kubernets
Kubectl apply –n kube-system –f https://cloudweave.works/k8s/net2k85 -versin=$(kubectl version/base 64)
\n’);
In kubernets containers are always present in Pod. A single Pod can run single instance of container and
multiple instances of container
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 195
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Pods are controlled by another application called controller
Deployment
Deployement is the high level service which is responsible for maintaining the controllers, Pots and container
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 196
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Kubernet run msql –-image mysql:5 --env MYSQL_ROOT_PASSWORD=intelliq
To delete a Deployement
kubectl delete servicename
apiVersion :
it is the version of pod object
kind:
it’s represent kind of object that getting created. That is pod, controller, service..etc
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 197
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
metadata:
Data about object created with this YAML file is stored here. It is also contains information related to label
This label can be used for filtering and serching for specific pods are deployement
Spec:
Kind : version
Pod : v1
Service : v1
Replicaset : apps/v1
Deployement : apps/v1
apiVersion: v1
kind: pod
metadata:
name: myapp-pod
labels:
app: myapp
type: front-end
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 198
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
spec:
containers:
- Name: httpd-containers
Image: httpd
Create pod-definitionfile which uses postgress image and starts container with name called myapp-
postgress
Vim pod-definition.yml
apiVersion: v1
kind: pod
metadata:
name: myapp-postgress
labels:
app; helloapp
tier: db-tier
spec:
containers:
- Name: mypost
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 199
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Image: postgress
Create poddefinitionfile for starting mysqwl as container and container name mydb and pass
environment variable and pod name is myapp-mysql
Apiversion: v1
Kind: pod
Metadata:
Names: dbname
Labels:
Spec:
Containers:
- Name: mydb
Image: mysql
Env:
- name: MYSQL_ROOT_PASSWORD
Value: intelliq
Run:
Kubectl created –f pod-definitionfile.yml
Start jenkins as container with in a pod the name of container should be myjenkins. Map container port
8080 and hostport 5050 and give name of pod as app-jenkins
Vim pod-definitionfile.yml
---
apiVersion: v1
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 200
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
kind: pod
metadata:
name: app-jenkins
labels:
ci:cd
spec:
containers:
-name: myjenkins
Image: jenkins
Ports:
Containerport: 8080
Hostport: 5050
Run:
Kubectl created –f pod-definitionfile.yml
Controllers
These are used for maintaining state of the ports and they can be implemented using replication controller and
replicasets
Replication controller:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 201
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Apiversion: v1
Kind: ReplicationController
Metadata:
Name: rc-tomcat
Spec:
Containers:
Replicas: 3
Template:
Metadata:
Name: app-tomcat
Labels:
App: tomcat
Spec:
Containers:
- Name: mytomcat
Image: tomcat
Ports:
Containerport: 8080
Hostport: 7070
Replicatin Set:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 202
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
This is another form of controller which is similar to replication controller but it has the additional field called
sector which is declared in spec section of the YAML file.
This helps replicatin controller acuire any pots with the same sectors and adds them to the kubernets cluster. It
is also contains replicas section similar to the replication controller which tells how many replicas maintained at
any point of time.
The replication set keeps on creating and deleting replicas to match the replica count
Whenever new pot as to be created the replication controller uses it’s template which contains the container
information
The link between it’s replica set and it’s pots is maintained by via it’s meta data section
Replicaset ansures that any point of time specifies the number of replicas are running in the cluster.
Note:
Replicaset are generally not used in scenarios where update operations have to be done on the application.
Replicationset file:
Replicationset file for launching php redis based image with 3 replicas
Vim replicatinse.yml
---
apiVersion: apps/v1
kind: Replicaset
metadata:
name: frontend
labels:
app: gestbook
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 203
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
tier: frontend
spec:
replicas: 3
selector:
matchlabels:
tier: frontend
template:
metadata:
labels:
tier: frontend
spec:
containers:
- Name: php-redis
Image: gcr-io/google_sample/gb_frontend:u3
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 204
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Deployement objects in kubernets
Controller objects like replicaset, replicationcontroller...etc are controlled by the deployement object. The
deployement object can also contain a selector field like replicasets where it can capture the pots with the same
selector and add them to the kubernets cluster.
It also contain the replica count which always maintain by the deployement by creating or deleting pots.
The main advantage of deployement over controller is deployements are dynamic where controller are statics.
That is the application deployed via controllers can not be upgraded to newer version. Where as deployement
can be upgraded.
Deployemetfile:
---
apiVersion: apps/v1
kind: Deployement
metadata:
name: frontend
labels:
app: nginx
tier: frontend
spec:
replicas: 3
selector:
matchlabels:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 205
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.9
ports:
- ContainerPort:80
To update the existing version of nginx running in the cluster in some another version
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 206
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Configuration Management Tool (Ansible)
The goals of Software Configuration Management are generally Configuration, Identification, Configuration
idioms and baselines, configuration control, implementing a control change process.
This is usually achieved by setting up a change control board whose primary function is to approve or reject all
change request that is sent against any baseline. Configuration status accounting, reporting and recording all the
necessary information on the status of the development process.
Cooperating Enablement: This feature helps to make the change configuration throughout the infrastructure
with one change.
Version Control Friendly: With this feature, the user can take their choice of version for their work.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 207
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Enable Change Control Processes: As Software Configuration Management tools are version control and
textual friendly we can make changes in code. Changes can be made as a merge request and send for review
Ansible is an open source configuration management and orchestration utility. It can automate the configuration
of remote hosts are virtual machines using ansible it is possible to lunches or shutdown multi-tiered architecture
due to this reason ansible is used for performing rolling updates with 0% downtime. Instead of creating shell
scripts for management remote servers ansible uses plays. A play is collection of task that should be performed
on remote host a file which contains these plays are called as ansible playbooks.
Ansible uses agent less architecture i.e. ansible pushes its tasks via ssh so it does not require any agent to be
installed on the manage hosts.
Note:
Ansible requires python to be installed on all the machines
Managed Hosts or managed Nodes: these are the remote machines which will be controlled by ansible.
Disadvantages of Ansible:
It cannot perform installation of the basic o/s.
It cannot monitor the changes done on the remote host.
2 The main machine where ansible is installed is called controller the remaining remote servers that ansible
configures are called manged hosts.
3 Establish passwordless ssh between the controller and the managed hosts
4 To install ansible
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 208
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
b) Update the apt repository
c) Install software-properties-common
f) Install ansible
ansible –version
Note: Install the same version of python in all managed and controller nodes
Ansible store all the remote managed hosts info in a file called as inventory file.
/etc/ansible/hosts
Open this file and add the ipaddress of all the managed hosts
10.10.10.72
10.10.10.73
10.10.10.74
10.10.10.75
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 209
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Save and quit
Modules in ansible
Ansible performs remote configuration of servers by using in built modules. These have been created using
python. Each module is deigns for performing a specific task
command : This is the default module of ansible and it is used to fire linux commands on the remot managed
nodes
shell : This is used for running shell scripts and linux commands that involve redirection and piping
copy : Used for copying files from the controller to the managed nodes
fetch : Used to copying files from the managed nodes to the controller
user : Used for usermanagement on the managed hosts ie creating,modifying and deleting users.
apt : Used for package management on the managed nodes ie installing,upgrading uninstalling etc.It works on
ubuntu,debain based linux flavours.
git : This is used for perfroming git version controlling on the managed nodes
stat : this is used to check the info about files and directories on the managed nodes.
ec2 : This is used for creating ec2 instances on the aws cloud
docker_image : This is used for executing the commands of docker that are related to docker images
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 210
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
docker_container : This is used for container management on the managed nodes
docker_login : Used for loginin into hub.docker.com from the managed nodes.
Command module
Shell Module
ansible command to execute ls -la on managed nodes and save the output into a file called file1 on on the
managed node
Copy Module
ansible command to copy a file and also change its ownership groupownership and premissions
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 211
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
ansible all -m copy -a 'src=myinventory dest=/tmp owner=Anu group=root mode=700' -b
Note: -b stands for become. It is used for giving higher previlages to execute a command on the managed nodes
File Module
This is used for creating files and directories on the managed nodes
File module can also be used for changing the permissions of files and also the ownership and groupownership
of files
apt module
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 212
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
state=latest is for upgrading to latest version
To install apache2 after updating the apt repository on all managed nodes
Service module
uri Module
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 213
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Git module
Install git on all managed nodes and download a remote git repository
Setup module
This is used to capture system facts that is system information.
$ ansible all –m setup
To find information about one variable we can give that variable name as on argument
Ext; to find the kernel on remote machine is running
$ ansible 192.168.60.101 –m steup –a ‘filter=facter_kernel’
Fetch module
To fetch a file from manage nodes into the controller machine we can use fetch module.
$ ansible all –m fetch –a ‘src=/home/vagrant/file1 dest=/home/vagrant’
1 Adhoc commands
2 Playbooks
3 Roles
Adhoc Commands
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 214
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Configuing apache2
Install apache2 on one mnaaged node and edit the content of its default index.html file,Restart apache2 and
check if this is reachable from all other managed nodes
Ansible playbook
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 215
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
The ansible commands that we have execute till now are called has ad-hoc commands and they are useful for
only performing single operation and they can work only on a single setup arguments they cannot be used for
complex configuration activities.
Ad-hoc commands can execute only one module at time to work on multiple modules we can use playbooks.
Playbooks are created in yamil format
Playbooks are powerful and flexible for performing cm
Using playbooks we can change lengthy and complex at administrative activities in to repeatable routines
Ansible playbooks are combination of plays each play defines set of operation that should be performed on
manage nodes these operation are called as tasks and managed nodes called as hosts.
Each task execute specific modules the modules are executed in the order In which we present in the playbooks.
vim playbook1.yml
---
- name: Installing tree
hosts: all
tasks:
- name: tree installation
apt:
name: tree
state: present
- name: git install
apt:
name: git
state: present
...
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 216
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Save and quit
To execute the playbook
ansible-playbook playbook1.yml -b
Vim plavybook2.yml
---
- name: User Creation
hosts: all
tasks:
- name: Creating users
user:
name: Lakshmi
password: intelliq
home: /home/vagrant/Lakshmi
shell: /bin/bash
...
Ansible playbbok for craeting directory and copy passwd file to that dirctory on all managed nodes
---
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 217
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
- name: Creating dir and copying the passwd file
hosts: all
tasks:
- name: Creating dir
file:
name: /tmp/newdir
state: directory
- name: Copying passwd file
copy:
src: /etc/passwd
dest: /tmp/newdir/passwd
...
Ansible playbbok for installing git and download from github repository
---
- name: Install git and download a remote repo
hosts: all
tasks:
- name: Install git
apt:
name: git
state: present
- name: Download the remote repo
git:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 218
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
repo: https://github.com/selenium-saikrishna/maven.git
dest: /tmp/git1
...
Create an ansible playbook for going to the manage nodes and fetching the all the users who are using
/bin/bash shell
---
- name: for capturing user eiht /bin/bash/ shell
hosts: all
tasks:
- name: Capturing info from /etc/password
shell: grep /bin/bash /etc/passwd > file1
- name: Fethcing files
fetch:
src: /home/vagrant/file1
dest: /home/vagrant
....
Install apche2 on one manage node start apache2 service and check the url response.
---
- name: creating users and capturing username and home dir
hosts: 192.168.60.2
become: yes
tasks:
- name: update apt repo and install apache2
apt:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 219
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
name: apache2
state: present
update_cache: yes
- name: starting apache service
service:
name: apache2
state: started
- name: checking url response
uri:
url: http://192.168.60.101
status: 200
...
---
- name: installing apache2
hosts: 192.168.60.1
tasks:
- name: installing apache2
apt:
name: apache2
state: present
- name: installing git
hosts: 192.168.60.2
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 220
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
tasks:
- name: installing git
apt:
name: git
state: present
...
Note: the playbooks we have created till now are working only on group hosts that is the entire paly is getting
executed on that group of hosts. To perform different activity’s on different group hosts we can create multiple
plays in playbook.
Variables
Variables are classified into 3 types
1) Global scope: these variables are defined from the command prompt and they can affect the complete
playbook.
2) Host scope: these variables are defied with respect the hosts and it can affect all the plays with in the
3) Play scope: These are defined at the level of induvial play and they can effect only that particular play.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 221
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
apt:
name: "{{a}}"
state: "{{b}}"
update_chache="{{c}}"
...
To run this playbook command prompt for installing maven without updating the repository:
$ ansible-playbook playbook12.yml --extra-vars “a=maven b=present c=no” -b
Similarly we can use the same the playbook for uninstalling git after updating apt repository.
$ansible-playbook playbook12.yml – extra-vars “a=git b=absent c=yes” –b
Create an ansible playbook for creating files or directories on the manage nodes and also for controlling
the ownership groupowenership and permissions by passing values through global scope variable
Vim playbook13.yml
---
- name: creating files and directories
hosts: all
tasks: file creating/ dir creation and controlling ownership
file:
name: "{{a}}"
state: "{{b}}"
owner: "{{c}}"
group: "{{d}}"
mode: "{{e}}"
...
Vim playbook14.yml
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 222
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
- name: creating files and directories
hosts: all
tasks: file creating/ dir creation and controlling ownership
file:
name: "{{name}}"
state: "{{state}}"
owner: "{{owner}}"
group: "{{group}}"
mode: "{{mode}}"
...
Note: global scope have the highest presidency compare host scope and play scope.
Create an ansible playbook for installing apache2 on all manage nodes after updating the apt repository
---
- name: package installation/uninstallation
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 223
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
hosts: all
vars:
- a: apache2
- b: present
- c: yes
tasks:
- name: installing/uninstallation
apt:
name: "{{a}}"
state: "{{b}}"
update_chache: "{{c}}"
...
Note: if we execute above playbook the variable values arr taken from variable section in this playbbok but we
overide these variable with global scope variables since blobal scope variable have high priority
cd path_of_folder_where_playbooks_are_present
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 224
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
mkdir group_vars
3 Create a file whose name should be similar tothe group name in our inventory file
vim webserver
---
a: Radha
b: intelliq
c: /home/vagrant/Radha
...
4 Change dir back to the fodler where the playbooks are present
cd ..
vim playbook10.yml
---
hosts: webserver
tasks:
user:
name: "{{a}}"
password: "{{b}}"
home: "{{c}}"
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 225
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
...
ansible-playbook playbook10.yml -b
cd path_of_playbooks_folder
mkdir host_vars
cd host_vars
4 Create a file whose name is same as an ipaddress of one machine in the inventory file
vim 10.10.10.74
---
a: tree
b: present
c: no
...
5 vim playbook11.yml
---
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 226
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
- name: Installing tree
hosts: 10.10.10.74
tasks:
apt:
name: "{{a}}"
state: "{{b}}"
update_cache: "{{c}}"
...
Variable Priorities
1 Global scope
Loops in ansible
1 with_items
2 with_sequence
with_items is used to pass data to the module and depending on how many sets of data are present with_items
will loop those many number of times
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 227
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
with_sequence is used to run a module specific number of times based on a count
vim playbook12.yml
---
hosts: 10.10.10.74
tasks:
apt:
name: "{{item}}"
state: present
update_cache:
with_items:
- tree
- git
- apache2
...
Playbook for creating multiple users and copying some files into the users home dir
---
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 228
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
- name: Creating user and copying files
hosts: all
tasks:
user:
name: "{{item.a}}"
password: "{{item.b}}"
home: "{{item.c}}"
with_items:
copy:
src: "{{item.a}}"
dest: "{{item.b}}"
owner: "{{item.c}}"
group: "{{item.d}}"
with_items:
...
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 229
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Ansible Roles
Roles provide a framework for fully independent, or interdependent collections of variables, tasks, files,
templates, and modules.
In Ansible, the role is the primary mechanism for breaking a playbook into multiple files. This simplifies
writing complex playbooks, and it makes them easier to reuse. The breaking of playbook allows you to
logically break the playbook into reusable components.
Each role is basically limited to a particular functionality or desired output, with all the necessary steps to
provide that result either within that role itself or in other roles listed as dependencies.
Roles are not playbooks. Roles are small functionality which can be independently used but have to be used
within playbooks. There is no way to directly execute a role. Roles have no explicit setting for which host the
role will apply to.
Top-level playbooks are the bridge holding the hosts from your inventory file to roles that should be applied to
those hosts.
cd /etc/ansible/roles
Note: role is created with apache after executing above command. Using tree see the role stracture(tree apache)
a)cd apache/tasks
---
- include: install.yml
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 230
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
- include: configure.yml
- include: check_url_response.yml
...
---
apt:
name: apache2
state: present
update_cache: yes
...
---
copy:
src: index.html
dest: /var/www/html/index.html
notify:
restart_apache2
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 231
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
...
---
- name: check_url_reponse
uri:
url: http://10.10.10.74
status: 200
...
managed nodes
cd ..
cd files
<html>
<body>
<h1>Intelliq</h1>
</body>
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 232
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
</html>
cd ..
cd handlers
---
- name: restart_apache2
service:
name: apache2
state: restarted
...
cd ..
cd ..
---
hosts: all
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 233
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
roles:
- apache
...
ansible-playbook configure_apache2.yml -b
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 234
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Nagios
Continious Monitoring
Continuous monitoring is a process to detect, report, respond all the attacks which occur in its infrastructure.
Once the application is deployed into the server, the role of continuous monitoring comes in to play. The entire
process is all about taking care of the company's infrastructure and respond appropriately.
Nagio is a free to use open source software tool for continuous monitoring. It helps you to monitor system,
network, and infrastructure. It is used for continuous monitoring of systems, applications, service and business
process in a DevOps culture.
Nagios runs plugins stored on the same server. It plugin's connects with a host or another server on your
network or the Internet. Therefore, in the case of failure Nagios core can alert the technical staff about the
issues. So that, your technical team performs the recovery process before outage in the business processes.
Features of Nagios
Following are the important features of Nagios:
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 235
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
• Ability to define event handlers which runs during service or host events for proactive problem
resolution
• Support for implementing redundant monitoring hosts
Nagios Architecture
Nagios is a client-server architecture. Usually, on a network, a Nagios server is running on a host, and plugins
are running on all the remote hosts which should be monitored.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 236
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
1. The scheduler is a component of server part of Nagios. It sends a signal to execute the plugins at the
remote host.
2. The plugin gets the status from the remote host
3. The plugin sends the data to the process scheduler
4. The process scheduler updates the GUI and notifications are sent to admins
Plugins
Nagios plugins provide low-level intelligence on how to monitor anything and everything with Nagios Core.
Plugins operate acts as a standalone application, but they are designed to be executed by Nagios Core. It
connects to Apache that is controlled by CGI to display the result. Moreover, a database connected to Nagios to
keep a log file.
• Check_nt is a plugin to monitor a windows machine which is mostly available in the monitoring server
• NSClinet++ should be installed in every Windows machine that you wants to monitor
• There is an SSL connection between the server and the host which continuously exchange information
with each other
Likewise, NRPE(Nagios Remote plug-in Executor) and NSCA plugins are used to monitor Linux and Mac OS
X respectively.
GUI
An interface of Nagios is used to display in web pages generated by CGI. It can be buttons to green or red,
sound, graph, etc.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 237
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
When the soft alert is raised many times, a hard alert is raised, then the Nagios server sends a notification to the
administrator.
1 Launch two ec2 instances in aws one name is as nagios-server and another one is remote-server
2 open the concole of nagios server
3 sudo apt-get update
4 sudo apt-get upgrade
5 sudo apt-get install nagios3
Note: to see the home page of nagios (hhtp://nagios-server-public-ip/nagios3)
6 sudo vim /etc/nagios3/nagios.cfg
Search for extenal_commands and changed 0 to 1
7 sudo vim /etc/group
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 238
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Search for nagios and add www.data at the end of statement
8 sudo chmod g+w /var/lib/nagios3/wr
9 sudo chmod g+w /var/lib/nagios3
10 sudo service apache2 restart
11 sudo service nagios3 restart
1 cd /etc/nagios.conf.d (this is the folder where all remote server configurations are present)
2 create new file (sudo vim remote-server) and write below nagios configuration code
define host
{
host_name remote-server-dns
alias remote-server
address remote-server-ip
max_check_attempts 3
check_period 24*7
check_command check-host-alive
contracts root
notification_interval 60
notification_period 24*7
}
Note: the above code you found (http://www.theurbanpenguin.com/nagios-defining-a-new-host/)
3 To check if the above file is added to the list of configurations or not
Sudo nagios3 –v /etc/nagios3/nagios.cfg | less
4 sudo /etc/init.d/nagios3 restart
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 239
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Active and passive checks
Nagios perform two kind of checks on remote server Active and passive
Active checks are initiated by nagios server and ther perform fixed frequency as specified in the nagios server
Passive checks are initiated by remote servers and they send notification to the nagios server
Note: chech the remote server status and logs by going hhtp://nagios-server-public-ip/nagios3
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 240
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Agile scrum
Scrum is an incremental and iterative model which promises more return on investments.
In scrum the complete software is divided into modules each module is developed, tested and delivered to the
client with in a time span of 2 to 4 weeks.
This is called as sprint. At the end of the sprint the one module of s/w to client in swapped ready state. Then it is
client can start using this module.
This sprint is farther divided into smaller sub sprints as small sprint as 24hours
Continuous monitoring of the client will be present on all the sprints.
Scrum team
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 241
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
System testers 1 - 2
Developer – 1 - 2
Testers – 1 – 2
Devops admin 1 - 2
The entire scrum team discusser with product owner to understand his requirements and these requirements
are created in the form of “user stories”.
The collection of all these user stories is called as product Backlog”
Once the product backlog is finalised the scrum team prioritizes the user stories.
Highest priority user stories will go with first sprint and so on…
This priority can be done in MoSCoW principle.
Mo – must have
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 242
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
S – Should have
Co – couldn’t have
W – Wouldn’t have
Any user story with Mo priority is considered as highest priority and should be delivered in first sprint
User stories with s priority go with second sprint
User stories with Co priority go with 3rd sprint
Wouldn’t assign to user stories which are eliminated
Agile ceremonies
1) Sprint plan meeting: this is the one day meeting conducted by scrum master and here work allocation is
done from all team members.
2) Scrum meeting or standard : this is conducted every day where is scrum team members should
discourse with product owner what work done on yesterday and what we work plan today suggestions
from the product owner should be implemented
3) Sprint retrospective: this meeting conducted is end of every sprint and here scrum team members will
analyse the drawback they faced in previous sprint and suggest solution overcome.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 243
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Scrum Board: it is present in the conference room where scrum meeting are conducted. It contains 3
sessions
1) To do
2) In progress
3) done
Initially all the user stories posted in to do section in the form sticky notes as the sprint progresses it
moves into in program and done section this gives transparency to all the scrum team members and they
will clearly know how the sprint is progressing.
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 244
DevOps Material
Mr.SaiKrishna,17yrs exp,Corporate Trainer IntelliQ IT Trainings
Address: # 502, 5th Floor, Manjira Squre Building, Opp to Prime Hospital, Above Udipi Park Hotel, Mytrivanam,
Ameerpet, Hyderabad. Phn : 7995857022, 9133507542, 9014663488 Page 245