In this architecture, we will set up two EC2 instances in two different AZs, and make them share the same data from a single NFS server. We will be using Amazon Linux 2
Architecture Diagram
Create an IAM Role
Create an EC2 Role and attach the AmazonElasticFileSystemClientFullAccess policy
Create a Security Group
Create an SG, add inbound rules
Add NFS with TCP 2049, select public in the source
Add SSH with TCP 22, select public in the source
Launch the EFS Server
Move to the EFS dashboard to create one.
We will be using default VPC, choosing a name and selecting customize
For testing purposes, we disable automatic backups, choose to burst in performance settings and disable encryption and choose next
Remove all available zones not in use, just use 1a and 1b, then remove the default security group, and add the SG created earlier
Click next and click create
Wait till has fully provisioned, under EFS created, and check Network tab to make sure the Mount target state has finished creating
Launch EC2 instance
Launch an EC2 instance, name it Web_server_one, choose Amazon Linux 2
Select the subnet us-east-1a
Select SG created earlier
Attach the IAM role created earlier and click create
Launch another EC2 instance, name it Web_server_two and select subnet us-east-1b,
Follow the same steps to create the second instance
Configure NFS Server on Web server one
Go into Web_server_one and connect using EC2 instance connect
Run the following commands below:
sudo mkdir -p /efs/content
sudo yum -y install amazon-efs-utils
sudo nano /etc/fstab
nfs-server-id:/ /efs/content efs _netdev,tls,iam 0 0
sudo mount /efs/content df -k cd /efs/content
sudo touch testfile.txt
Configure NFS Server on Web server two and view the file created
sudo yum -y install amazon-efs-utils
sudo mkdir -p /efs/content
sudo nano /etc/fstab
nfs-server-id:/ /efs/content efs _netdev,tls,iam 0 0
sudo mount /efs/content ls -la
cd /efs/content
Check to see if you see testfile.txt is available