🎬 Introduction to Servers & Virtualization
💡 Preface
This module is part of a course on DevOps.
Checkout the course introduction for more information
This module is part of chapter 2
What is a Server
A server is a dedicated computer that computes, stores and manages data or serves a specific purpose
For example, a server could be running a database that stores important data, run a website for a company, or a set of services
Types of servers include:
- Mail server
- Web server
- Database server
- DNS server
- Proxy servers
- Application servers
Servers can either be physical or virtual.
Physical servers are ones that are made up of physical hardware, like the ones in a datacenter.
You can also setup a physical server by using your old desktop hardware, or when you buy a Rasberry Pi or a mini PC like an NUC.
When setting up a server, hardware is important
We want hardware that is reliable and long lasting to minimise cost and increase reliability and longevity
For DevOps, SRE and platform engineers the most important part of setting up servers is choosing the hardware resources such as CPU, RAM memory and Hard disk types and sizes.
Why Servers are important for DevOps , SRE and Cloud Engineers
Throughout a DevOps career, you will be working either directly or indirectly with servers, whether you are working with real on-prem hardware, or servers in the cloud, or even with serverless technology, you will still be indirectly working with servers and will need to consider important aspects of how servers operate.
For example:
- "How much traffic can this server handle?" (does not matter if its physical or virtual!)
- "How much data can this server store?"
- "Why is my application on this server so slow?"
"The cloud is just someone else's computer"
Even if this is a cloud product or "server-less" technology where you cannot interact with a server directly, there is always a server somewhere and we will need to consider performance and reliability of our system running on that server
What is Virtualisation
Not all servers are physical.
A Virtual server (or Virtual Machine) is a software-based server that acts as a real server.
We can run this software on a physical server and run multiple virtual server
So it allows us to slice up and share physical hardware among multiple virtual servers
If you have a physical server with 24 cores and 64GB of RAM, you could host a few 4 core 8GB RAM virtual servers
Why run Virtual machines
There are a number of benefits why Virtual machines are great.
- Isolation: Having seperate servers with seperate functions, like running a Web server and a Database server
- Automation: Using automation software or tools can help recreate servers and roll out updates
- Scalability: Ability to quickly add more servers when demands increase
Virtualisation software
There are many types of virtualization software that allows us to create Virtual machines
For simplicity and compatibility, in this course we will use
Virtual Box as it can run on Windows, Linux and MacOS and its the simplest one to start with
Requirements
In order to follow along with this module, you will need an operating system with hypervisor capabilities.
For Windows: check if Virtualization is enabled by:
- Right click your taskbar and open
Task Manager
- Select the
Performance
window - Check the right side of the panel, see
Virtualization
if its enabled or not.
For Linux: check if Virtualization is enabled by:
- run
sudo cat /proc/cpuinfo
- If you see the below flags, Virtualization is enabled in the BIOS
vmx
: Intel VT-x, virtualization support enabled in BIOS.svm
: AMD SVM, virtualization enabled in BIOS.
You will need at least 2GB extra RAM and 25GB of hard disk space to create a Virtual machine for this module
These numbers are early access guide only and may be reviewed and adjusted based on course feedback
Installation
Windows:
In this module we will walk through the installation on both Windows & Linux.
for Windows its as simple as following the installer prompts
Linux
For Linux, the installation can be slightly more complicated.
- Virtualization needs to be enabled as per above Requirements
- You need latest kernel modules for your computer
- You either need to turn off Secure boot in the BIOS, or you need to manually sign the VirtualBox kernel modules by using
mokutil
Install Virtual Box on Ubuntu:
# install a few dependencies
sudo apt-get update
sudo apt-get install -y ca-certificates curl wget gnupg
# download oracle public key
wget -O- https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --yes --output /usr/share/keyrings/oracle-virtualbox-2016.gpg --dearmor
# get your ubuntu codename for your source list
cat /etc/os-release | grep CODENAME
# update apt sources
sudo echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian jammy contrib" >> /etc/apt/sources.list.d/virtualbox.list
sudo apt-get update
sudo apt-get install -y virtualbox-7.1
Preferences
On the Preferences page, the most important thing is to select a folder where all our Virtual Machine data will be stored
Creating our first Server
In order to create a virtual server, we need to get an ISO file
What is an ISO image ?
Traditionally, an ISO image file is an image of an optical disk. In the past, we could create copies of CD's or DVD disks by creating ISO images of them and store them as files
For Virtual machines, ISO image files are basically the disks that contains the operating system files that we use to install the operating system onto a Virtual Server.
Download the virtual machine ISO file
In this course we will get Ubuntu Linux from ubuntu.com
Setup Network
One very important component of environments both for in data centers and in the cloud is the network.
Servers communicate with one another over the network.
Networks can be either public (like sitting on the internet) or private or a combination of public and private
- Host-only Networks
This can be used to create a network containing the host and a set of virtual machines, without the need for the host's physical network interface
- NAT Networks
Network Address Translation (NAT) is the simplest way of accessing an external network from a virtual machine. Usually, it does not require any configuration on the host network and guest system. For this reason, it is the default networking mode in Oracle VM VirtualBox.
- Cloud Networks
This can be used to connect a local VM to a subnet on a remote cloud service.
In order for a server to communicate with another server it needs to belong to a network, and in order to belong to a network, a server needs an IP address
An IP is a series of numbers and dots that identify a device that is part of a network.
Networks have an IP range.
We can specify a network range using whats called a CIDR
It's a way for us to "size" our network and know how many IP addresses are available in that network.
There are many online network size calculators out there, but I like to use mxtoolbox
For example, we can create a network with IP starting with 10.0.0.0
and let's say we want 32 IPs , we select /27
Our calculator will show us that this gives us 32 IPs
Our first IP is 10.0.0.0 and we can increment the number at the end all the way up to 31, which in total means that we have 32 IP addresses.
Private IPv4 address ranges include:
- 10.0.0.0 to 10.255.255.255
- 172.16.0.0 to 172.31.255.255
- 192.168.0.0 to 192.168.255.255
Private network ranges are blocked from being used on public networks.
A network can have a really large IP range, because you may want to divide networks into many smaller networks, for example a network for each department or subset of servers.
These divides are called Subnets.
When a device connects to a network its assigned an IP address by DHCP
Port Forwarding
allows us to forward certain ports from our machine to this virtual machine network. This is because the NAT Network is isolated so we need to setup any connections between us and the virtual machine
Now to create the network, we can briefly walk through the VirtualBox UI and look at the default NAT Network that is created.
In this walk through, I'd like you to get a bit more of an understanding of networks, so I would prefer if we create our own and not rely on the default one
The default network could be subject to change which may cause it to break in the future.
To create a network and setup a DHCP for it, we will use the VBoxManage
command line.
On Linux, if you have VirtualBox installed you can simply type VBoxManage in a terminal window and you should see its output.
Let's create our NAT Network and a DHCP for it using the following commands:
For Windows, you will need to add the following directory to your PATH environemnt variable: C:\Program Files\Oracle\VirtualBox
Once done, open a new PowerShell terminal
VBoxManage natnetwork add --netname "my-website" --network "10.0.0.0/27" --enable --ipv6 off
VBoxManage dhcpserver add --netname "my-website" --ip "10.0.0.1" --netmask "255.255.255.224" --lowerip "10.0.0.4" --upperip "10.0.0.30" --enable
VBoxManage natnetwork modify --netname "my-website" --dhcp on
Creating Virtual Machine
On the main panel, we can click on Machine
and New
to get to the server creation page.
give our server a Name
and Folder
where our virtual server data will be created.
We select the ISO Image
that we downloaded previously.
Once we select our ISO file, the rest gets filled out because the software gets the data from the ISO image.
Next important section is Hardware
Hardware
We select our Base Memory
(RAM Memory) and Processors
(CPU)
We learnt about the importance of these resources in our Operating system introduction module
When we choose these resources, we have to consider how much resources our host computer has.
Next we create a hard disk, by filling out Hard Disk File Location and Size
Then we press Finish
to create the virtual server
Now before starting the virtual server, we need to add it to our network we created.
We can do this from the settings page
Server Settings Summary
Here are some of the settings we used in this module when creating our Virtual Machine:
Property | Value |
---|---|
name | my-website-1 |
directory | C:\temp\vms |
memory | 4096MB |
cpu | 4 cores |
disk | 25GB |
During the installation we also provided some Operating system settings. I've recorded those below:
Property | Value |
---|---|
computer name | my-website-1 |
your name | devopsguy |
username | devopsguy |
password (for simplicity of this demo i kept it simple) | devopsguy |
Setup Server Access
Now Virtual Box allows us to access our server by giving us a screen interface.
Now if we wanted to automate things later and remotly manage this server, we need to setup SSH access
Get the local IP to setup port forwarding in Virtual Box.
For this demo, we can set a non-standard port just incase you already have port 22
used on your system.
Therefore the host port we will set it to 2222
and the Guest port (which is the virtual server) will set it as 22
# grab the IP address from the `inet` section
ip addr
The IP address of the virtual server will be the "Guest IP" in the port forward rule.
This means all traffic on our system from port 2222
will not be forwarded to port 22
of our virtual server.
On our Virtual server, we will need to install SSH server.
sudo apt-get update
sudo apt-get install -y openssh-server
Ensure that the SSH server is up and running
sudo service ssh status
sudo service ssh start
sudo service ssh status
We can now see the SSH service is running, but is disabled. So when our VM reboots it will not automatically start up. To make the SSH service start up automatically, we need to enable it. Let's do that
# enable SSH
sudo systemctl enable ssh
# now we can see its enabled:
sudo service ssh status
Now on our system, we can open up Visual Studio code terminal and SSH to our Virtual server:
ssh -p 2222 <username>@127.0.0.1