ππΎ DevOps 7.6: Mastering EBS (Elastic Block Storage) ππ
"Unlock the Power of AWS EBS! Learn to Optimize Elastic Block Storage for Scalability and Reliability. Dive Deep into Storage Management with DevOps"
Introduction:
Elastic Block Storage (EBS) is a scalable and high-performance block storage service on AWS, offering reliable and flexible storage volumes for EC2 instances. With EBS, you can easily attach and detach volumes to EC2 instances, providing durable and low-latency storage solutions for various applications and workloads. Dive into the world of EBS to harness the full potential of AWS storage capabilities.
EBS Types ?
Amazon EBS (Elastic Block Store) offers different types of volumes to cater to diverse performance and cost requirements. Here are the main types:
General Purpose (gp2):
Suitable for a broad range of workloads.
Balanced performance of 3 IOPS per GB with up to 16,000 IOPS and a throughput of 250 MiB/s.
Cost-effective choice for various applications.
Provisioned IOPS (io1):
Designed for I/O-intensive applications such as large relational or NoSQL databases.
Allows provision of a specific amount of IOPS (Input/Output Operations Per Second) per volume.
Suitable for applications that require predictable and high-performance storage.
Throughput Optimized (st1):
Ideal for frequently accessed, large datasets.
Optimized for throughput rather than IOPS.
Cost-effective for big data, data warehousing, and log processing.
Cold HDD (sc1):
Lowest cost per gigabyte EBS volume.
Suited for less frequently accessed workloads with large amounts of cold data.
Ideal for scenarios where the lowest storage cost is a priority.
Magnetic (standard):
Legacy storage type.
Lowest cost per gigabyte among EBS volume types.
Suitable for workloads where data access is infrequent.
Choosing the right EBS type depends on your application's specific performance and cost requirements.
Lets Get Started:
For this blog we have to create an Centos EC2 instance with below provisioning details -
Steps are as follow's:
You can follow the same steps for launching an instance.
https://saswatblogs.hashnode.dev/devops-72-getting-started-with-ec2ssh into your intsance (refer to the above link).
#!/bin/bash yum install httpd wget unzip -y systemctl start httpd systemctl enable httpd cd /tmp wget https://www.tooplate.com/zip-templates/2119_gymso_fitness.zip unzip -o 2119_gymso_fitness.zip cp -r 2119_gymso_fitness/* /var/www/html/ systemctl restart httpd
Enter the above details in the shell.
Now let's get back to the storage tab present in the instance. Go to the volume section and name the volume.
So, we hosted an web service, which has images. So our requirement is to store that image in separate volume. Click on "Create Volume".
You can fill the above details but ensure that the instance and volume should be in the same availability zone. And Create the Volume.
Now select the volume. And Click on Actions and Attach the volume as shown.
Select the instance and Click "Attach".
Now let's go to shell and type
fdisk -l
- It shows information about the available disks on the system.-
You can see /dev/xvdf of 5gb we created has been attached.
NOTE: The
df -h
command is used to display information about disk space usage on the system. Lets create a partion. You can follow the below screenshot for it.
-
Now if you do
fdisk -l
, you can see the partition. -
So next part is formatting it. Linux basically provides multiple utility for formatting.
-
So with the above we can see the partitioning is formatted with extension4.
Using the commandmkfs.ext4
- This command is used to create an ext4 file system on a Linux system. Formatting is done. Now let's mount it.
Below you can see all the images have been moved /tmp/img-backups. First we will do temporary mounts.
You can see below the disk is mounted and you can see the space used.
To unmount you can use -
The above was temporary mount for permanent mount we have to do the following.
Do
vi /etc/fstab
-/etc/fstab
which is a system configuration file on Linux systems that controls how disk partitions or logical volumes are mounted and used. Each line in the file represents a different file system or partition.-
Add the last line as shown. And do
mount -a
to apply changes. Follow the below image to permanently mount. -
You can verify the same by doing
ls /var/www/html/images
and check the website if it is images is visible.
EBS Snapshots:
Steps:
First let's umount the above using -
umount /var/www/html/images
.
And then detach the volume from the volumes dashboard using detach volume option in the actions. And you should also delete the unused volume to avoid charges.Same way create another volume named db01 as discussed above. And attach it to the ec2 instance.
Go to your shell and format it as shown below
-
Now we are going to mount it -
Match the below contents for /etc/fstab file -
# # /etc/fstab # Created by anaconda on Mon Dec 19 11:24:05 2022 # # Accessible filesystems, by reference, are maintained under '/dev/disk/'. # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info. # # After editing this file, run 'systemctl daemon-reload' to update systemd # units generated from this file. # UUID=d5ae404e-d570-441c-bd68-fb544b5ebbb9 / xfs defaults 0 0 /dev/xvdf1 /var/lib/mysql ext4 defaults 0 0
Check it is mounted -
Now we are going to install mysql service -
yum install mariadb-server -y
and start the service as follows.-
Here below you can see the db data.
-
What will happen if the data is deleted ? That is where snapshot comes in.
1) First you have to unmount the partition.
2) Then detach volume which is corrupted.
3) Create new volume from the snapshot.
4) Attach the volume created from snapshot.
5) Mount it back. So first select the volume and in actions, select on "Create Snapshot". And fill the details and submit.
-
Now lets delete the data as shown below -
-
Unmount it -
-
Now detach that particular volume for volume dashboard in aws.
So now you can go to snapshots and select the snapshot and in actions you can select "Create Volume".
Go through the selections and create volume.
And attach the volume to the instance. Now we can see we have got all the data.
-
So this is how you recover your data
Now terminate all the instance and delete all the EBS to avoid charges.
ππ‘ConclusionπΎπ:
In this journey through Elastic Block Storage (EBS), we delved into its nuances, understanding the types of EBS volumes, how to attach and detach them, and the critical concept of snapshots. Snapshots provide data redundancy and recovery capabilities, offering a safeguard for your valuable data.
πΈ Snapshot Safeguard: We learned about creating snapshots, which capture the state of your EBS volumes at a specific point. These snapshots act as backups, enabling you to restore or clone volumes, ensuring the resilience and durability of your data.
π Next Stop: Elastic Load Balancing: Stay tuned for the next installment where we explore the dynamic world of Elastic Load Balancing (ELB), optimizing the distribution of incoming application traffic across multiple targets. Elevate your AWS mastery with our upcoming insights into ELB.