Docsity

DevOps Development and Operation, Study notes of Computer Science

Toggle sidebar
bg1
DevOps Complete Package
LAMP
=====
So when it comes to LAMP we are talkin g about { Linux, Apache, MySql & PHP }
LAMP is an open source Web development platform that uses Linux as the operating system, Apache as the Web
server, MySQL as the relational database management system and PHP as the object-oriented scripting lang uage.
Because the platform has four layers, LAMP is sometimes referred to as a LAMP stack. Stacks can be built on different
operating systems.
The same setup in windows is called WAMP
The same setup in mac is called MAMP
Advantages Of LAMP
==================
Open Source
Easy to code with PHP
Easy to deploy an application
Develop locally
Cheap Hosting
Easy to build CMS application
o Wordpress, Drupal, Joomla, Moodle etc
Web Server
A web server is a program which serv es web pages to users in response to their requests, which are forwarded by their
computers' HTTP clients(Browsers).
All computers that host websites must have web server program.
Purpose of Web server
===================
A web server’s main purpose is to store web site files and broadcast them over the internet for you site visitors to see. In
essence, a web server is simply a powerful computer that stores and transmits data via the internet.
Web servers are the gateway betwe en the average individual and the world wide web.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download DevOps Development and Operation and more Study notes Computer Science in PDF only on Docsity!

DevOps Complete Package

LAMP

So when it comes to LAMP we are talking about { Linux, Apache, MySql & PHP } LAMP is an open source Web development platform that uses Linux as the operating system, Apache as the Web server, MySQL as the relational database management system and PHP as the object-oriented scripting language. Because the platform has four layers, LAMP is sometimes referred to as a LAMP stack. Stacks can be built on different operating systems. The same setup in windows is called WAMP The same setup in mac is called MAMP Advantages Of LAMP ==================  Open Source  Easy to code with PHP  Easy to deploy an application  Develop locally  Cheap Hosting  Easy to build CMS application o Wordpress, Drupal, Joomla, Moodle etc Web Server A web server is a program which serves web pages to users in response to their requests, which are forwarded by their computers' HTTP clients(Browsers). All computers that host websites must have web server program. Purpose of Web server =================== A web server’s main purpose is to store web site files and broadcast them over the internet for you site visitors to see. In essence, a web server is simply a powerful computer that stores and transmits data via the internet. Web servers are the gateway between the average individual and the world wide web.

LAMP Architecture Linux :: We already talked about linux Apache ======= An open source web server used mostly for Unix and Linux platforms. It is fast, secure and reliable. Since 1996 Apache has been the most popular web server, presently apache holds 49.5% of market share i.e, 49.5% of all the websites followed by Nginx 34% and Microsoft IIS 11%. Parameters for Apache (httpd) Packages - httpd & mod_ssl Port - 80 443 Protocol - http https Server Root - /etc/httpd Main config file - /etc/httpd/conf/httpd.conf Document root - /var/www/html {all our web pages } Logs - /var/log/httpd/error_log /var/log/httpd/access_log What version of OS you have ========================

cat /etc/redhat-release

cat /etc/os-release

Checking httpd service is running or not

6.x - Whenever you have problem with httpd {troubleshooting httpd}

service httpd status

netstat -ntpl | grep 80

ps -ef | grep httpd

7.x - Whenever you have problem with httpd {troubleshooting httpd}

Nginx is a http server, which is used in many high traffic websites like GitHub, heroku etc. The 3 imp features that nginx gives is: Load balancing, Caching and Reverse proxying. In load balancing, say u have a high traffic website which gets 1000 requests per second may be more then that, if u have only one server all the 1000 requests will be severe by the single server where the response time will be decreased. So we put more servers and distribute the load to all the servers equally. So the 1000 requests will be distributed to 3 servers like 300 requests for each server assuming we got 3. Reverse proxy, we are having multiple applications on the server, and u can only run one application on one port, say u running one app on port 80 now u can’t run another application on port 80 we got to use another port. { app1.com ==> app1.com:80 } Now we are running multiple applications we need give diff port right something like { app2.com:81 } Now I don’t want to specify port 81 in url, I want app2.com, to deal with this problem we can use nginx. Now nginx intercepts the requests and it will see that the following request is for app2.com now it routes this request to that application which is running on port 81. This is what reverse proxy is. Forward Proxy & Reverse Proxy ========================== The word "proxy" describes someone or something acting on behalf of someone else. In the computer realm, we are talking about one server acting on the behalf of another computer. Forward Proxy =============== Forward Proxy: Acting on behalf of a requestor (or service consumer) "forward proxy" retrieves data from another web site on behalf of the original requestee. In forward proxy we get to see 3 computers: X = your computer, or "client" computer on the internet Y = the proxy web site, proxy.example.org Z = the web site you want to visit, www.example.net Normally, one would connect directly from X —> Z. However, in some scenarios, it is better for Y —> Z, on behalf of X, which chains as follows: X —> Y—> Z Reasons why X would want to use a forward proxy server ==================================================== X is unable to access Z directly because a) Someone with administration authority over X's internet connection has decided to block all access to site Z. Employees at a large company have been wasting too much time on facebook.com, so management wants access blocked during business hours. Torrent downloads can be blocked by our ISP’s so to view the torrent downloads we can use forward proxy. b) The administrator of Z has blocked X. Examples: The administrator of Z has noticed hacking attempts coming from X, so the administrator has decided to block X's ip address. Z is a forum web site. X is spamming the forum. Z blocks X. Reverse Proxy ===============

