0% found this document useful (0 votes)
86 views28 pages

Project Solution 1

The document outlines steps to configure a DevOps project using automated build pipelines including: 1. Creating AWS EC2 instances for a master node and test server. 2. Installing dependencies like Git, Java, Jenkins, and Ansible on the master node. 3. Configuring the test server as a Jenkins slave and installing additional dependencies like Docker. 4. Using Ansible playbooks to deploy and test a PHP application on the test server.

Uploaded by

mayekaromkar15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views28 pages

Project Solution 1

The document outlines steps to configure a DevOps project using automated build pipelines including: 1. Creating AWS EC2 instances for a master node and test server. 2. Installing dependencies like Git, Java, Jenkins, and Ansible on the master node. 3. Configuring the test server as a Jenkins slave and installing additional dependencies like Docker. 4. Using Ansible playbooks to deploy and test a PHP application on the test server.

Uploaded by

mayekaromkar15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

DevOps Project

Subject: - configure and manage slave node using automated build pipeline

 Create AWS EC2 instance (Master and Test Server)


1. Log in to AWS console.
2. Launch a Virtual Machine with EC2 instance.
3. Click on the next. Select Ubuntu server 22.04 LTS(HVM)
4. Click on the next - For Instance, type we have selected free tier eligible t2. micro.
5. Click on the next - Number instance we making 2.
6. Click on the next, configure Security Group.
7. Now we will require to open all the port.
8. Click on add rule for all traffic.

 1 instance for the master


 2 instances for web deployment server
9. Click on the next, add storage and extend upto 14 GB.

10. Then, review and launch.


11. Create a new keypair. Download the keypair. key name is “project”
12. Instance has been created.
13. We have given the name to instance “Master and Test Server”.

Subject - Deployment of the project is PHP application we will handling Test Server
machine to completely from the Master.
 Configuring Test Server with Master and deployment to Test Server machine.
Overview: -

 In Master machine we require to install Git, JAVA, Jenkins and ansible.


 In Test Server machine for deployment of PHP application firstly, we require to
dockerizing PHP application. Like we are putting PHP application as a docker image then
we running docker image and containerization in Test Server Machine for deployment.
 On Test Server machine we need to docker because docker image is run in Test Server
machine.
 After deployment we will do selenium testing. So for this we need to chromium browsers,
chrome driver etc.
 Our Test Server machine as Jenkins Slave. On slave machine Java Should be install.
 Git should be install in slave machine.
 These are all dependencies we should install in slave machine.
 We have configuration management tool we have ansible here.
 Ansible should be install in test server machine.

 Task: -
 Install Java, Jenkins, Ansible on the machine. And add that Test Server Machine Ansible
Hosts.
 Also add Jenkins in our Test Server.
 Then we will deploy our application using the ansible first configure Test Server
machine.
 Install all the dependencies Java, chromium browsers, chrome driver etc. on the Test
Server.
 Using Jenkins, we have to deploy our PHP applications. We will dockerize first and then
we will deploy it.
 Now 1st we will download the ansible playbook and download the all thing in master
instances.
 (Jenkins, Java, Ansible in the master)
 The thing is very important because we are using instance type t2. micro. there is some
limitation t2. micro 1 GB of RAM per instance. Limitation of 1 GB RAM is that you
can’t install the Jenkins and puppet in same machine.
 Since, puppet and Ansible we are using for same thing like configuration management.
 So, we don’t require both of them.
 We are using only ansible here for our project.
 Now, Master machine we will install Git, Java, Jenkins.
 Let’s connect to master and install the all these.

1. Open the Putty for connect to Master.


2. Enter the hostname or IP address. IP address is: -

3. We will set project.pem key pair, so firstly we will create the .ppk file for connect to master.
4. Now selects the project.ppk file in SSH authentications.
5. Now EC 2 instance Master has been connected through putty.

6. Now, we are installing all the require tools.


7. For Git: - EC 2 instance Master has already installed Git by default.
To check the git version.
Command: - git –version

8. For JAVA: - installation


Firstly, Update the repositories:
Command: - sudo apt-get update

Install Open JDK


Command: - sudo apt-get install openjdk-8-jdk
Verify the version of the JDK:
Command: - java -version
9. For Jenkins: - installation
Add the Jenkins repository to your Ubuntu system
Run the command for Jenkins’s installation: -
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins- keyring.asc > /dev/null

Add the Jenkins software repository to the source list and provide the authentication key:
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian- stable binary/ | sudo tee
/etc/apt/sources.list.d/jenkins.list > /dev/null

