Linux | Cloud | DevOps | Scripting

Breaking

Monday 24 June 2019

Amazon Elastic File System (EFS)


Lots of applications require shared file storage that can be accessed by multiple computers at the same time. Building our own file system storage takes time and can be very expensive. We need to perform some backup operations also. So that our data could be secure. 

Amazon Elastic File System (EFS)
Fig: Amazon Elastic File System
Amazon Elastic File System (EFS) is a better option. EFS is a shared file system that we can use with Amazon EC2. With Amazon EFS applications running on multiple EC2 instances can access our file system at the same time. This service uses the industry-standard NFSv4 file access protocol. 

Advantages of Amazon Elastic File System:

  1. Fully managed service
  2. Consistent and scalable performance
  3. Low cost
  4. High Availability and high durability
  5. Secure
  6. Scale up and scale down automatically
  7. Seamless integration

Steps we need to follow:

  1. Enable DNS resolutions and DNS hostname
  2. Create EFS volume 
  3. Install two instances
  4. Install EFS Client s/w in the first instance
  5. Mount and Verify EFS volume
  6. Create some files and verify from the first instance
  7. Install EFS Client s/w in the second instance
  8. Mount and Verify EFS volume
  9. Verify all the files created by the first instance 

Step 1: Enable DNS resolutions and DNS hostname:

AWS ➔ Services ➔ VPC ➔ Select your VPC ➔ Actions ➔ Edit DNS resolution: [*] enable this service ➔ Save ➔ Close.

Again select your VPC ➔ Actions ➔ Edit DNS hostnames: [*] enable this service ➔ Save ➔ Close.

Step 2: Create and attach an EFS volume with the first instance

AWS ➔ Services ➔ EFS ➔ Create file system ➔ VPC: webshack-vpc ➔ Create mount targets ➔ us-east-1a ➔ Next step ➔ Tags: Name: custom_efs_share ➔ [*] Enable Lifecycle Management ➔ Choose throughput mode: Bursting ➔ Choose performance model General purpose ➔ Enable encryption if you want  ➔Next step ➔ Review ➔ Create File System.

It's in creating state right now and takes some time to be in the available state.

Step 3: Install two instances:

I am creating tow Linux instances in my created VPC, named 'webshack-vpc':

AWS ➔ Services ➔ EC2 ➔ Instances ➔ Launch Instance ➔ [*] Free Tier only ➔ Select 'Amazon Linux' AMI ➔ Instance Type: t2.micro ➔ Next ➔ Number of instances: 2 ➔ Network: select own created VPC, named 'webshack-vpc' ➔ Subnet: select your public subnet ➔ Auto-assign Public IP: (already enabled as I have enabled it at the time of creation of public subnet) ➔ Next ➔ Next: tags ➔ Name: linux-server ➔ Next: SG ➔ [*] Create a new Security Group or select an existing one which enables port number 22 ➔ Review and Launch ➔ Launch ➔ Create a new key-pair OR select any existing key pair ➔ Launch Instances ➔ View Instances.

Now, rename the second instance, because name of both of the instances is same. For this, just click on pencil icon and provide a name like 'linux-server2'. So, now, we have two instances 'linux-server' and 'linux-server2'.

Rename Instance
Fig: Rename Instance

Step 4: Install EFS Client s/w in the first instance:

AWS ➔ Services ➔ EFS ➔ select EFS volume ➔ click on 'Amazon EC2 mount instructions (from local VPC)' ➔ here, we can see all commands which we can use to install client software and to mount EFS volume.

EFS Client Software
Fig: EFS Client Software
Login to the instance ➔ and run command:

Install EFS-client software:
$ sudo yum install -y amazon-efs-utils

Step 5: Mount and Verify EFS volume:

My current location is the home directory of ec2-user which is '/home/ec2-user', here I am going to create a mount point:

$ mkdir efs-share

Mount EFS volume:

$ sudo mount -t efs fs-d4337b37:/ efs-share/

Verify mount point:

$ df -h

Disk space available on the file system
Fig: disk space available on the file system
It's showing that EFS volume has been mounted on '/home/ec2-user/efs-share'

Step 6: Create some files and verify from first instance, named 'linux-server':

Navigate to efs-share directory:

$ cd /home/ec2-user/efs-share/

$ sudo touch file{1..5}.txt

$ ls
-rw-r--r-- 1 root root 0 Jun 24 09:28 file1.txt
rw-r--r-- 1 root root 0 Jun 24 09:28 file2.txt
-rw-r--r-- 1 root root 0 Jun 24 09:28 file3.txt
-rw-r--r-- 1 root root 0 Jun 24 09:28 file4.txt
-rw-r--r-- 1 root root 0 Jun 24 09:28 file5.txt

Step 7: Install EFS Client s/w in the second instance

Login to the second instance named 'linux-server2' ➔ and run command:

Install EFS-client software:
$ sudo yum install -y amazon-efs-utils

Step 8: Mount and Verify EFS volume:

Create mount point:
$ mkdir efs-share-2

Mount EFS volume:
$ sudo mount -t efs fs-d4337b37:/ efs-share-2/

Verify mount point:
$ df –h

As a result, this will show all the files which we created from first instance. Also, if we create any file from here, that will show in first instance which is 'linux-server'.


Ques: How to attach EFS volume with another subnet?

Ans. Navigate to EFS volume: 
AWS ➔ Services ➔ EFS ➔ Select your file system ➔ Manage File system access ➔ click on + icon in the starting of your subnet, on which you want to attach the EFS volume ➔ Save.


Attach Amazon Elastic File System to another AZ
Fig: Attach EFS to another AZ

Cleanup Steps:

  1. Unmount EFS filesystem from both EC2 instances
  2. Terminate both EC2 instances
  3. Delete EFS volume




No comments:

Post a Comment

Pages