Devops Lab Manual
Devops Lab Manual
CP08-IV-SEMESTER
DEVOPS
LAB MANUAL
Prepared by:-
Ranjitha M
Approved by:
Program Manager – CP08
DEVOPS LAB MANUAL
2.2 Creating new repository and commit the codes to newly created repository
2.3 Importing the codebase from different Github account to your Github account
5.2
Directory Manipulations commands
DEVOPS LAB MANUAL
5.3 Use common commands for working with files and directories
5.4
Installing Software in Linux CLI
5.5
Sending E-mails
6.0 Create AWS Resources with Terraform 8
7.3 Create the Stack and choose template for launching instance
8.1 Build the infrastructure and automate code deployment for a PHP application with
OpsWorks
8.4 Execute other commands – Undeploy, Rollback, Start Web Server, Stop Web
Server, Restart Web Server
10.1 Use application source files to create Docker container images and place them in
Amazon ECR
10.2 Create an Amazon ECS cluster
10.3 Use the Amazon ECR images to create ECS task definitions and services
10.4 Implement the services in ECS by using AWS Fargate enjoying the advantages of
serverless
10.5 Register ECS tasks with an Application Load Balancer (ALB) target group
DEVOPS LAB MANUAL
Build the Ubuntu instance on AWS and here we are trying to access the AWS instance over
SSH.
Prerequisites
Install Java:
Since Jenkins is a Java application, the first step is to install Java. Update the package index
and install the Java 8 OpenJDK package with the following commands
sudo apt update
sudo apt install openjdk-8-jdk
When the key is added, the system will return OK. Next, we'll append the Debian package
repository address to the server's
Once the Jenkins repository is enabled, update the apt package list and install the latest version of
Jenkins by typing:
Jenkins service will automatically start after the installation process is complete. You can verify it by
printing the service status:
Output:
Jul 29 09:27:32 ip-172-31-18-58 systemd[1]: Starting LSB: Start Jenkins at boot time...
Jul 29 09:27:32 ip-172-31-18-58 su[9534]: pam_unix(su:session): session opened for user jenkins by
(uid=0)
Jul 29 09:27:32 ip-172-31-18-58 su[9534]: pam_unix(su:session): session closed for user jenkins
Jul 29 09:27:33 ip-172-31-18-58 systemd[1]: Started LSB: Start Jenkins at boot time.
-----
Since systemctl doesn't display output, we'll use its status command to verify that it started
successfully:
sudo systemctl status Jenkins
Output:-
Active: active (exited) since Fri 2019-08-16 14:35:18 UTC; 8min ago
Docs: man:systemd-sysv-generator(8)
CGroup: /system.slice/jenkins.service
Aug 16 14:35:17 ip-172-31-35-128 systemd[1]: Starting LSB: Start Jenkins at boot time...
Aug 16 14:35:17 ip-172-31-35-128 su[19960]: pam_unix(su:session): session opened for user jenkins
by (uid=0)
Aug 16 14:35:17 ip-172-31-35-128 su[19960]: pam_unix(su:session): session closed for user jenkins
Aug 16 14:35:18 ip-172-31-35-128 systemd[1]: Started LSB: Start Jenkins at boot time.
ubuntu@ip-172-31-35-128:~$
Jenkins will be launched as a daemon up on start. See /etc/init.d/jenkins for more details.
Log file will be placed in /var/log/jenkins/jenkins.log. Check this file if you are troubleshooting
Jenkins.
/etc/default/jenkins will capture configuration parameters for the launch like e.g JENKINS_HOME
By default, Jenkins listen on port 8080. Access this port with your browser to start configuration.
Allowing 8080 port on Firewall By default, 8080 port is not allowed on firewall.
Click on “Description” on AWS instance (where you have created the instance).
Add a new rule with the “Custom TCP rule” and the range “8080”save
Make sure you access the “initialAdminPassword “ file with root permission.
root@ip-172-31-35-128:~# sudo su
root@ip-172-31-35-128:~# cd /var/lib/jenkins/secrets/
------------------------------------------------------------END--------------------------------------------------------------------
2.2 Creating new repository and commit the codes to newly created repository
2.3 Importing the codebase from different Github account to your Github account
Double click on the Git installer. The installer gets save on the machine as per the Windows OS
configuration.
You may like to keep the installation to another folder, so here is the chance to do so. I just want to
keep it in the suggested default folder in my Program Files\Git
Make sure ,we select “Git Bash Here and Git GUI Here”.
DEVOPS LAB MANUAL
This is the option to store the shortcut of the Git under the Program Menu.
This is asking your choice that whether you like to Git from the Windows Command Prompt or you
like to use some other program like Git Bash. As of now just select the Windows Cmd for simplicity
of the tutorial, later we will cover Git Bash and other as well.
DEVOPS LAB MANUAL
If you have PuTTY/TortoiseSVN installed, you may see this screen, otherwise just ignore
this. Regardless, use OpenSSL to make things easy.
If you have PuTTY/TortoiseSVN installed, you may see this screen, otherwise just ignore
this. Regardless, use OpenSSL to make things easy.
DEVOPS LAB MANUAL
Just go with default selections, as we will cover the details in later advance chapter.
Now, its all done. This will just take few minutes to complete the installation as per your machine
speed.
DEVOPS LAB MANUAL
Let’s just verify if the installation went well for Git. Go to cmd and type git and press enter. you
should get the following output on the screen.
git –version
git –help
------------------------------------------------------------END--------------------------------------------------------------------
DEVOPS LAB MANUAL
Chef-Solo is an open source tool that runs locally and allows to provision guest machines using Chef
cookbooks without the complication of any Chef client and server configuration. It helps to execute
Install Git – Since we are going to fetch the cookbooks from Git repo.
Install Chef dk
wget https://packages.chef.io/files/stable/chefdk/3.2.30/ubuntu/18.04/chefdk_3.2.30-
1_amd64.deb
dpkg -i chefdk_3.2.30-1_amd64.deb
root@ip-172-31-41-229:~#
Create a ruby file with file extension .rb – since we are recipe on ruby.
nano hello.rb
file 'HelloChef' do
end
chef-apply hello.rb
----------------------------------------------------------------END----------------------------------------------------------------
Ansible installation
Prerequisites
Two or more Ubuntu 18.04 servers. One of these will be used as our Ansible server
DEVOPS LAB MANUAL
Each should have a non-root user with sudo privileges, and a basic firewall configured.
SSH keys generated for the non-root user on your Ansible server.
Ensure to create same username on both control server and node server.
Ex:- ansiadmin
adduser ansiadmin
passwd -x -1 <username>
To get the latest version of Ansible for Ubuntu, you can add the project's PPA (personal
package archive) to your system, you should first ensure that you have the software-properties-
common package installed.
[apt-get update] - Downloads the package lists from the repositories and "updates" them to
get information on the newest versions of packages and their dependencies. It will do this for all
repositories and PPAs.
Next, refresh your system's package index once again so that it is aware of the packages available in
the PPA:
On our Ansible server, use the cat command to print the contents of your non-root user’s
SSH public key file to the terminal’s output: <Copy the public key to node to estimate the
connection with password>
cat ~/.ssh/id_rsa.pub
DEVOPS LAB MANUAL
ssh-keygen
Since Ansible uses Python interpreter located at /usr/bin/python to run its modules, you’ll need to
install Python on the host for Ansible to communicate with it.
Python installation
To do
adduser ansiadmin
passwd -x -1
adduser ansiadmin
DEVOPS LAB MANUAL
passwd -x -1
su ansiadmin
ssh-keygen
cat ~/.ssh/id_rsa.pub
su ansiadmin
Let’s install small package from control server to node system via ansible.
cd /etc/ansible/
nano hosts
All the host entries either hostname or ip address will update in this host, with following
format.
[group name]
Host1
Host2
Command Ex:
Host or target section – Defines the target machines on which the playbook should run. This is based
on the Ansible inventory file.
Variable section – This is optional and can declare all the variables needed in the playbook.
Tasks section – This section lists out all the tasks that should be executed on the target machine. It
specifies the use of Modules. Every task has a name which is a small description of what the task will
do and will be listed while the playbook is run.
Example 1: Create the file on the target machines or servers as mentioned in the inventory file and
the webserver's group, save the below code with .yml extension and run the playbook.
- hosts: webservers
become: true
tasks:
Example 2: Create a directory with the mode as 775 and owner/group as Ansible.
---
- hosts: webservers
become: true
tasks:
ansible-doc -l | more
----------------------------------------------------------------END-----------------------------------------------------
DEVOPS LAB MANUAL
5.2
Directory Manipulations commands
5.3 Use common commands for working with files and directories
5.4
Installing Software in Linux CLI
5.5
Sending E-mails
ls
The ls command - the list command - to show all the major directories filed under a given file system.
ubuntu@ip-172-31-35-128:~$ ls
ubuntu@ip-172-31-35-128:~$ mkdir Test
ubuntu@ip-172-31-35-128:~$ ls
Test
ubuntu@ip-172-31-35-128:~$
cd
The cd command - change directory - will allow the user to change between file directories.
mv
The mv command - move - allows a user to move a file to another folder or directory. Just like dragging a
file located on a PC desktop to a folder stored within the "Documents" folder, the mv command functions in
the same manner.
man
The man command - the manual command - is used to show the manual of the inputted command.
Man mkdir
DEVOPS LAB MANUAL
mkdir
The mkdir - make directory - command allows the user to make a new directory. Just like making a new
directory within a PC or Mac desktop environment, the mkdir command makes new directories in a Linux
environment.
mkdir testdirectory
rmdir
The rmdir - remove directory - command allows the user to remove an existing command using the Linux
CLI.
rmdir testdirectory
rm
The rm command - remove - like the rmdir command is meant to remove files from your Linux OS.
Whereas the rmdir command will remove directories and files held within, the rm command will delete
created files. An example of the rm command:
rm testfile.txt
apt-get update downloads the package lists from the repositories and "updates" them to get information on
the newest versions of packages and their dependencies.
apt-get install command is usually to be prepended by sudo, which essentially means that you need to run
the command with elevated privileges as root or superuser.
systemctl command
Linux systemctl command. The systemctl command is a new tool to control thesystemd system and
service.
----------------------------------------------------------------END-----------------------------------------------------
DEVOPS LAB MANUAL
As of the writing of this article, the latest release is v0.12.9. Download it like below:
# Ubuntu
sudo apt-get install wget unzip
# CentOS
sudo yum install wget unzip
export VER="0.12.9"
wget
https://releases.hashicorp.com/terraform/${VER}/terraform
_${VER}_linux_amd64.zip
$ unzip terraform_${VER}_linux_amd64.zip
Archive: terraform_0.12.9_linux_amd64.zip
inflating: terraform
This will create a terraform binary file on your working directory. Move this file to the
directory/usr/local/bin.
$ which terraform
/usr/local/bin/terraform
$ terraform -v
Terraform v0.12.9
$ mkdir projects
$ cd projects
touch main.tf
I’m doing a Test with AWS Provider but you can use other Providers for your
projects. My terraform configuration provider section is as below.
$ vim main.tf
# Provider
provider "aws" {
access_key = ""
secret_key = ""
region = "us-west-1"
}
DEVOPS LAB MANUAL
$ terraform init
$ terraform plan
$ terraform apply
----------------------------------------------------------------END-----------------------------------------------------
7.3 Create the Stack and choose template for launching instance
Procedure
STEP 5:In resource type select S3 and drag and drop on designer
Use ra;
----------------------------------------------------------------END-----------------------------------------------------
8.1 Build the infrastructure and automate code deployment for a PHP application with
OpsWorks
8.4 Execute other commands – Undeploy, Rollback, Start Web Server, Stop Web Server,
Restart Web Server
OPSWORK :
AWS OPSWORK is a configuration management service that helps you configure & operate
applications in a cloud enterprise by using puppet & chef .AWS OPSWORK stack & AWS
OPSWORK for chef automate lets you use chef cookbooks & solutions for configuration management
while OPSWORK for puppet enterprise lets you configure a puppet enterprise master server in AWS
puppet offers a set of tools for enforcing the desired state of your infrastructure & automating on
demand tasks.
STEP 12 : go to actions
----------------------------------------------------------------END-----------------------------------------------------
Step 5: It shows a dashboard in that select, application category as web application , programming
language as Node JS , AWS service as Amazon EC2
2.) Project ID
DEVOPS LAB MANUAL
Step 10 : It shows a page called Amazon EC2 key pair Select key pair or create a new key pair
----------------------------------------------------------------END-----------------------------------------------------
10.1 Use application source files to create Docker container images and place them in Amazon
ECR
10.2 Create an Amazon ECS cluster
10.3 Use the Amazon ECR images to create ECS task definitions and services
10.4 Implement the services in ECS by using AWS Fargate enjoying the advantages of serverless
10.5 Register ECS tasks with an Application Load Balancer (ALB) target group
DEVOPS LAB MANUAL
2. Authentication to AWS
Open Power Shell interface with administration privileges and enter the following commands:
aws configure
Access key: ****
Secret key: ****
The region name and output format information are not mandatory.
The data above can be found from the IAM service on AWS console management.
6. Create a repository
aws ecr create-repository (dash dash)repository-name centos
The repository has been created successfully into Amazon Elastic Container Registry (see below):
DEVOPS LAB MANUAL
Before proceeding to the next step, make sure that the following requirements are met:
Docker version must be greater or equal to 1.7
The repository is created and that the user has sufficient privileges to access it
The Docker authentication is successful
If you are in a test environment, to avoid extra costs, make sure to delete the image and the
repository from Amazon elastic container registry.
Use the following command to delete the image:
aws ecr batch-delete-image (dash dash)repository-name centos (dash dash)image-ids
imageTag=6.6
Use the following command to delete the repository:
aws ecr delete-repository (dash dash)repository-name centos
To create a cluster
1. Open the Amazon ECS console at https://console.aws.amazon.com/ecs/.
2. From the navigation bar, select the Region to use.
3. In the navigation pane, choose Clusters.
4. On the Clusters page, choose Create Cluster.
DEVOPS LAB MANUAL
5. For Select cluster compatibility, choose one of the following options and then choose Next Step:
Networking only– With this option, you can launch a cluster of tasks using the Fargate launch type.
The Fargate launch type allows you to run your containerized applications without the need to
provision and manage the backend infrastructure. When you register your task definition, Fargate
launches the container for you.
EC2 Linux + Networking– With this option you can launch a cluster of tasks using the EC2 launch
type and Linux containers. The EC2 launch type allows you to run your containerized applications on
a cluster of Amazon EC2 instances that you manage.
EC2 Windows + Networking – With this option you can launch a cluster of tasks using the EC2 launch
type using Windows containers. The EC2 launch type allows you to run your containerized
applications on a cluster of Amazon EC2 instances that you manage. For more information,
see Windows Containers.
If you chose the Networking only cluster template, continue with the following steps.
1. On the Configure cluster page, enter a Cluster name. Up to 255 letters (uppercase and lowercase),
numbers, hyphens, and underscores are allowed.
2. In the Networking section, configure the VPC for your cluster. You can keep the default settings, or
you can modify these settings with the following steps.
a. (Optional) If you choose to create a new VPC, for CIDR Block, select a CIDR block for your VPC. For
more information, see Your VPC and Subnets in the Amazon VPC User Guide.
b. For Subnets, select the subnets to use for your VPC. You can keep the default settings, or you can
modify them to meet your needs.
3. In the Tags section, specify the key and value for each tag to associate with the cluster. For more
information, see Tagging Your Amazon ECS Resources.
4. In the CloudWatch Container Insights section, choose whether to enable Container Insights for the
cluster. For more information, see Amazon ECS CloudWatch Container Insights.
5. Choose Create.
----------------------------------------------------------------END-----------------------------------------------------