sudo apt-get update

sudo apt-get install Jenkins -y

10. Our jenkins should be installed.


We know the service status command: - systemctl status Jenkins
11. Now jenkins actively running in master.
12. We will connect to Jenkins in the browser.
Command: -
sudo cat cat /var/lib/jenkins/secrets/initialAdminPassword

13. For Open Jenkins in browser: - we have used public IP of Master EC 2 instances.
14. Use public IP in browser.
15. Jenkins Run as port 8080
16. Add the password
17. Add Password and continue.

18. Then Select or click on: - Install suggested plugins.


19. Create First Admin User

20. Start Using Jenkins


21. Now, we will install the ansible in Master EC2 instance.
To using Ansible as a means of managing our server infrastructure, we need to install the
Ansible software on the machine that will serve as the Ansible control node.

From our control node, run the following command to include the official project’s PPA
(personal package archive) in your system’s list of sources:

sudo apt-add-repository ppa:ansible/ansible

22. Next, refresh your system’s package index so that it is aware of the packages available in
the newly included PPA:

sudo apt update

23. Following this update, we can install the Ansible software with:
sudo apt install ansible

24. Our Ansible control node now has all of the software required to administer hosts. Next,
we will go over how to add our hosts to the control node’s inventory file so that it can
control them.
25. After installation of Ansible in Master machine. Then we will install the ansible in Slave
machine (Test Server).
Now we will connect the Test Server instance EC2 via Putty.
Test Server Public IP: -
Key pair: - Projects
Slave Test server EC2 instance.
1. First thing does update the packaging.

Sudo apt-get update


2. We add the machine as ansible host and SSH connection will be establishing in both
machines.
3. We have to established SSH connection. Master to the Test Server Machine.
4. We have to generate SSH key.
First SSH key generate in Master machine.
Command: - ssh-keyen

5. Now we will check our SSH key.

Command: cd .ssh/
Command: ls

Id_rsa – Private key


Id_rsa.pub- public key
6. Copy to the public key of the Master machine and authorized_keys of the Master machine.
Command: - Cat .ssh/id_rsa.pub >> .ssh/authorized_keys

7. While making the SSH connection they checking the Key. Key is valid or key is
matching then connection would be established.
Command: - Cat .ssh/id_rsa.pub
Open the public key and copy the key.
8. Now go to the slave , SSH directory
9. Copy the public key master machine in the slave machine of authorized file.
10. Command: - sudo nano authorized_keys in slave machine
11. Open the command line.
12. Paste master machine public in second line.

13. We will save the files.


14. Now we have made the SSH connection between master machine and Slave /Test server
machine.
15. For SSH.
Command: - ssh slave machine user name@private IP to Test Server
ssh ubuntu@Private_ip

It’s connected to the slave through ssh.


16. Now we have added the second machine in the inventory file of ansible we have all those
machines.
17. In master machine edit this file sudo nano /etc/ansible/hosts (this is the inventory file)

18. Creating the new group [webserver]


For new we are using private ip of Test Server machine.

19. Now we have edited the Test Server machine inventory file of ansible.
20. We try to ping that machine which the ansible reach that machine or not.
21. To do that, command ansible -m ping groupname.
Command: - ansible -m ping webserver

22. We able to ping the second machine using ansible command. Once ansible connection is
establish.
23. Now, in master machine we have to installed git, Java, Jenkins, Ansible.
24. Now, Ansible we have to configure in Test Server machine. We have installing require
tools like git, java , docker, chrome driver, chromium browser on to the Test server
machine.
25. For install the chrome driver - firstly the chrome driver installs to the master machine.
26. Then directly copy the chrome driver Master to Test Server.
27. Run the command directly using ansible to Test Server machine. There are 5-6
command. It will increase the playbook size. Rather we do first install the chrome driver
on to the master and then directly copy to the Test server machine using ansible
playbook.
28. For chrome driver installation command is below: -
sudo apt-get update
sudo apt-get install -y unzip xvfb libxi6 libgconf-2-4
sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add
sudo echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >>
/etc/apt/sources.list.d/google-chrome.list

sudo apt-get -y update


sudo apt-get -y install google-chrome-stable
wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
29. Chrome driver has been downloading
(user - /home/ubuntu/)

30. Now, directly copy the chromedriver to our test server machine.
31. Write the ansible playbook to install the dependencies of the Test Server machine.
32. Creating first playbook now,
33. Any playbook name (command: - sudo nano project.yml)
34. Write the playbook.
---

- hosts: all

become: true

tasks:

