Open main menu

CDOT Wiki β

Changes

OPS345 Lab 3

936 bytes added, 02:31, 2 January 2022
Storage for the web server
An EBS volume looks like any other block storage device (e.g. a harddrive partition) to an operating system in an AWS instance. But of course it's not a partition or a harddrive or an LVM logical volume, its actual implementation details are internal to AWS and of no concern to us, the users. The concept should be familiar to you because it's so similar to how in OPS245 you've created a virtual harddrive in VMware and attached it to an existing VM.
 
== Create and attach EBS device ==
* First go to Volumes under Elastic Block Store. Notice that some volumes are already there. These are the virtual harddrives which your existing VMs have been installed on, where they store all the operating system files, the contents of the home directories, and anything else "on the harddrive".
[[File:AWSAttachVolume.png|800px|border|center]]
* The name of the device doesn't really matter. Mine turned out to be /dev/sdf.
Note that you don't need to shut down your VM nor even reboot it. The action you performed is the equivalent of plugging in a hot-pluggable storage device into a Linux desktop or laptop.
[[File:AWSVolumeAttached.png|800px|border|center]]
At this point you have a new block storage device of 1GB plugged into your box, but it is not currenty being used. Hopefully you paid attention in the OPS245 LVM labs because this is the same stuff, just in the cloud instead of a local hypervisor.
 
== Use your new EBS device as a LV ==
 
It should not be difficult to imagine that your web server might run out of storage space if it only has 1GB available. How much work would it be to recreate the entire machine, reconfigure it, move all the files over, and do that without too much downtime?
 
In order to avoid all those problems you use LVM. The storage for your web server will be on a Logical Volume, on a separate EBS device than the operating system. If you run out of space: all you have to do is add another EBS device, and extend the logical volume to use the space on that new device as well. Exactly like you did in OPS245.
 
* Create a volume group '''vg_www''', and add /dev/xvdf to it as a physical volume.
* Then create a logical volume '''lv_www''' and allocate all the space from /dev/xvdf to lv_www.
* Double-check with blkid and ls that your new logical volume has been created.
* Format that logical volume as ext4.
[[File:AWSCreateLV.png|800px|border|center]]
* Mount your new filesystem on /var/www. You should not get any errors or surprises
* before starting the service, we'll configure the server to store all webpages on a separate volume: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html
** attach to www (note reboot is not required)
* ls /dev/xvd* -l # note /dev/xvdf
* vgcreate vg_www /dev/xvdf
* lvcreate -n lv_www -l 100%FREE vg_www
* blkid
* ls /dev/mapper/vg_www-lv_www
* mkfs.ext4 -L www /dev/mapper/vg_www-lv_www
* vi /etc/fstab
** /dev/mapper/vg_www-lv_www /var/www ext4 defaults 0 0