본문 바로가기
[AWS]/Highly Available, Scalable, AWS Stack

9. Prepare for recovery: Configure data volume

by SAMSUNG CLOUD-OKY 2022. 1. 18.
반응형

 

# SSH into your server, after you have attached the data volume to the instance

# Check if data volume exists, device with name xvdf should exist:
lsblk

# Install file system on data volume
sudo mkfs -t ext4 /dev/xvdf

# Create mount point:
sudo mkdir /data

# Mount the volume to the mount point:
sudo mount /dev/xvdf /data

# Add this line to /etc/fstab, so volume is mounted after reboot:
sudo vi /etc/fstab

/dev/xvdf   /data       ext4    defaults,nofail 0       2  #Copy this whole line and paste to bottom of fstab file, and save

# Test for mount errors:
sudo mount -a

# Check if volume is mounted using df command, /dev/xvdf should show up as mounted on /data:
df -h

# Reboot machine so we can see volume is mounted after reboot:
sudo reboot

# After reboot, SSH again and use df again to verify volume is mounted after reboot as well:
df -h

 

 

In this video take a look at how to configure the data volume.

So what we have to do is we'll have to create the volume then we have to attach this to the server.

The volume is a raw block storage device.

So we will have to use make FS and install a file system on it ok then we will mount this volume to a mount point

which will be slash data slash data is a folder and when we read and write from this folder we will be.

Reading and writing from the EBS Volume.

Once we have mounted it to the mount point ok and then we will also edit the fstab configuration

file.

And this is required so that the volume is mounted even after a reboot or a restart.

OK so there are there are five steps to be completed to configure the data volume.

Let's see how to do these.

All right so let's set up the data volume.

So here the management console right and this server has a single volume which is the root volume.

let's create the data volume and let's start with a size of one.

OK that is the minimum size.

And also lets make sure that the volume comes up in the same zone as the server so the server is in

zone 1 b.

So this is an important selection.

The volume can only be attached to a server in the same zone so.

So here is our data volume.

And now you can see we have two volumes the first one.

This one.

The second one rather is the root volume and then the one on the top is the data volume that we have just created

and the state is available which means it is not yet attached to the server.

So lets change that from actions.

Say attach volume select the instance and note the device name slash dev slash sdf.

SDF this is a device name we will use when we run our make fs command from the operating system.

OK so here is how you attach the EBS volume to the EC2 instance.

Now let's S-sh into this server.

Right.

And I'm going to run a series of commands and I will look at my notes.

These are available with your material as well.

And the first command we run is to run ls block which means it shows us the block devices which

are which are attached to this EC2 instance right and you can see that there's xvdf.

Right this is the data volume that we have attached and the name changes slightly so.

So on the management console you saw it was called slash dev slash sdf but now it's called slash xvdf.

So that's normal.

Don't worry about that.

And above that you'll find xvda this is the root volume.

So the command now shows that we have two block devices attached to this EC2 instance.

after that we run the make.

fs command like this this installs a file system on the data volume.

Next we will create a mount point.

This is just a folder is just a folder.

But when we mount this data volume to this mount point right what we're saying is when you read and

write from the slash data folder we will actually be reading and writing from the data volume.

So.

So later we'll have to configure my sql to use slash data as the directory data directory for my sql.

OK so now we have mounted the EBS.

volume to the mount point.

But we also need to edit fstab this configuration change is required to ensure that the to ensure that

the volume mounts even after a reboot right so here what we need to do is add a line ok so we can

add a line at the at the bottom of this page and you can copy the whole line here.

You can copy the whole line from here.

And and you can paste it here.

OK.

And this is to ensure that the volume is mounted after a reboot as well.

OK once you've done that you can test ok you can test if there are any problems.

And this is quite useful.

this command mount -a is quite useful in case you edit the fstab incorrectly you add

some extra characters or maybe there is some syntax problem.

So this command is quite useful and there should be no error right when you run this mount -a

command.

There should be no error.

OK.

Also test the configuration by using the df command.

ok df -h and this command will show you the volume has been mounted on slash data.

You can see here the last line slash dev slash xvdf.

Mounted on slash data which means our configuration looks fine.

Looks fine.

OK.

You should also reboot.

You can reboot the server like this.

All right.

And once the server comes back S-sh into the server once again and run this df command once again and verify

that you see the last line.

this means our fstab edit is also working fine.

ok.

So let's look at what we've done.

Essentially we have created a 1 G-B volume.

Right so basically this was one G-B volume and make sure that you create it in the same zone.

This way you can attach the volume to the server right.

Next we did an ssh into the server we ran the mkfs command and this is to install a file system on the raw

block storage device.

right then we created a mount point called slash data and then we mounted the EBS volume to this mount

point which means we can read and write right that we can read and write from this folder.

And that would mean that we are reading and writing from the new EBS volume.

OK.

Finally we edited the stab configuration file.

This is to ensure that when the server reboots the volume is mounted once again.

OK.

So so good luck with this with this task and I'll see you in the next set of videos in this module.

 

 

 

반응형

댓글