AWS Series 3 Use EBS

Source: Internet
Author: User

Amazon Elastic Block Store (EBS) can be used as persistent data block-level storage for EC2 instances. It features high availability and durability, with availability up to 99.999%. It takes only a few minutes to extend a new storage block to an existing EC2 instance, saving time and effort. Each EBS block is placed in a specific zone, and a copy is automatically maintained to protect data security at any time.

Amazon EBS provides three types of hard disks: SSD (solid state drive), provisioned iops SSD (dedicated iops solid state drive), and magnetic (General hard drive ). SSD is the default hard disk format of the EC instance (brutal! Amazon is really rich. Since I have changed my own SSD, I cannot do without SSD .) Provisioned iops SSD is more ferocious and features high consistency and ultra-low latency performance. It is specially designed for I/O-intensive operations, such as databases. Iops is called input/output operations per second, which is the number of read/write (I/O) operations per second. iops is used to measure the performance of random access. Provisioned iops SSD can reach 30 iops per GB. Magnetic volumes is commonly known as the magnetic volume, which is the cheapest, of course, the worst performance. If your application is not I/O-intensive and does not frequently access data, it is more cost-effective to use this type.

Another feature of EBS is to easily create snapshots and save them to Amazon S3. EBS snapshots are incrementally stored. For example, if you have a GB hard disk, the first snapshot uses GB capacity, and the second snapshot only changes 5 GB of data, you only need to spend GB of storage fee in total. Of course, you don't have to worry about data loss caused by deleting one of the snapshots, because when you delete a snapshot, the system will only delete the data that is not used by other snapshots, so it will not affect other snapshots.

Now, the two main tasks in this article are two. The first task is to attach a new EBS volume to an EC instance and add it to the file system of the current EC instance. The second task is to create a snapshot for the EC instance.

First of all, you are ready to create a new EC2 instance. How to create an article has been described in detail in the previous article. If you do not have an AWS account, you can use the free lab provided by qwiklabs for this exercise. The address is https://run.qwiklabs.com. To be honest, qwiklabs is really a good thing. If I use my account to practice, it will take a lot of money. Qwiklabs has several free labs. It is an industry conscience to use all AWS resources without any fees.

This should be the case after EC2 is created.

Then SSH is used remotely.

1
$: ssh [email protected] -i ~/Downloads/key.pem

First, check the current disk status.

12345
[[email protected] ~]$ df -hFilesystem      Size  Used Avail Use% Mounted on/dev/xvda1      7.8G  1.1G  6.6G  14% /devtmpfs        486M   56K  486M   1% /devtmpfs           499M     0  499M   0% /dev/shm

It can be seen that the total size of the current disk is about 8 GB and there are three file systems.

Next, create a hard disk.

ClickVolumesClick to go to the disk control panel.

The hard disk shown here is the hard disk used by the current EC2 instance.

ClickCreate VolumesTo add a new hard disk.

The hard disk type is the one I mentioned above. The higher the iops, the more expensive the hard disk will be. The selection of zones must be consistent with the EC2 instance to be used currently, otherwise, the hard disk cannot be attached across zones. If the snapshot ID is provided, the new hard disk will have the data of the snapshot.

Shows how to create a hard disk.

Currently, it is available. If you attach it to an EC2 instance, it becomes in-use.

ClickActionClick and selectAttach VolumeCommand to attach the hard disk to an EC2 instance.

In this interface, select the Instance name and the mapped device address, and then attach.

The hard disk status has changed.

Then return to the terminal to view the disk information.

12345
[[email protected] ~]$ df -hFilesystem      Size  Used Avail Use% Mounted on/dev/xvda1      7.8G  1.1G  6.6G  14% /devtmpfs        486M   60K  486M   1% /devtmpfs           499M     0  499M   0% /dev/shm

The newly added 20 GB hard drive is the same as the previous one. What's going on? This is because although you have added a hard disk to the machine, you have not formatted and created a file system, and added the file system to the file system tree of EC2.

Let's use another command to view the storage status.

12345
[[email protected] ~]$ lsblkNAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINTxvda    202:0    0   8G  0 disk└─xvda1 202:1    0   8G  0 part /xvdf    202:80   0  20G  0 disk

Here we can see that there is a 20 GB large hard disk xvdf, but there is no mountpoint. You can think of this mountpoint as the root address of this hard disk on the EC2 instance.

Careful readers may find that the address we enter when attaching a hard disk is/dev/sdfWhy is it displayed in the command linexvdfSo? This is because the naughty operating system kernel has been changed, and the modified addresses of different Linux distributions will be different.

Run the file command to check whether a file system has been created for this hard disk.

12
[[email protected] ~]$ sudo file -s /dev/xvdf/dev/xvdf: data

If the output is data, the file system has not been created for this hard disk.

Run the following command to create a file system for xvdf.

1
[[email protected] ~]$ sudo mkfs -t ext4 /dev/xvdf

Then run the file command to confirm.

12
[[email protected] ~]$ sudo file -s /dev/xvdf/dev/xvdf: Linux rev 1.0 ext4 filesystem data, UUID=1e14ec91-156a-4eb5-8846-cb5f2fa51b64 (extents) (large files) (huge files)

Bash

You can see that the file system in ext4 format has been created for this hard disk.

Next, add the file system to the file system tree of the current instance. Use the mount command here.

12
[[email protected] ~]$ sudo mkdir /boot2[[email protected] ~]$ sudo mount /dev/xvdf /boot2

Now let's take a look at the storage of EC2 instances.

12345
[[email protected] ~]$ lsblkNAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINTxvda    202:0    0   8G  0 disk└─xvda1 202:1    0   8G  0 part /xvdf    202:80   0  20G  0 disk /boot2

You can create files and folders in the/boot2 directory at will.

This is not the case. We need to add the mountpoint to the system file. Otherwise, the hard disk will not be found after the system is restarted. Edit/etc/fstabFile, add the following lines to it.

1
/dev/xvdf       /data   ext4    defaults,nofail        0       2

In this way, you are not afraid to lose the mountpoint during restart. After adding the fstab file, you can try to see if the fstab file is running properly.

1
[[email protected] ~]$ sudo mount -a

If there is no error, everything will be fine. If there is an error and you restart the computer, you will be waiting to cry.

This is the first task. The second task is to create a snapshot for an existing hard disk, which is very simple. BackVolumesControl Panel, selectActionInCreate SnapshotButton.

After a while, snapshot will be created successfully.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.