DevOps Pre-Requisites-as PDF
DevOps Pre-Requisites-as PDF
www.kodekloud.com
The DevOps Pre-Requisite
Course
2
Common Challenges
• Issues with setting up a basic lab
• Issues with connecting to VMs
• Trouble with navigating Linux CLI
• No experience working with text editors
• Errors during installation of application/dependencies
• Applications – Java, Python, NodeJS
• Web Servers – Apache, NGINX
• Databases – MySQL, MongoDB
• Issues with networking between VMs
• Trouble navigating JSON or YAML files
DevOps Pre-Requisite
Who is this course for?
WEB SERVERS
DATABASES
MULTI-TIER APPLICATIONS
JSON/YAML
CURRICULUM
LINUX BASICS
• Setup Labs – Laptop or Cloud
SETUP LAB ENVIRONMENT
• VirtualBox
LINUX NETWORKING BASICS • Deploying VMs
• Multiple VMs
SCM BASICS (GIT)
• Networking and Troubleshooting
Network
APPLICATION BASICS
• Snapshots and Restore VMs
WEB SERVERS • Vagrant Basics
DATABASES
MULTI-TIER APPLICATIONS
JSON/YAML
CURRICULUM
LINUX BASICS
• Interfaces
SETUP LAB ENVIRONMENT
• IP Addresses
LINUX NETWORKING BASICS • Routing
SCM BASICS (GIT) • DNS
APPLICATION BASICS
WEB SERVERS
DATABASES
MULTI-TIER APPLICATIONS
JSON/YAML
CURRICULUM
LINUX BASICS
• Install GIT
SETUP LAB ENVIRONMENT
• GIT Repositories
LINUX NETWORKING BASICS • Clone source code with GIT
SCM BASICS (GIT) • Make and commit changes
APPLICATION BASICS
• Push source code
WEB SERVERS
DATABASES
MULTI-TIER APPLICATIONS
JSON/YAML
CURRICULUM
LINUX BASICS
• Who is this for?
SETUP LAB ENVIRONMENT • Non-Developers
LINUX NETWORKING BASICS
• Different types of applications
SCM BASICS (GIT)
• Python
APPLICATION BASICS • NodeJS
• Java
WEB SERVERS
• Building and Deploying them
DATABASES • Troubleshooting Applications
MULTI-TIER APPLICATIONS • Labs
JSON/YAML
CURRICULUM
LINUX BASICS
• Web Frameworks
SETUP LAB ENVIRONMENT
• Web Servers
LINUX NETWORKING BASICS • Apache HTTPD
SCM BASICS (GIT) • NGINX
APPLICATION BASICS
• Python - Gunicorn
• NodeJS – PM2
WEB SERVERS
• IPs and Ports
DATABASES
• SSL and TLS Security
MULTI-TIER APPLICATIONS
JSON/YAML
CURRICULUM
LINUX BASICS
• Who is this for?
SETUP LAB ENVIRONMENT • Non-Developers
LINUX NETWORKING BASICS
• Different types of databases
SCM BASICS (GIT)
• MySQL
APPLICATION BASICS • MongoDB
• Web Server connectivity
WEB SERVERS
DATABASES
MULTI-TIER APPLICATIONS
JSON/YAML
CURRICULUM
LINUX BASICS
APPLICATION BASICS
WEB SERVERS
DATABASES
MULTI-TIER APPLICATIONS
JSON/YAML
CURRICULUM
LINUX BASICS
APPLICATION BASICS
WEB SERVERS
DATABASES
MULTI-TIER APPLICATIONS
JSON/YAML
just enough
LINUX
Why Linux?
26
https://insights.stackoverflow.com/survey/2019
Why Linux?
https://docs.ansible.com/ansible/latest/user_guide/windows_faq.html
Kubernetes Documentation
Linux Basics
• Linux CLI
• VI Editor
• Package Management
• Service Management
LINUX
Shell Types
echo $SHELL Broune Shell (Sh Shell)
/bin/bash
Z Shell (zsh)
ls
List files & folders
File.txt my_dir1 file2.conf
pwd
Present Working Directory
/home/my_dir1
mkdir –p /tmp/asia/india/bangalore
cat new_file.txt
View contents of file
This is some sample contents
LINUX
User Accounts
whoami
matthew
matthew
id
uid=1001(matthew) gid=1001(matthew) groups=1001(matthew)
su aparna
Password:
37
User Accounts
ls /root
ls: cannot open directory /root: Permission denied
matthew root
sudo ls /root SUDO
anaconda-ks.cfg initial-setup-ks.cfg /etc/sudoers
38
Download Files
curl http://www.some-site.com/some-file.txt -O
some-file.txt
cat /etc/*release*
CentOS Linux release 7.7.1908 (Core)
Derived from Red Hat Enterprise Linux 7.7 (Source)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
• Wget
• Curl
• Cat /etc/*release*
41
Package Managers
RPM (Red Hat Package Manager)
rpm –i telnet.rpm Install Package
?
?
? RPM
? telnet.rpm
ansible
YUM
yum install ansible Install Package
/etc/yum.repos.d
PyYAML
YUM
python RPM
ansible
sshpass
YUM Repos
yum repolist
repo id repo name status
base/7/x86_64 CentOS-7 - Base 10097
extras/7/x86_64 CentOS-7 - Extras 341
mongodb-org-4.2/7 MongoDB Repository 25
mysql-connectors-community/x86_64 MySQL Connectors Community 141
mysql-tools-community/x86_64 MySQL Tools Community 105
mysql80-community/x86_64 MySQL 8.0 Community Server 161
updates/7/x86_64 CentOS-7 - Updates 1787
ls /etc/yum.repos.d/
CentOS-Base.repo CentOS-Media.repo mysql-community.repo
CentOS-CR.repo CentOS-Sources.repo mysql-community-source.repo
CentOS-Debuginfo.repo CentOS-Vault.repo
CentOS-fasttrack.repo mongodb-org-4.2.repo
cat /etc/yum.repos.d/CentOS-Base.repo
[extras]
name=CentOS-$releasever - Extras
baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
YUM
yum list ansible
Installed Packages
ansible.noarch 2.9.6-1.el7 @epel
/etc/systemd/system
curl http://localhost:5000
Hello, World!
Services
/etc/systemd/system
/usr/bin/python3 /opt/code/my_app.py
/usr/bin/python3 /opt/code/my_app.py my_app.service
* Serving Flask app "my_app" (lazy loading)
* Environment: production [Service]
WARNING: This is a development server. Do not use it in a production deployment. ExecStart=
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
systemctl daemon-reload
curl http://localhost:5000
Hello, World!
systemctl start my_app
Services
/etc/systemd/system
systemctl status my_app my_app.service
● my_app.service
Loaded: loaded (/etc/systemd/system/my_app.service; static; vendor preset: disabled) [Service]
Active: active (running) since Tue 2020-04-07 09:01:39 UTC; 2s ago ExecStart= /usr/bin/python3 /opt/code/my_app.py
Main PID: 5038 (python3)
CGroup: /system.slice/my_app.service
└─5038 /usr/bin/python3 /tmp/app/my_app.py
curl http://localhost:5000
Hello, World!
Services
/etc/systemd/system
systemctl status my_app my_app.service
● my_app.service
Loaded: loaded (/etc/systemd/system/my_app.service; static; vendor preset: disabled) [Service]
Active: active (running) since Tue 2020-04-07 09:01:39 UTC; 2s ago ExecStart= /usr/bin/python3 /opt/code/my_app.py
Main PID: 5038 (python3)
CGroup: /system.slice/my_app.service
└─5038 /usr/bin/python3 /tmp/app/my_app.py
[Service]
Type=notify
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecReload=/bin/kill -s HUP $MAINPID
Restart=always
StartLimitBurst=3
StartLimitInterval=60s
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
[Install]
WantedBy=multi-user.target
Labs
VI Editor
Working with Files
cat > index.html
CTLR + D 59
Poem By: Meine Klaus, Schenker Rudolf
VI Editor
vi index.html
COMMAND INSERT
MODE MODE
esc i
VI Editor - Command Mode
K
>
Move Around
> H
> J L
>
Delete x dd
Command :
Save :w :w filename
Quit (Discard) :q
Find /of n
Lab Setup
Labs
Virtualization S/W
Type 1
VM VM VM
Hypervisor
Baremetal (Server)
Virtualization S/W
Type 1 Type 2
VM VM VM
VM VM VM Hypervisor
• Commercial
• Install Anywhere –
• FREE
Windows, Linux
• OpenSource
• Snapshots & Clones
• Install Anywhere –
Windows, Linux, MAC • VMWare Player:
• Snapshots & Clones • Free
• Run Multiple VMs • Windows/Linux
• Networking • One VM at a time
• No Snapshots
• VMWare Fusion:
• Free
Oracle VirtualBox VMWare Workstation • Mac
• One VM at a time
• No Snapshots
Oracle VirtualBox
• Support:
• Windows, MAC OS X, Linux, Solaris
https://www.virtualbox.org/manual/ch01.html#
hostossupport
• Resource Requirements:
• CPU: x86 Intel or AMD
• Memory: 512 MB
• Disk space: 30 MB
• Recommended Resources:
• CPU: Dual or Quadcore
• Memory: 4 GB
• Disk Space: 100 GB
https://www.virtualbox.org/wiki/Downloads
The more the better
Oracle VirtualBox
Oracle VirtualBox
Oracle VirtualBox
Images
https://www.osboxes.org/
Oracle VirtualBox
Start
References
• https://communities.vmware.com/thread/579385
• https://www.vmware.com/products/workstation-
player.html#compare
Labs
Connectivity
Frequently Asked Questions
• How do I connect to the VM?
• How do I SSH into my VM?
• Why can’t I access the server on my VM?
• What’s Port mapping?
79
Guest
Virtual Machine
Host
LAPTOP 80
81
Guest Guest
Windows
Virtual Machine Virtual Machine
Host LAPTOP 82
guest> service sshd status
Redirecting to /bin/systemctl status sshd.service Guest Guest
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2020-03-22 11:57:47 UTC; 1 day 18h ago
Docs: man:sshd(8)
man:sshd_config(5) Windows
Main PID: 2406 (sshd)
CGroup: /system.slice/sshd.service 192.168.1.10 192.168.1.11
└─2406 /usr/sbin/sshd -D -u0
Virtual Machine Virtual Machine
Host LAPTOP 83
IP Address
guest> ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 52:54:00:8a:fe:e6 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global noprefixroute dynamic eth0
valid_lft 86387sec preferred_lft 86387sec
84
Start SSH service
guest> service sshd status
Redirecting to /bin/systemctl status sshd.service
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2020-03-25 09:29:51 UTC; 3h 53min ago
Docs: man:sshd(8)
man:sshd_config(5)
87
IP Address
ip addr show
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fa
1000
link/ether 02:0e:0c:9a:00:f0 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.5/24 brd 192.168.1.255 scope global enp0s3
88
VirtualBox Networking
Guest
Virtual Machine
89
??
LAN
192.168.1.10
192.168.1.0
Host Only 192.168.5.1
192.168.5.2 192.168.5.3
Host-Only
Network ifconfig
192.168.5.0 en9: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mt
LAN
ether 64:4b:f0:20:6a:6b
inet 192.168.1.10 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=201<PERFORMNUD,DAD>
192.168.1.10
status: active 192.168.1.0
vboxnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu
192.168.5.4 192.168.5.5 ether 0a:00:27:00:00:00
inet 192.168.5.1 netmask 0xffffff00 broadcast 192.168.5.255
Host Only 192.168.5.1
192.168.5.2 192.168.5.3
Host-Only
Network
192.168.5.0
LAN
192.168.1.10
192.168.1.0
192.168.5.4 192.168.5.5
Network Address Translation (NAT) Network
192.168.5.1
192.168.5.2 192.168.5.3
NAT Network
Host-Only
Network
192.168.5.0
192.168.5.0
LAN From: To:
From: To: From: To: 192.168.1.11 192.168.1.10
192.168.5.2 192.168.1.11 192.168.1.10 192.168.1.10
192.168.5.2 192.168.1.11
192.168.1.0 Here’s your data..
Read DB
192.168.5.4 192.168.5.5
Network Address Translation (NAT)
192.168.5.1
192.168.5.2 192.168.5.3
NAT Network
192.168.5.0
LAN
192.168.1.10 192.168.1.11
192.168.1.0
192.168.5.4 192.168.5.5
192.168.1.26
192.168.1.25
Bridge Network
192.168.1.12 192.168.1.13
BRIDGE
Network
LAN
192.168.1.10 192.168.1.11
192.168.1.0
192.168.1.14 192.168.1.15
192.168.1.26
192.168.1.25
Bridge Network
192.168.1.12 192.168.1.13 192.168.1.14 192.168.1.15
BRIDGE
Network
LAN
192.168.1.10 192.168.1.11
192.168.1.0
192.168.1.26
192.168.1.25
Internet Connectivity
Network Address
Translation (NAT) Host-Only Network Bridged
192.168.5.1 192.168.5.1
80 80
5000 8080
22 2222
Requirement Solution
VMs must be able to reach the internet/other systems in the network NAT
VMs must NOT be visible in the external network and VMs must NOT be able to reach Host Network
internet/other systems in the network
VMs must be able to reach each other and the internet but NOT visible in the external Host Network + NAT
network NAT Network
VirtualBox Networking
VM can reach VMs can reach Host can reach VM Other systems in network Solution
internet/other systems each other (Without Port can reach VM
in the network forwarding)
Yes No No No NAT
vagrant up
1. Download
Bringing machine 'default' up with 'virtualbox' provider...
2. Create VM ==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
3. Create Networks ==> default: Checking if box 'centos/7' version '1905.1' is up to date...
==> default: Setting the name of the VM: centos2_default_1586895892002_53453
4. Configure Networking ==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
5. Configure Port Forwarding ==> default: Forwarding ports...
default: 22 (guest) => 2200 (host) (adapter 1)
6. Boot up VM ==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
==> default: Machine booted and ready!
Getting started
https://www.vagrantup.com/
Vagrant Init
vagrant init centos/7
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read the comments in the
Vagrantfile as well as documentation on `vagrantup.com` for more information on using
Vagrant.
ls centos/7
Vagrantfile
vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'centos/7' version '1905.1' is up to date...
==> default: Setting the name of the VM: centos2_default_1586895892002_53453
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes... https://app.vagrantup.com/boxes
Vagrant Commands
vagrant
Usage: vagrant [options] <command> [<args>]
Common commands:
init initializes a new Vagrant environment by creating a Vagrantfile
up starts and provisions the vagrant environment
suspend suspends the machine
resume resume a suspended vagrant machine
halt stops the vagrant machine
destroy stops and deletes all traces of the vagrant machine
status outputs status of the vagrant machine
reload restarts vagrant machine, loads new Vagrantfile configuration
snapshot manages snapshots: saving, restoring, etc.
vagrant ssh
[vagrant@localhost ~]$
Vagrantfile
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.synced_folder "../data", "/vagrant_data"
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
config.vm.provision "shell", inline: <<-SHELL
apt-get update
apt-get install -y apache2
SHELL
end
Vagrant Providers
• VirtualBox
• VMware
• Hyper-V
• Docker
• Custom
Review
Lab Linux Applications DB Security Networking Storage
DevOps Pre-Requisites
CKA Puppet
CKAD DevOps
What to test
Check Ignore
Facts Delivery/Speed
Explanation Noise
Code/Typos Pauses/Stops
Analogies/Examples Animation
Student/Expert
How to Review
just enough
Applications
Introduction
• JavaScript –
NodeJS
• Python
• Java
https://insights.stackoverflow.com/survey/2019#technology
Types
Compiled Interpreted
C C++
Compiled
MyClass.java
if __name__ == '__main__':
print_message()
python main.py
Hello World
Packages/Modules/Libraries
• Filesystems
• Math
• Operating system
• HTTP
• Security
• Networking
Build
• Compile
• Run Tests
• Package
• Delivery
NETWORKING
Networking Pre-Requisites
• Switching
• Routing
• Default Gateway
• DNS Configurations on Linux
just enough
DNS
just enough
Introduction
About Java
wget https://download.java.net....
openjdk-13.0.2_linux-x64_bin.tar.gz
https://jdk.java.net/13/
Java Development Kit (JDK)
java
ls jdk-13.0.2/bin
jaotc javadoc jdeprscan jinfo jps jstatd rmiregistry
jar javap jdeps jjs jrunscript keytool serialver
jarsigner jcmd jfr jlink jshell pack200 unpack200
java jconsole jhsdb jmap jstack rmic
javac jdb jimage. jmod jstat rmid
Before v9
Build
Compile
MyClass.java
Dependency 1 Service1.class
Dependency 2 Service2.class
Dependency 3
Utility.class
Tools.class
Java Archive
(JAR)
Package
META-INF/MANIFEST.MF
MyClass.class
Dependency 3
Utility.class
Tools.class
Image 1
Java Archive Web Archive
Image 2 HTML 1 (JAR) (WAR)
HTML 2
javac MyClass.java
jar cf MyClass.jar ..
javadoc MyClass.java
Build Process
Build Tools
2.Package
3.Document
Gradle
https://github.com/arun-gupta/docker-java-sample
Summary
• Java
• Java Runtime Environment
• Java Development Kit
• Compiling a Java application
• Packaging a given application to JARs
• What are Build Tools?
DevOps Course
Labs
just enough
JavaScript
https://enonic.com/blog/websites-past-and-present
NodeJS
const a = 10, b = 5;
• Files
• Web Servers
• Databases
• Security
• Many More
https://www.npmjs.com/
NPM Commands
npm -v
6.13.7
app.js my_application
var file = require("file");
node_modules
file.mkdirs("/tmp/dir1") file
LICENSE
README.md
node -e "console.log(module.paths)"
package.json
[ '/app/node_modules', '/node_modules' ]
lib
npm install file -g app.js
Common Modules
ls /usr/lib/node_modules/npm/node_modules/ ls /usr/lib/node_modules/
package.json
Application Dependencies
{
"name": "example-contentful-theExampleApp-js",
"version": "0.0.0",
"private": true,
"dependencies": {
"body-parser": "^1.18.2",
"contentful": "^6.0.0",
"cookie-parser": "~1.4.3",
"dotenv": "^5.0.0",
"execa": "^0.9.0",
"express": "^4.16.2",
"helmet": "^3.11.0",
"lodash": "^4.17.5",
"marked": "^0.3.16",
"morgan": "^1.9.1",
"pug": "~2.0.0-beta6"
}
}
Labs
just enough
Python
• Free
• Open source
• Cross Platform Compatible
Download
https://www.python.org/downloads/
Versions
python2 python3
Python 2.7.16 (default, Nov 17 2019, 00:07:27) Python 3.6.8 (default, Nov 21 2019, 19:31:34)
[GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux2 [GCC 8.3.1 20190507 (Red Hat 8.3.1-4)] on linux
Type "help", "copyright", "credits" or "license" Type "help", "copyright", "credits" or "license"
for more information. for more information.
>>> exit() >>> exit()
python2 -V python3 -V
Python 2.7.16 Python 3.6.8
Python Commands
Hello World
def print_message():
print("Hello World")
if __name__ == '__main__':
print_message()
Labs
just enough
Python Package Manager (pip)
python2 -V python3 -V
Python 2.7.16 Python 3.6.8
pip2 -V pip3 -V
pip 9.0.3 from /usr/lib/python2.7/site-packages pip 9.0.3 from /usr/lib/python3.6/site-packages
(python 2.7) (python 3.6)
pip -V
pip 9.0.3 from /usr/lib/python2.7/site-packages (python 2.7)
usr
lib
python2.7
site-packages
Python3.6
site-packages
lib64
python2.7
site-packages
Flask-1.1.1.dist-info
python3.6
site-packages
Python Package Manager (pip)
pip install flask
</>
</>
188
Application Types
189
Standalone vs Client-Server
Server
Web Client
Chat
Desktop Client Server
Mobile Client
Servers
Web Application
Server Server
Servers
Application
Web
Server
Servers
Web Application DB
Server Server Server
just enough
https://insights.stackoverflow.com/survey/2019
Web Frameworks
REQUEST
https://www.shop-app.com
Web
Server
@GetMapping("/products")
public String[] getProducts() {
return getProductList();
}
}
Application Code
Web Frameworks
DemoApplication.java demo.py demo.js
package com.example.demo; from flask import Flask const express = require('express')
// <code hidden> const app = express()
app = Flask(__name__)
@SpringBootApplication app.get('/products', (req, res) =>
@app.route(‘/products') res.send(getProductList()))
@RestController def hello():
public class DemoApplication { return getProductList()
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args); if __name__=='__main__':
} app.run()
@GetMapping("/products")
public String[] getProducts() {
return getProductList();
}
}
Application Code
Web Server
DemoApplication.java
package com.example.demo;
// <code hidden>
@SpringBootApplication
@RestController
public class DemoApplication {
@GetMapping("/products")
public String[] getProducts() {
return getProductList();
Web
} Server
}
Application Code
Web Server
DemoApplication.java
package com.example.demo;
// <code hidden>
@SpringBootApplication
@RestController
public class DemoApplication {
8080 80 8000
Web Server
DemoApplication.java
package com.example.demo;
Application 3 Code
Static vs Dynamic Websites
just enough
• Open source
• Web Server
Install Apache Web Server
yum install httpd
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
Document Root
#
/var/www/html
DocumentRoot "/var/www/html”
#
# prevent Apache from glomming onto all bound IP addresses.
#
DNS Name IP Address
#Listen 12.34.56.78:80
www.houses.com
Listen 80 192.168.1.10
Config File
#
/etc/hosts
# DocumentRoot: The directory out of which you will serve your
# documents.
# Host Database By default, all requests are taken from this directory, but
127.0.0.1 localhost
# symbolic
127.0.0.1
links and aliases mayhttp://www.houses.com
www.houses.com
be used to point to other locations.
http://localhost
http://localhost:80
#
DocumentRoot "/var/www/html”
Web
Server
#
# ServerName gives the name and port that the server uses to identify 80
itself.
# This can often be determined automatically, but we recommend you Default HTTP Port - 80
specify
# it explicitly to prevent problems during startup. HTML
# CSS
# If your host doesn't have a registered DNS name, enter its IP address
here. JavaScript
# Document Root
#ServerName www.example.com:80 /var/www/html
ServerName www.houses.com:80
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80
Config File
#
Web
# DocumentRoot: The directory out of which you will serve your
Server
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be usedhttp://www.houses.com
http://localhost
http://localhost:80
to point to other locations.
# HTML
DocumentRoot "/var/www/html” CSS
# JavaScript
# ServerName gives the name and port that the server uses to identify Server: www.houses.com
Document Root: /var/www/houses
itself. VirtualHost
# This can often be determined automatically, but we recommend you
specify HTML
# it explicitly to prevent problems during startup.
http://www.oranges.com CSS
#
# If your host doesn't have a registered DNS name, enter its IP address JavaScript
here. Server: www.oranges.com
Document Root: /var/www/oranges
# VirtualHost
#ServerName www.example.com:80
Document Root
ServerName www.houses.com:80 /var/www/html
here.
#
DNS#ServerName
Name IP Address
www.example.com:80
ServerName www.houses.com:80
www.houses.com
www.oranges.com
192.168.1.10
192.168.1.10
Config File
/etc/hosts
Web
Server
# Host Database
127.0.0.1 localhost http://www.houses.com
http://localhost
http://localhost:80
<VirtualHost
127.0.0.1
*:80>
www.houses.com
ServerName
127.0.0.1 www.houses.com
www.oranges.com HTML
DocumentRoot /var/www/houses
</VirtualHost> CSS
JavaScript
Server: www.houses.com
Document Root: /var/www/houses
VirtualHost
<VirtualHost *:80>
Include conf/houses.conf ServerName www.houses.com
DocumentRoot /var/www/houses
Include conf/oranges.conf </VirtualHost>
/etc/httpd/conf/oranges.conf
<VirtualHost *:80>
ServerName www.oranges.com
DocumentRoot /var/www/oranges
</VirtualHost>
Labs
References
• https://www.digitalocean.com/community/tutorials/how-to-install-
the-apache-web-server-on-centos-7
just enough
NGINX
just enough
APACHE TOMCAT
Install Apache Tomcat
yum install java-1.8.0-openjdk-devel
wget https://downloads.apache.org/tomcat/
tomcat-8/v8.5.53/bin/apache-tomcat-8.5.53.tar.gz
./apache-tomcat-8.5.53/bin/startup.sh
http://tomcat.apache.org/download-80.cgi
View Server
https://localhost:8080
Apache Tomcat Directory
ls –l apache-tomcat-8.5.53
-rw-r----- 1 19318 Mar 11 10:06 BUILDING.txt catalina-tasks.xml
-rw-r----- 1 5408 Mar 11 10:06 CONTRIBUTING.md catalina.bat
catalina.sh
-rw-r----- 1 57011 Mar 11 10:06 LICENSE ciphers.bat
-rw-r----- 1 1726 Mar 11 10:06 NOTICE ciphers.sh
-rw-r----- 1 3255 Mar 11 10:06 README.md configtest.bat
-rw-r----- 1 7136 Mar 11 10:06 RELEASE-NOTES configtest.sh
-rw-r----- 1 16262 Mar 11 10:06 RUNNING.txt daemon.sh
drwxr-x--- 2 4096 Mar 18 10:17 bin digest.bat
digest.sh
drwx------ 2 4096 Mar 11 10:06 conf setclasspath.bat
drwxr-x--- 2 4096 Mar 18 10:17 lib setclasspath.sh
drwxr-x--- 2 4096 Mar 11 10:03 logs shutdown.bat
drwxr-x--- 2 4096 Mar 18 10:17 temp shutdown.sh
drwxr-x--- 7 4096 Mar 11 10:04 webapps startup.bat
drwxr-x--- 2 4096 Mar 11 10:03 work startup.sh
tool-wrapper.bat
tool-wrapper.sh
version.bat
version.sh
Apache Tomcat Directory
ls –l apache-tomcat-8.5.53
-rw-r----- 1 19318 Mar 11 10:06 BUILDING.txt
-rw-r----- 1 5408 Mar 11 10:06 CONTRIBUTING.md <!-- A "Connector" represents an endpoint
catalina.policy by which requests are received
-rw-r----- 1 57011 Mar 11 10:06 LICENSE
catalina.properties and responses are returned. Documentation at :
-rw-r----- 1 1726 Mar 11 10:06 NOTICE
Java HTTP Connector: /docs/config/http.html
-rw-r----- 1 3255 Mar 11 10:06 README.md context.xml Java AJP Connector: /docs/config/ajp.html
-rw-r----- 1 7136 Mar 11 10:06 RELEASE-NOTES jaspic-providers.xml APR (HTTP/AJP) Connector: /docs/apr.html
-rw-r----- 1 16262 Mar 11 10:06 RUNNING.txt -->
jaspic-providers.xsd <Connector port="8080" protocol="HTTP/1.1"
drwxr-x--- 2 4096 Mar 18 10:17 bin
drwx------ 2 4096 Mar 11 10:06 conf logging.properties connectionTimeout="20000"
redirectPort="8443" />
drwxr-x--- 2 4096 Mar 18 10:17 lib server.xml <!-- A "Connector" using the shared thread pool-->
drwxr-x--- 2 4096 Mar 11 10:03 logs <!--
tomcat-users.xml
drwxr-x--- 2 4096 Mar 18 10:17 temp <Connector executor="tomcatThreadPool"
drwxr-x--- 7 4096 Mar 11 10:04 webapps tomcat-users.xsd port="8080" protocol="HTTP/1.1"
drwxr-x--- 2 4096 Mar 11 10:03 work web.xml connectionTimeout="20000"
redirectPort="8443" />
Apache Tomcat Directory
ls –l apache-tomcat-8.5.53
-rw-r----- 1 19318 Mar 11 10:06 BUILDING.txt
-rw-r----- 1 5408 Mar 11 10:06 CONTRIBUTING.md
-rw-r----- 1 57011 Mar 11 10:06 LICENSE
-rw-r----- 1 1726 Mar 11 10:06 NOTICE
-rw-r----- 1 3255 Mar 11 10:06 README.md
-rw-r----- 1 7136 Mar 11 10:06 RELEASE-NOTES
-rw-r----- 1 16262 Mar 11 10:06 RUNNING.txt
drwxr-x--- 2 4096 Mar 18 10:17 bin
drwx------ 2 4096 Mar 11 10:06 conf catalina.2020-03-18.log
drwxr-x--- 2 4096 Mar 18 10:17 lib catalina.out
host-manager.2020-03-18.log
drwxr-x--- 2 4096 Mar 11 10:03 logs localhost.2020-03-18.log
drwxr-x--- 2 4096 Mar 18 10:17 temp localhost_access_log.2020-03-18.txt
drwxr-x--- 7 4096 Mar 11 10:04 webapps manager.2020-03-18.log
drwxr-x--- 2 4096 Mar 11 10:03 work
Apache Tomcat Directory
ls –l apache-tomcat-8.5.53 jar –cvf app.war *
-rw-r----- 1 19318 Mar 11 10:06 BUILDING.txt
-rw-r----- 1 5408 Mar 11 10:06 CONTRIBUTING.md
-rw-r----- 1 57011 Mar 11 10:06 LICENSE mvn package
-rw-r----- 1 1726 Mar 11 10:06 NOTICE
-rw-r----- 1 3255 Mar 11 10:06 README.md
-rw-r----- 1 7136 Mar 11 10:06 RELEASE-NOTES gradle build
-rw-r----- 1 16262 Mar 11 10:06 RUNNING.txt
drwxr-x--- 2 4096 Mar 18 10:17 bin
drwx------ 2 4096 Mar 11 10:06 conf
drwxr-x--- 2 4096 Mar 18 10:17 lib
drwxr-x--- 2 4096 Mar 11 10:03 logs
drwxr-x--- 2 4096 Mar 18 10:17 temp
drwxr-x--- 7 4096 Mar 11 10:04 webapps
drwxr-x--- 2 4096 Mar 11 10:03 work
app.war
Application Code
Web Frameworks
ls –l apache-tomcat-8.5.53 jar –cvf app.war *
-rw-r----- 1 19318 Mar 11 10:06 BUILDING.txt
-rw-r----- 1 5408 Mar 11 10:06 CONTRIBUTING.md
-rw-r----- 1 57011 Mar 11 10:06 LICENSE mvn package
-rw-r----- 1 1726 Mar 11 10:06 NOTICE
-rw-r----- 1 3255 Mar 11 10:06 README.md
-rw-r----- 1 7136 Mar 11 10:06 RELEASE-NOTES gradle build
-rw-r----- 1 16262 Mar 11 10:06 RUNNING.txt
drwxr-x--- 2 4096 Mar 18 10:17 bin
drwx------ 2 4096 Mar 11 10:06 conf
drwxr-x--- 2 4096 Mar 18 10:17 lib
drwxr-x--- 2 4096 Mar 11 10:03 logs
META-INF
drwxr-x--- 2 4096 Mar 18 10:17 temp WEB-INF
drwxr-x--- 7 4096 Mar 11 10:04 webapps hello.jsp
drwxr-x--- 2 4096 Mar 11 10:03 work images
app.war index.html
Application Code
Verify
cat ~/apache-tomcat-8.5.53/logs/catalina.out
18-Mar-2020 10:43:32.769 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application
directory [/home/vagrant/apache-tomcat-8.5.53/webapps/ROOT] has finished in [13] ms
18-Mar-2020 10:43:32.769 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application
directory [/home/vagrant/apache-tomcat-8.5.53/webapps/manager]
18-Mar-2020 10:43:32.783 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application
directory [/home/vagrant/apache-tomcat-8.5.53/webapps/manager] has finished in [14] ms
18-Mar-2020 10:43:32.784 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
18-Mar-2020 10:43:32.789 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 407 ms
18-Mar-2020 11:21:23.503 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive
[/home/vagrant/apache-tomcat-8.5.53/webapps/app.war]
18-Mar-2020 11:21:23.560 INFO [localhost-startStop-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive
[/home/vagrant/apache-tomcat-8.5.53/webapps/app.war] has finished in [57] ms
View Sample Application
https://localhost:8080/app
Labs
just enough
Web Frameworks
https://insights.stackoverflow.com/survey/2019
Project Structure main.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
my-application def hello():
LICENSE return 'Hello, World!'
README.md if __name__=='__main__':
requirements.txt pip install –r requirements.txt app.run()
main.py
utils python main.py
tests * Serving Flask app "main" (lazy loading)
config * Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
routes Use a production WSGI server instead.
services * Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
db
core
Production Deployment
from flask import Flask
main.py
app = Flask(__name__)
• Gunicorn @app.route('/')
• uWSGI def hello():
return 'Hello, World!'
• Gevent if __name__=='__main__':
• Twisted Web app.run()
gunicorn main:app -w 2
[2020-03-10 09:53:29 +0000] [2916] [INFO] Starting gunicorn 20.0.4
[2020-03-10 09:53:29 +0000] [2916] [INFO] Listening at: http://127.0.0.1:8000 (2916)
[2020-03-10 09:53:29 +0000] [2916] [INFO] Using worker: sync
[2020-03-10 09:53:29 +0000] [2919] [INFO] Booting worker with pid: 2919
[2020-03-10 09:53:29 +0000] [2921] [INFO] Booting worker with pid: 2921
https://flask.palletsprojects.com/en/1.1.x/deploying/wsgi-standalone/
Labs
just enough
Express.js
Project Structure
app.js
my-application const express = require('express')
const app = express()
LICENSE
app.get('/products', (req, res) =>
res.send(getProductList()))
README.md
app.use(express.static(path.join(__dirname, 'public')));
package.json
app.js app.listen(3000);
public
tests
config
routes
services
db
core
Project Structure
package.json
{
"name": "my-application",
my-application npm install "version": "0.0.0",
"private": true,
LICENSE "dependencies": {
README.md node app.js "dotenv": "^5.0.0",
"execa": "^0.9.0",
package.json "express": "^4.16.2"
app.js npm run start :dev },
"scripts": {
public "debug": "node debug app.js",
tests "start": "NODE_ENV=production node app.js",
config "start:dev": "NODE_ENV=dev node app.js",
routes "test:e2e": "node tests/run-e2e-test.js",
"test:unit": "jest tests/unit",
services "test:unit:watch": "jest tests/unit --watch"
db }
core }
Project Structure
http://localhost:3000
my-application npm install
LICENSE
README.md node app.js
package.json
app.js npm run start :dev
public
tests
supervisord
config
routes
forever
services
db
pm2
core
pm2
ip addr show
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fa
1000
link/ether 02:0e:0c:9a:00:f0 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global enp0s3
245
Ports
main.py
from flask import Flask
app = Flask(__name__)
?
10.0.2.16 @app.route('/')
wlp0s2 def hello():
return 'Hello, World!'
?
10.0.2.15
if __name__=='__main__':
enp0s3
app.run()
app.run(port=8000)
app.run(port=8000,
app.run(port=8000, host='10.0.2.15')
host='0.0.0.0')
, host=‘127.0.0.1’)
http://10.0.2.15:8000
http://10.0.2.16:8000
246
Ports
ip addr show
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
1000
link/ether 02:0e:0c:9a:00:f0 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global enp0s3
247
Ports
http://127.0.0.1:8000
http://localhost:8000
248
Ports
127.0.0.1 127.0.0.1
lo lo
10.0.2.16
wlp0s2
10.0.2.15
enp0s3
http://127.0.0.1:8000 http://127.0.0.1:8000
http://localhost:8000 http://localhost:8000
249
Labs
Databases
Why?
Databases
• MySQL
• MongoDB SQL
• Redis SQL
SQL
SQL
NoSQL
Key-Value
SQL
SQL
NoSQL
NoSQL
NoSQL
NoSQL
NoSQL
https://insights.stackoverflow.com/survey/2019#technology
SQL
Tabular/Relational Databases
{ { {
"name": "Aryan Kumar", "name": "Lily Oliver", "name": "Lauren Rob",
"age": 10, "age": 15, "age": 13,
"location": "New York", "location": "Bangalore", "location": "Bangalore",
"Grade": "A" "Grade": "B" "Grade": "C"
} } }
SQL vs NoSQL
SELECT * from persons where AGE > 10 db.persons.find( { age:Collection
{ $gt: 10 } } )
{ {
"name": "John Doe", "name": "Dave Smith",
Table "age": 45, "age": 34,
"location": "New York", "location": "New York",
Name Age Location Salary Grade "salary": 5000 "salary": 4000,
"organization": "ACME"
John Doe 45 New York 5000 } }
• Open source
• Fast
• Reliable
• SQL
Community Commercial
https://www.mysql.com/products/
Install
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html
Validate
cat /var/log/mysqld.log
2020-03-19T17:57:37.375709Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 4162
2020-03-19T17:57:39.467035Z 5 [Note] A temporary password is generated for root@localhost: g/io%pFlE77m
2020-03-19T17:57:41.582829Z 0 [System] [MY-010116]A[Server]
temporary password is generated
/usr/sbin/mysqld for root@localhost:
(mysqld 8.0.19) g/io%pFlE77m
starting as process 4211
2020-03-19T17:57:43.812826Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-03-19T17:57:44.021160Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL
Community Server - GPL.
2020-03-19T17:57:44.245102Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
2020-03-19T18:04:21.190127Z 8 [Warning] [MY-013360] [Server] Plugin sha256_password reported: ''sha256_password' is deprecated and will be removed in a future release.
Please use caching_sha2_password instead'
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Validate
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
mysql_secure_installation
user password
'username'@'host'
Create User
mysql –u root -pg/io%pFlE77m
'username'@'host'
192.168.1.10
Create User
mysql –u root -pg/io%pFlE77m
192.168.1.10
Privileges
mysql> GRANT <PERMISSION> ON <DB.TABLE> TO 'john'@'%';
• Open source
• NoSQL
• Scalable
• High Performance
Community Enterprise
https://www.mongodb.com/what-is-mongodb
MongoDB
{ {
"name": "John Doe", "name": "Dave Smith",
"age": 45, "age": 34,
"location": "New York", "location": "New York",
"salary": 5000 "salary": 4000,
"organization": "ACME"
} Document }
{ { {
"name": "Aryan Kumar", "name": "Lily Oliver", "name": "Lauren Rob",
"age": 10, "age": 15, "age": 13,
"location": "New York", "location": "Bangalore", "location": "Bangalore",
"Grade": "A" "Grade": "B" "Grade": "C"
} } }
Collection
MongoDB
{ {
"name": "John Doe", "name": "Dave Smith", {
"age": 45, "age": 34, "name": "Aryan Kumar",
"location": "New York", "location": "New York", "age": 10,
"salary": 5000 "salary": 4000, "location": "New York",
"organization": "ACME" "Grade": "A"
} Document } }
{
"name": "Lauren Rob",
"age": 13,
{ { { "location": "Bangalore",
"name": "Aryan Kumar", "name": "Lily Oliver", "name": "Lauren Rob", "Grade": "C"
"age": 10, "age": 15, "age": 13, }
"location": "New York", "location": "Bangalore", "location": "Bangalore",
"Grade": "A" "Grade": "B" "Grade": "C"
} } } {
"name": "Lily Oliver",
"age": 15,
Collection "location": "Bangalore",
"Grade": "B"
}
{
"name": "Lauren Rob",
{ { { "age": 13,
"name": "Aryan Kumar", "name": "Lily Oliver", "name": "Lauren Rob", "location": "Bangalore",
"age": 10, "age": 15, "age": 13, "Grade": "C"
"location": "New York", "location": "Bangalore", "location": "Bangalore", }
"Grade": "A" "Grade": "B" "Grade": "C"
} } }
Collection Collection
Database
MongoDB
MongoDB Server
Install
Install
Install
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
Start DB Service
systemctl start mongod
www.kodekloud.com