afm719 / Cloud-Computing-Arahi

0 stars 0 forks source link

Cluster Tutorial (ENG) #2

Open afm719 opened 3 days ago

afm719 commented 3 days ago

Create a Cluster with One Master Machine and Two Nodes (node01 and node02)

Initial Requirements

  1. Download VirtualBox: https://www.virtualbox.org/
  2. Download a compatible Ubuntu distribution (an older version is recommended for compatibility): https://ubuntu.com/download/server

Cluster Specifications

Master Machine:

Node Machines (node01, node02, ...):

Creating the template Machine for Post-Creation of Cluster Machines

  1. Create a machine named template.
  2. Choose a location (usually, leave it as the default).
  3. Load the ISO image.

image

  1. Assign the parameters mentioned earlier.

image

  1. You can leave the default username and password. IMPORTANT: REMEMBER FOR LATER CONFIGURATION.

image

  1. Finish the setup and start the machine (it will ask for the user and password noted earlier).
  2. Once started, run the following commands:
sudo apt update
sudo apt upgrade

If you encounter issues, try installing a newer and more stable version.

  1. Install necessary packages:
sudo apt install net-tools gcc make

Once done, shut down the machine:

sudo shutdown -h now

The template machine is now ready to be cloned.

Creating the Master Machine

  1. Clone the template machine (click the sheep icon and select "Full clone", name it master).
  2. After creation, go to:

Save the configuration.

Network Configuration of the Master Node

To view the available interfaces in the VM, execute the command:

ip link show

You'll see something like:

image

Where:

You need to configure the enp0s8 interface as static using IP address 192.168.0.1. To do this, edit the following file:

sudo vim /etc/netplan/50-cloud-init.yaml

Insert the following content:

network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: true
    enp0s8:
      dhcp4: no
      addresses: [192.168.0.1/24]

If using the VIM editor, the command to save is ESC :w and to exit is ESC :q!.
If using the NANO editor, to save use CTRL+X.

After saving, always apply the changes using:

sudo netplan apply

To identify the machine more easily, modify the host files with these commands:

sudo vim /etc/hostname

Change template to master.

Then:

sudo vim /etc/hosts

Add the following lines:

127.0.0.1 localhost
192.168.0.1 master

192.168.0.22 cluster01

SSH Setup

This step is important to connect VMs with your host machine:

  1. In VirtualBox (master machine), go to: Settings > Network > Port Forwarding > Add.
  2. Set the following rule:

image

  1. Install the SSH service:
sudo apt install openssh-server
  1. Check if it's active:
sudo systemctl status ssh

If not, enable it:

sudo systemctl enable ssh
  1. On your WINDOWS/MAC terminal, run the command to generate a key:
ssh-keygen

Copy the public key to the master host with the command:

cd .ssh
scp -P 2222 id_ed25519.pub vboxuser@127.0.0.1

(Remember, the id_...pub and vboxuser will vary based on the username and key name generated.)

  1. Finally, on the master machine, run:
cat id_ed25519.pub >> .ssh/authorized_keys
rm id_ed25519.pub

Now, your SSH connection is ready:

ssh -p 2222 vboxuser@127.0.0.1

Execute this command from your WINDOWS/MAC terminal.

DHCP and DNS Configuration

Execute the following commands:

sudo apt install dnsmasq -y

Edit the configuration file:

sudo vim /etc/dnsmasq.conf

Add:

port=53
bogus-priv
strict-order
interface=enp0s8
listen-address=::1,127.0.0.1,192.168.0.1
bind-interfaces
log-queries
log-dhcp
dhcp-range=192.168.0.22,192.168.0.28,255.255.255.0,12h
dhcp-option=option:dns-server,192.168.0.1
dhcp-option=3

Link the DNS resolver:

sudo ln -fs /run/systemd/resolve/resolv.conf /etc/resolv.conf

Update the network configuration:

sudo vim /etc/netplan/50-cloud-init.yaml

network:
  ethernets:
    enp0s3:
      dhcp4: true
    enp0s8:
      dhcp4: false
      addresses: [192.168.0.1/24]
      nameservers:
        addresses: [192.168.0.1]
  version: 2

Apply changes:

sudo netplan apply

Update DNSMASQ defaults:

sudo vim /etc/default/dnsmasq

IGNORE_RESOLVCONF=yes
DNSMASQ_EXCEPT="lo"

Restart services:

sudo systemctl restart dnsmasq systemd-resolved
sudo systemctl status dnsmasq

Verify DNS:

host cluster01

image

Distributed File System

Install NFS:

sudo apt install nfs-kernel-server
sudo mkdir -p /mnt/shared

Mount the NFS share:

sudo mount -t nfs 192.168.0.1:/shared/ /mnt/shared
df -h | grep /mnt/shared

Make it persistent:

sudo vim /etc/fstab

Add:

192.168.0.1:/shared  /mnt/shared  nfs  defaults  0  0

Test with:

sudo mount -a

Verify with:

df -h | grep /mnt/shared

Reboot:

sudo reboot

Nodes (node01, node02, ...)

Repeat the cloning and network configuration steps for each node.

Once started, edit the network file:

sudo vim /etc/netplan/50-cloud-init.yaml

network:
  ethernets:
    enp0s3:
      dhcp4: true
      dhcp4-overrides:
        use-dns: no
    enp0s8:
     dhcp4: true
     dhcp-identifier: mac
     nameservers:
          addresses: [192.168.0.1]
  version: 2

Apply changes:

sudo netplan apply

Update DNS:

sudo ln -fs /run/systemd/resolve/resolv.conf /etc/resolv.conf

Hostname Resolution

Update the master’s /etc/hosts file:

192.168.0.23   cluster01

Test by pinging:

ping cluster01

Finally, from the master machine, connect:

ssh vboxuser@cluster01
# or
ssh vboxuser@192.168.0.23

Repeat the same steps to set up the distributed file system on each

node.

Now, your 3-machine cluster is ready to use!