This guide will show you how to install AWS EFS using EFS-Helper on RHEL. Additionally, you will see how to use the AWS EC2 user data field to auto-configure your RHEL instance.
Table of Contents
Let’s get started!
You will need to modify the script below and replace fs-MY_EFS_ID with your EFS storage id. The script also assumes your security groups are correctly configured, allowing inbound traffic.
Lastly, Stunnel may be updated when you run this script. Therefore, the script may not work if you download a version that is no longer available. Visit Stunnel downloads to confirm the latest version and then update the script accordingly.
It would be best if you also modify the hostname to be more suitable for your environment.
The AWS EFS install script for RHEL
The script below will install AWS EFS on your RHEL instance:
#!/bin/bash
sudo hostnamectl set-hostname --static testwebserver.localdomain
cd /home/ec2-user/ || exit
sudo yum -y update
sudo yum -y install git
sudo git clone https://github.com/aws/efs-utils
sudo yum -y install rpm-build
cd /home/ec2-user/efs-utils/ || exit
sudo make rpm
sudo yum -y install build/amazon-efs-utils*rpm
sudo yum -y install gcc openssl-devel tcp_wrappers-devel
sudo curl -o stunnel-5.44.tar.gz https://www.stunnel.org/downloads/stunnel-5.44.tar.gz
sudo tar xvfz stunnel-5.44.tar.gz
cd stunnel-5.44 || exit
./configure
make
sudo make install
if [[ -f /bin/stunnel ]]; then
sudo mv /bin/stunnel /root
fi
sudo ln -s /usr/local/bin/stunnel /bin/stunnel
cd / || exit
sudo mkdir efs
sudo mount -t efs -o tls fs-MY_EFS_ID:/ efs
sudo echo $'Gofs-MY_EFS_ID /efs efs defaults,_netdev 0 0\E:x\n' | sudo vi /etc/fstab
Run the script via AWS EC2 user data
You can also run the script via AWS EC2 user data if you wish the instance to be auto-configured with your EFS mount. To do this, add this script in the user data field on the ‘configure instance details’ page when launching a new instance.
Example of the user data field under advanced details when configuring an AWS EC2 instance:
Frequently asked questions
Stunnel (“Secure Tunnel”) is a cross-platform proxy application designed for clients and servers. Additionally, Stunnel uses the OpenSSL library for cryptography.
AWS Amazon Elastic File System (EFS) automatically grows and shrinks as you add and remove files. With AWS EFS, there is no need for management or provisioning.
The AWS EFS (mount) helper helps you mount your EFS file systems. It includes the AWS EFS recommended options by default. Additionally, the mount helper has built-in logging for troubleshooting purposes.
You have the option of passing user data to an AWS EC2 instance when launching it. In addition, the user data field can perform common automated configuration tasks and even run scripts after the instance starts.