Thursday 13 March 2014

Setting up a Ubuntu Server

Firstly welcome to my blog I am going to be posting up tutorials and useful information regarding Linux related stuff.

When setting up a server the first thing your going to want to consider is how to layout and manage your storage, I will kick off this series of tips with notes on Ubuntu Server installation and will provide a few pointers on advanced stuff such as RAID and LVM

With all mission critical machines you are going to need some form of backup in place although RAID provides redunancy it is not a backup! so please do not just rely on RAID for backups. It is good practice with all mission critical systems to have some form of backup strategy in place. Be-live me when the shit hits the fan and the boss is screaming at you for he's companies precious data  you will thank the gods that you have implemented a sound backup / disaster recovery solution

I cover backing up data at a later date and methods of backing up.

As you can see from the diagram below I will be initially using a 20 Gig Hard Disk, 
But Wait a minute Ally this is a server right why is the disk size so low? 

Good question the reason the disk space is low is because I am working virtually to practice the process of configuring and working with Partitions and advanced features so I do not need massive amounts of hard disk space. 

So As you can see  the name of the Hard Disk shown in (fig A) is SDA this is Linux's naming convention for Drives

First Hard Disk SDA, Second Hard Disk SDB, and so on 

If you are making the transition from Windows then you will be more at home with the windows drive naming convention as shown below

Windows First Hard Disk C:  Windows Second Hard Disk D:


PLEASE BEAR IN MIND THIS IS INITIAL THEORY FOR RAID AND LVM WHAT I AM TRYING TO DO IS TO GET YOU TO UNDERSTAND THE CONCEPTS OF RAID AND LVM I WOULD NEVER DEPLOY A SERVER WITHOUT SOME FORM OF RAID ON THE / partition

Figure A shows the drive layout if I wanted to install Ubuntu with just one hard disk and no bells and whistles i.e no RAID no LVM

(fig A)

 

So I have a massive 20 Gigs of space :) the first thing as shown there are three partitions on the drive SDA1, SDA2, SDA3

You will only need to create two as the extended is automatically created 

Ok so that is a single disk based installation "But Ally I want some excitement in my life talk to me about RAID!" 

What the hell is RAID?

A Good explanation on RAID and the levels can be found here

http://www.thegeekstuff.com/2010/08/raid-levels-tutorial/

For this Guide / Tips I am working with RAID-1 ( Mirroring)


(fig B)
Ok As you can see from the above diagram I have added four hard disks to the Computer and I will walk you through the process of Setting up Software Raid-1 during the Ubuntu install process.

Again I am working with small capacity hard disks through vmware which is a good way of practicing if you don't feel comfortable getting hands on with servers. Good thing about Vmware is you can quickly add hard disks to a configuration on the fly so practicing stuff like RAID is pretty easy.

Anyways back to the above picture!

So we have Four 10 Gig Hard Disks - /dev/sdb /dev/sdc /dev/sdd /dev/sde

We want to configure one partition on each drive to be used as RAID

 /dev/sdb1
 /dev/sdc1

/dev/sdd1
/dev/sde1

We then combine /dev/sdb1 + /dev/sdc1 to create a Raid 1 mirror called Md 0

We also combine /dev/sdd1 and /dev/sde1 to create a Raid 1 mirror called Md 1


So the goal is to create Two Raid 1 mirrors Md0 and Md1

 So how the hell do we set this up?

Partitioning
Follow the installation steps until you get to the Partition disks step, then:
  1. Select Manual as the partition method.
  2. Select the first hard drive, and agree to "Create a new empty partition table on this device?".
    Repeat this step for each drive you wish to be part of the RAID array.
  3. Select the "FREE SPACE" on the first drive then select "Create a new partition".
  4. Next, select the Size of the partition. This partition will be the swap partition, and a general rule for swap size is twice that of RAM. Enter the partition size, then choose Primary, then Beginning.
    A swap partition size of twice the available RAM capacity may not always be desirable, especially on systems with large amounts of RAM. Calculating the swap partition size for servers is highly dependent on how the system is going to be used.
  5. Select the "Use as:" line at the top. By default this is "Ext4 journaling file system", change that to "physical volume for RAID" then "Done setting up partition".
  6. For the / partition once again select "Free Space" on the first drive then "Create a new partition".
  7. Use the rest of the free space on the drive and choose Continue, then Primary.
  8. As with the swap partition, select the "Use as:" line at the top, changing it to "physical volume for RAID". Also select the "Bootable flag:" line to change the value to "on". Then choose "Done setting up partition".
  9. Repeat steps three through eight for the other disk and partitions.

    RAID Configuration

    With the partitions setup the arrays are ready to be configured:
    1. Back in the main "Partition Disks" page, select "Configure Software RAID" at the top.
    2. Select "yes" to write the changes to disk.
    3. Choose "Create MD device".
    4. For this example, select "RAID1", but if you are using a different setup choose the appropriate type (RAID0 RAID1 RAID5).
      In order to use RAID5 you need at least three drives. Using RAID0 or RAID1 only two drives are required.
    5. Enter the number of active devices "2", or the amount of hard drives you have, for the array. Then select "Continue".
    6. Next, enter the number of spare devices "0" by default, then choose "Continue".
    7. Choose which partitions to use. Generally they will be sda1, sdb1, sdc1, etc. The numbers will usually match and the different letters correspond to different hard drives.
      For the swap partition choose sda1 and sdb1. Select "Continue" to go to the next step.
    8. Repeat steps three through seven for the / partition choosing sda2 and sdb2.
    9. Once done select "Finish".
      

    Formatting

    There should now be a list of hard drives and RAID devices. The next step is to format and set the mount point for the RAID devices. Treat the RAID device as a local hard drive, format and mount accordingly.
    1. Select "#1" under the "RAID1 device #0" partition.
    2. Choose "Use as:". Then select "swap area", then "Done setting up partition".
    3. Next, select "#1" under the "RAID1 device #1" partition.
    4. Choose "Use as:". Then select "Ext4 journaling file system".
    5. Then select the "Mount point" and choose "/ - the root file system". Change any of the other options as appropriate, then select "Done setting up partition".
    6. Finally, select "Finish partitioning and write changes to disk".


      "Ally I want to setup RAID After I have installed Ubuntu!" 

      OK Don't panic what you need to do is to read this and learn about mdadm

      https://help.ubuntu.com/community/Installation/SoftwareRAID#Using_mdadm

      mdadm allows the creation of raid arrays from the command line and allows for greater control over management.

     
    Useful Commands and mdadm Commands
    
    

    CommandUse
    fdisk -ldisplays hard disks in system 
    ls -l /dev/sd*Shows drives and partitions
    apt -get install mdadmInstall Raid Management
    cat /proc/mdstatShow Raid Arrays