This content originally appeared on DEV Community and was authored by JJ Chen
đźš©issue: Web servers in different Availability Zones need to access the same file data.
Step 1. Create security groups for EFS
Create security groups for EFS → Allow web servers to access EFS
- Security Group:Acts as a virtual firewall, used to control inbound and outbound traffic for EC2 instances. Can be used within an existing VPC.
In the lab, choose VPC of
PetModelsWebServer
.Set the NFS type in the Inbound Rule of the Security Group of EFS
Choose the Security Group of
PetModelsWebServer
as source
Only resources belonging to the Web server Security Group are allowed to access EFS
- By selecting a security group as the incoming source, any EC2 instances linked to the security group you select will have NFS client access to the file system.
Step 2. Create an EFS
Create File System on the EFS security group
Set network access to allow mount Target
- Az-1 to EFS security groups
- Az-2 to EFS security groups
- Az-3 to EFS security groupsclick
Attach
button to copy mount command
Step 3. EC2 mount NFS
Ok! Now, all environments are ready.
You will mount a /data folder on EC2.
The following are the command for mounting a NFS in Linux
sudo -i
# download aws efs utils
sudo yum install -y Amazon-efs-utils
# create folder
mkdir data
# paste from "Attach" button
sudo mount -t efs -o tls fs-id:/ data
cd data
# write text in file
sudo bash -c “cat >> efs-1-setup.log”
# cat -> output "efs-1-setup.log"
efs-1 mounted in site A
cat efs-1-setup.log
Step 4. Repeat Step 3. for each EC2
After setting, you can read and write files from other EC2s.
All changes will be synchronized with EFS.
This content originally appeared on DEV Community and was authored by JJ Chen
JJ Chen | Sciencx (2024-07-24T16:44:04+00:00) AWS Cloud Quest: EFS mount on EC2. Retrieved from https://www.scien.cx/2024/07/24/aws-cloud-quest-efs-mount-on-ec2/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.