- name: Install Git

package:

name: git

state: present

- name: Run update

apt:

update_cache: true

- name: Install jdk

package:
name: openjdk-11-jdk

state: present

- name: Download Chrome browser

command: wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

- name: Install Chrome Browser

command: apt install ./google-chrome-stable_current_amd64.deb -y

- name: Run update

apt:

update_cache: yes

- name: download chromedriver

command: wget https://chromedriver.storage.googleapis.com/87.0.4280.88/chromedriver_linux64.zip


- name: install unzip

command: apt install unzip

- name: unzip chromedriver

command: unzip chromedriver_linux64.zip

- name: move chromedriver

command: mv chromedriver /home/ubuntu/

35. save name with project.yml


36. now we check the syntax of the playbook.
Command: - ansible-playbook project.yml
Ansible-playbook project.yml --check

37. Go to the Test Server machine check java.


Java -version
38. In Test server chromedriver is there.

39. Then, Run the command


Sudo chmod -R 777 chromedriver
 Now we require to Docker on the slave (Test Server) machine.

1. Create the file docker.yml.


Sudo nano docker.yml

Script: -
---
- hosts: all
become: yes
become_user: root
tasks:
- name: Add Docker GPG key
apt_key: url=https://download.docker.com/linux/ubuntu/gpg

- name: Add Docker APT repository


apt_repository:
repo: deb
[arch=amd64] https://download.docker.com/linux/ubuntu {{ansible_distribution_release}} stable

- name: Install list of packages


apt:
name: "{{ item }}"
state: present
update_cache: yes
with_items:
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- docker-ce
2. Docker has been installed now
3. All the dependencies installed in Test Server. (Git, java, Chromedriver, chromium
browser, Docker)
4. Ansible part has been done now.

 Add Test Server machine as Jenkins’s slave:

1. Open Jenkins.
2. Username: Nikhil
3. Password:
4. Click on manage Jenkins.

5. Click on configure Global Security.


6. Firstly, we have to select the Agent.
TCP port for inbound agents
Select: - Random
7. Then save.
8. Click on Manage Nodes and Clouds
9. Click New Node.
10. Enter Node name – project
Select permanent Agent
Then click on Create

11. Now , this is going to the configuration,

12. Add Remote root directory.


13. Click on Tool location.

14. Then Save.


15. Now click on project.
16. We have to do establish connection.

17. Right click on – agent.jar and copy link address.


18. Go to master machine.
19. Type the wget

20. Now copy this file in our slave machine.


21. scp agent.jar ubuntu@private address of Test server machine:/home/ubuntu
22. now check the Test Server.

23. Now, copy java.jar command we have run this command on slave/ Test server machine
to establish the connection
24. First open new terminal and connect to slave machine.
25. Now copy the java.jar command from jenkins to Master machine

26. Its shows connected.


27. Click on jenkins.
28. Refresh the page.
29. Agent project is connected.

30. We are created to jenkins slave and connected it.


31. Next, we have to dockerize the our php application.
32. We have to create docker file. And we should the content of php application on to that
image.
33. Open the problem statement of project.

34. Click on the same PHP application link: - https://github.com/nikhilk814/projCert--


edureka-certificate-.git
35. Repositories has been created under my Git account with same content.
36. Docker has been created.

FROM devopsedu/webapp

ADD website /var/www/html

RUN rm /var/www/html/index.html

CMD apachectl -D FOREGROUND

37. Then commit new file it.


38. Click on Code or clone / download.

39. Copy the url- https://github.com/nikhilk814/projCert--edureka-certificate-.git


40. Now go to jenkins , we have created jenkins job.
41. Job should run on jenkins slave machine
42. We have to build this docker file on the slave/Test Server machine then run the docker
image which will be created.
43. Click on new Item.
44. Enter name and select the Free style project and click on OK.
45. Then we get general setting option
46. Select the Restrict where this project can be run Label expression --project

47. source code management - select Git and add the Repository URL.
48. Then Build, add build step select Execute shell.
49. We have run shell command to build the docker file and then to run docker image
which will be created.
50. Click and type -
sudo docker build -t phpapplication .
sudo docker run -itd -p 8081:80 phpapplication
51. Then apply and save

52. Open the Slave /Test server Machine.


53. Type – sudo visudo
Go to last and enter the – jenkins ALL=(ALL) NOPASSWD: ALL
54. Go to jenkins.
55. Then Build now.
56. its successful.
57. Open the browser and we checked website is live.
58. Now PHP application is live.
59. Project deployment successfully complete.

You might also like