Reverse Proxy: Acting on behalf of service/content producer In reverse proxy we get to see 3 computers: X = your computer, or "client" computer on the internet Y = the reverse proxy web site, proxy.example.com Z = the web site you want to visit, www.example.net Normally, one would connect directly from X --> Z However, in some scenarios, it is better for the administrator of Z to restrict or disallow direct access, and force visitors to go through Y first. So, as before, we have data being retrieved by Y --> Z on behalf of X, which chains as follows: X --> Y --> Z. Reasons why Z would want to setup a reverse proxy server ==============================================

  1. Z wants to force all traffic to its web site to pass through Y first. a) Z has a large web site that millions of people want to see, but a single web server cannot handle all the traffic. So Z sets up many servers, and puts a reverse proxy on the internet that will send users to the server closest to them when they try to visit Z. This is part of how the Content Distribution Network (CDN) concept works. Examples: Apple Trailers uses Akamai Jquery.com hosts its javascript files using CloudFront CDN (sample).
  2. The administrator of Z is worried about retaliation for content hosted on the server and does not want to expose the main server directly to the public. Load Balancing and Reverse Proxying with Nginx ======================================== Make sure you have 3 machines setup with you: M1 IP-ADD: 104.154.22. M2 IP-ADD: 104.198.254. M3 IP-ADD: 104.198.70. Machine ========

yum -y install httpd

systemctl enable httpd

systemctl start httpd

allow port 80 in firewall

echo “MACHINE01” > /var/www/html/index.html

vi /var/www/html/index.html { MACHINE —> 1 }

Machine

yum -y install httpd

systemctl enable httpd

systemctl start httpd

allow port 80 in firewall

echo “MACHINE02” > /var/www/html/index.html

vi /var/www/html/index.html { MACHINE —> 2 }

Machine

Installation Version 5.

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

sudo yum -y install mysql-server

Start the mariadb server # sudo systemctl start mysqld Setting password # sudo mysql_secure_installation To login to database # sudo mysql -u root -p

ps -ef | grep mysql

netstat -ntpl | grep 3306

How to connect to Database?

mysql -u root -p {if db is same host}

