Mounting the Amazon Elastic File System (EFS) to multiple EC2 instances is a common task in AWS, and it is used to share a file system across multiple servers. This guide will walk you through the steps to achieve that.
Navigate to the EFS Console:
Sign in to the AWS Management Console.
Go to the EFS service under the Storage category.
Create a New File System:
Click on Create file system.
Choose the VPC where your EC2 instances reside.
Select your Availability Zones (AZs). It's recommended to enable EFS in all AZs that your EC2 instances are located in.
Select your preferred Throughput mode and Performance mode based on your workload requirements.
Set Up Security and Network:
Configure the Network access by creating or selecting existing Security Groups that allow access from your EC2 instances.
Optionally, set up Lifecycle management and Encryption.
Click on Create to finalize.
Step 2: Create two Amazon EC2 with same security groups
Step 3: Attach the EFS to EC2 Instances
Install EFS Utilities on EC2 Instances:
SSH into your EC2 instances.
Install the necessary utilities to mount EFS:
sudo yum install -y amazon-efs-utils # For Amazon Linux sudo apt-get install -y amazon-efs-utils # For Ubuntu/Debian
Create a Mount Directory:
On each EC2 instance, create a directory where you want to mount the EFS:
sudo mkdir efs
Mount the EFS File System:
You can mount the EFS using the file system ID (found in the EFS console):
sudo mount -t efs -o tls fs-XXXXXXXX:/ efs
Ensure that the EFS file system ID (
fs-XXXXXXXX
) is replaced with your actual EFS ID.
Verify the Mount:
Run
df -h
to check if the EFS is successfully mounted:df -h | grep efs
You should see your EFS file system listed.
Step 4: Testing and Using the Shared File System
Write Test Files:
On one EC2 instance, create a test file in the mounted directory:
cd efs touch file1 file2 file3
On another EC2 instance, check if the file exists:
cd efs ls
Monitor and Manage:
- You can monitor the performance of your EFS via AWS CloudWatch and adjust performance modes as needed.
Mounting an AWS EFS file system to multiple EC2 instances allows you to create a shared, scalable file system that is accessible across multiple servers. This is particularly useful for applications that require a centralized storage solution in a distributed environment.
I hope you find this blog interesting. If you are a DevOps Enthusiast like me, then subscribe to my newsletter to get notified about my latest blogs.