Magento Elastic Files System (EFS) on AWS

CHOOSING YOUR FILE SHARE TECHNOLOGY

Choosing the right file share technology for your Magento store is crucial. With a variety of options for network file shares, it can be difficult deciding which one is best for your stack. Variables related to budget, performance and expertise are common discussion points at a round table. I have experience a magnitude of file share technologies on the AWS Cloud. Today I am focusing on Amazon’s EFS, s3fs-fuse and GlusterFS. While all three have their advantages and disadvantages, I prefer to lean on Amazon’s EFS technology due to its simplicity and performance capabilities of Magento’s architecture.

Amazon’s Elastic File System is an easy-to-use network file share utilizing the NFSv4.0 and v4.1 protocols. It was designed with goals of being elastic and performance oriented. It’s main selling points are simplicity, security and elasticity with the ability to store exabytes of data. The best part is how cheaply this can be accomplished. When you create a file system in Amazon’s EFS, there are a few simple configurable options. Access controls, availability zones, performance modes and encryption options are a few of the major decisions that will be addressed in this post. Additional information can be found at Amazon’s EFS Overview page.

WHAT FILES SHOULD I BE SHARING IN MAGENTO

Sharing the entire Magento file system across web nodes is less than ideal. While this might simplify management and synchronization across your web environments, there are heavy performance implications for a high traffic site. When traffic increases, the performance of PHP degrades, which can cause an EFS to bog down. This has been done in a variety of architectural scenarios and I have never been a fan of it. Sharing just a few directories is the optimal way to accomplish a robust environment. When it comes to supporting a large clustered Magento environment, it’s important to share the “var/” and “media/” directories.

HOW IT’S DONE

Begin by creating an Elastic File System. There are a lot of available options, but only a few that are a necessity. When creating an EFS, use any allowed Availability Zones. Configure a personal internal Security Group built around internal EFS routing while focusing on port “:2049”. Then, make sure that at least a “Name” tag is set. Choosing a performance mode is next. “Max I/O” is going to be the most stable choice due to the possibility of clustering multiple web nodes. The last thing that is advisable is to encrypt data at rest. This is easily done via the AWS KMS key system.

CREATING YOUR EFS

Create the EFS within AWS – Configure File System Access

  • Choose your VPC
  • Choose the desired availability zones (defaults to all)
  • Choose a subnet
  • Assign any required elastic IP addresses
  • Add additional security groups outside of your internal routing

Configure Optional Settings

  • Add Tags (Minimum of “Name”)
  • Choose your performance mode (Max I/O)
  • Enable encryption at rest (KMS key)

Review and Create

  • Review your settings chosen
  • Hit “Create File System”

ADDING EFS TO YOUR WEB NODES

Create your EFS file structure

Before mounting the “media/” and “var/” directories, create a file structure that allows for easy management and visibility into what is being shared. I start by creating the mount points to manage the EFS.

  • Create a management mount point outside of your web server file structure.
~# sudo mkdir -p /mnt/elasticfs
  • Mount your EFS root to this new mount point.
~# sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-jkl123jo1.efs.us-east-1.amazonaws.com:/ /mnt/elasticfs
  • Add an additional file structure to manage your site’s files. (I like to use the domain)
~# sudo mkdir -p /mnt/elasticfs/example.com
  • Create a public and private directory
    • The creation of a public directory is done with the intention to keep public files shared between the web nodes. The creation of a private directory is to store items such as configuration files that don’t need to shared with any other services.
~# sudo mkdir -p /mnt/elasticfs/example.com/{public,private}
~# sudo mkdir -p /mnt/elasticfs/example.com/public/{media,var}
  • Unmount your management mount point.
~# sudo umount /mnt/elasticfs
  • Create your shared folder structure for Magento.
~# sudo mkdir -p /var/www/vhosts/example.com/shared/{media,var}

Create your fstab file

  • Add three separate mount points for each shared directory within the Magento shared file structure. This allows for ease of management and maintenance.
fs-jkl123jo1.efs.us-east-1.amazonaws.com:/example.com/public/media	/var/www/vhosts/example.com/shared/media nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 0 0
fs-jkl123jo1.efs.us-east-1.amazonaws.com:/example.com/public/var	/var/www/vhosts/example.com/shared/var nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 0 0
  • Mount your new shared file system

Create symlinks to your new mounted filesystem

  • Keep the shared file structure outside of the root installation of Magento. This can be accomplished by creating symlinks within the Magento standard file structure that will point back to the mounted file system.
~# ln -s /var/www/vhosts/example.com/shared/{media,var} /var/www/vhosts/example.com/magento-root/

WRAPPING IT ALL UP

There are many ways to share a network filesystem. A lot of administrators have their own preferences as to how one should accomplish this. With the above information, management of high transactional e-commerce sites management, stability and scalability is achieved. Hopefully this helps you in setting up an Elastic File System on your AWS Magento store. Please feel free to reach out to me on any of my media platforms for an open discussion.

Jarett Ehas Written by:

AWS Certified Solutions Architect. Linux Devops Engineer.