mysql -u root -p -h {if db is on diff host

CMS Application

Download wordpress # wget https://wordpress.org/latest.tar.gz

sudo tar xvf wordpress.tar -C /var/www/html

sudo yum -y install php php-mysql

Login to phpmyadmin, and create user a database and user called wordpress something like that. Give anything you want as username and password Copy and paste the code given by wordpress into wp-config.php Change the ownership of wordpress directory to apache:apache

GIT

Why Version Control ??

Have you ever: ● Made a change to code, realised it was a mistake and wanted to revert back? ● Lost code and didn’t have a backup of that code? ● Had to maintain multiple versions of a product? ● Wanted to see the difference between two (or more) versions of your code? ● Wanted to prove that a particular change in code broke application or fixed a application? ● Wanted to review the history of some code? ● Wanted to submit a change to someone else's code? ● Wanted to share your code, or let other people work on your code? ● Wanted to see how much work is being done, and where, when and by whom? ● Wanted to experiment with a new feature without interfering with working code? In these cases, and no doubt others, a version control system should make your life easier. Key Points ● Backup ● Collaboration ● Storing Versions ● Restoring Previous Versions ● Understanding What Happened Version Control / Revision control / Source Control is is a software that helps software developers to work together and maintain a complete history of their work. You can think of a version control system ("VCS") as a kind of "database". It lets you save a snapshot of your complete project at any time you want. When you later take a look at an older snapshot ("version"), your VCS shows you exactly how it differed from the previous one. A version control system records the changes you make to your project’s files. This is what version control is about. It's really as simple as it sounds.

Centralized Version Control System (CVCS) Uses a central server to store all files and enables team collaboration. But the major drawback of CVCS is its single point of failure, i.e., failure of the central server. Unfortunately, if the central server goes down for an hour, then during that hour, no one can collaborate at all. Distributed Version Control System (DVCS) DVCS does not rely on the central server and that is why you can perform many operations when you are offline. You can commit changes, create branches, view logs, and perform other operations when you are offline. You require network connection only to publish your changes and take the latest changes.

Hence, this architecture is called 2 Tree Architecture. Because you have two tree in there Working Copy and Repository. The famous VCS with this kind of architecture is Subversion or SVN. How the Distributed DVCS works =========================== Unusually, a DVCS works by having three places to store things:

  1. Working Copy
  2. Staging
  3. Repository As Git uses Distributed version control system, So let’s talk about Git which will give you an understanding of DVCS. Git was initially designed and developed by Linus Torvalds in 2005 for Linux kernel development. Git is an Open Source tool. History For developing and maintaining Linux Kernel, Linus Torvalds used BitKeeper which is also one of the VCS, and is open source till 2004. So instead of depending on other tools, they developed their own VCS. Just see the wiki of Git.

Git Architecture Git uses three tree architecture. Well interestingly Git has the Working Copy and Repository as well but it has added an extra tree Staging in between: As you can see above, there is a new tree called Staging. What this is for? This is one of the fundamental difference of Git that sets it apart from other VCS, this Staging tree (usually termed as Staging area) is a place where you prepare all the things that you are going to commit. In Git, you don't move things directly from your working copy to the repository, you have to stage them first, one of the main benefits of this is, to break up your working changes into smaller, self-contained pieces. To stage a file is to prepare it for a commit. Staging allows you finer control over exactly how you want to approach version control. Advantages Of Git ===================

Let’s have some configuration set:

git config --global user.name “Ravi”

git config --global user.email “[email protected]”

Taking e-commerce sites as example. Basic Git Workflow =============

  1. You modify files in working directory
  2. You stage files, adding snapshots of them to your staging area.
  3. You do a commit, which takes the files as they are in the staging area and stores that snapshot to your git repository.

mkdir website

git init

git status {Branches will talk later}

vi index.html

{put some tags <h1><body> just structure}

git status

git add index.html {staged the changes}

git commit -m “Message” {moves file from staging area to local repo}

git status

You can skip the staging area by # git commit -a -m “New Changes”

Commit History - How many Commits have happened ?? To see what commits have been done so far we use a command:

git log

It gives commit history basically commit number, author info, date and commit message. Want to see what happend at this commit, zoom in info we use:

git show

Let’s understand this commit number This is sha1 value randomly generated number which is 40 character hexadecimal number which will be unique. Let’s change the title in index.html and go with

git add status commit

git log {gives the latest commit on top and old will get down}

Git diff

Let’s see, the diff command gives the difference b/w two commits.

git diff xxxxxx..xxxxxx

You can get diff b/w any sha’s like sha1..sha20. Now our log started increasing, like this the changes keep on adding file is one but there are different versions of this file.

git log --since YYYY-MM-DD

git log --author ravi

git log --grep HTML { commit message }

git log --oneline

Git Branching

In a collaborative environment, it is common for several developers to share and work on the same source code. Some developers will be fixing bugs while others would be implementing new features. Therefore, there has got to be a manageable way to maintain different versions of the same code base. This is where the branch function comes to the rescue. Branch allows each developer to branch out from the original code base and isolate their work from others. Another good thing about branch is that it helps Git to easily merge the versions later on. It is a common practice to create a new branch for each task (eg. bug fixing, new features etc.)

What happens if you create a new branch? Well, doing so creates a new pointer for you to move around. Let’s say you create a new branch called testing.

git branch testing

This creates a new pointer to the same commit you’re currently on. Two branches pointing into the same series of commits. How does Git know what branch you’re currently on? It keeps a special pointer called HEAD. HEAD is a pointer to the latest commit id and is always moving, not stable.

git show HEAD

In Git, this is a pointer to the local branch you’re currently on. In this case, you’re still on master. The git branch command only created a new branch — it didn’t switch to that branch.

This command shows you where the branch pointers are pointing:

git log --oneline --decorate

You can see the “master” and “testing” branches that are right there next to the f30ab commit. To switch to an existing branch, you run the git checkout command.

git checkout testing

This moves HEAD to point to the testing branch. What is the significance of that? Well, let’s do another commit:

vim test.rb