![Photo by Steve Johnson on Unsplash](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/steve-johnson-S0j-5wSN3YQ-unsplash-scaled.jpg?resize=1038%2C576&ssl=1)
[AWS] EC2 ubuntu 18.04에 EFS 마운트하기
파일이 크지만, 영구적으로 저장될 필요가 없는 경우에는 S3를 사용하는게 꼭 최선이 아닐 수 있습니다. 최근에 비디오 관련된 작업을 한적이 있었는데, 다운로드를 하고 분석을 한뒤에 삭제를 하면 되는 과정이였습니다. 물론 분석과정에 많은 인스턴스들이 투입이 되어야 하는 로직이였습니다.
제 경우에 가장 중요한 포인트는, S3를 사용하지 않고, 여러 인스턴스들이 동일한 파일에 접근하는 것입니다.
그래서, AWS의 EFS를 Network File System (NFS)으로 사용하기로 했습니다.
OS: ubuntu 18.04
1. EFS 런칭
AWS Management Console에서 EFS를 찾으세요.
![](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/image-30-1024x750.png?resize=640%2C469&ssl=1)
Create file system button을 클릭 하세요
![](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/image-31-1024x750.png?resize=640%2C469&ssl=1)
아무 이름이나 지으세요
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-32-1024x750.png?resize=640%2C469&ssl=1)
끝!
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-33-1024x750.png?resize=640%2C469&ssl=1)
2. EC2 instance 런칭
EFS 관련되서 찾아 오신 분들이니까, 이 부분은 이미 잘 아실 거라고 생각하고 설명을 생략하도록 하겠습니다.
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-34-1024x750.png?resize=640%2C469&ssl=1)
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-35-1024x750.png?resize=640%2C469&ssl=1)
![](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/image-36-1024x750.png?resize=640%2C469&ssl=1)
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-37-1024x750.png?resize=640%2C469&ssl=1)
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-38-1024x750.png?resize=640%2C469&ssl=1)
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-39-1024x750.png?resize=640%2C469&ssl=1)
보안 그룹에 대한 추가작업은 나중에 진행하도록 하겠습니다. 그냥 22번 포트만 열어두세요!
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-40-1024x750.png?resize=640%2C469&ssl=1)
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-41-1024x750.png?resize=640%2C469&ssl=1)
![](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/image-42-1024x750.png?resize=640%2C469&ssl=1)
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-43-1024x750.png?resize=640%2C469&ssl=1)
![](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/image-44-1024x750.png?resize=640%2C469&ssl=1)
3. EC2에서 EFS를 위한 세팅작업
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-45.png?resize=640%2C496&ssl=1)
![](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/image-46.png?resize=640%2C496&ssl=1)
mounting을 하기위한 관련된 패키지들을 다음 명령어를 활용하여 설치해주세요.
sudo apt-get update
git clone https://github.com/aws/efs-utils
sudo apt-get -y install binutils
cd efs-utils
./build-deb.sh
sudo apt-get -y install ./build/amazon-efs-utils*deb
EFS가 연결될 폴더를 하나 생성 해주겠습니다.
sudo mkdir /mnt/efs
sudo chmod 775 /mnt/efs
sudo chown -R $USER /mnt/efs
4. EC2를 위한 역할(Role) 만들기
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-47-1024x750.png?resize=640%2C469&ssl=1)
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-48-1024x750.png?resize=640%2C469&ssl=1)
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-49-1024x750.png?resize=640%2C469&ssl=1)
EFS에 대한 정책(policy)가 기본적으로는 없는 것 같으니, 하나 만들겠습니다.
![](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/image-50-1024x750.png?resize=640%2C469&ssl=1)
EFS를 서비스로 고르고, 액션은 그냥 Full Action 주고, Resouce는 저희가 위에서 만든 EFS를 선택하겠습니다.
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-51-1024x750.png?resize=640%2C469&ssl=1)
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-52-1024x750.png?resize=640%2C469&ssl=1)
policy의 이름을 자유롭게 적어주세요!
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-54-1024x750.png?resize=640%2C469&ssl=1)
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-55-1024x750.png?resize=640%2C469&ssl=1)
다시 역할을 세팅하던 페이지로 돌아와서, 저희가 방금 생성한 Policy를 추가합니다.
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-56-1024x750.png?resize=640%2C469&ssl=1)
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-57-1024x750.png?resize=640%2C469&ssl=1)
생성!
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-58-1024x750.png?resize=640%2C469&ssl=1)
5. EC2에 추가적인 세팅
두 가지에 대해서 추가적으로 작업을 해주셔야 하는데,
첫번째로는, 위에서 만든 역할을 EC2 인스턴스에 할당 하는 것이고, 두번째는 보안 그룹을 하나 더 추가해주는 것입니다.
먼저 역할 할당!
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-59-1024x750.png?resize=640%2C469&ssl=1)
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-60-1024x750.png?resize=640%2C469&ssl=1)
다음으로, 아래 그림과 같이 default라는 보안그룹을 EC2에 추가적으로 할당해주세요.
![](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/image-61-1024x750.png?resize=640%2C469&ssl=1)
![](https://i2.wp.com/codethief.io/wp-content/uploads/2020/10/image-62-1024x750.png?resize=640%2C469&ssl=1)
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-63-1024x750.png?resize=640%2C469&ssl=1)
6. EFS 마운팅 하기
이제 AWS console에서 할일은 다 끝났습니다. 다시 터미널로 돌아와서 마무리 작업을 하겠습니다.
먼저, 아래 명령어로 EFS를 Mount 하겠습니다.
fs-xxxxxxxx 는 여러분의 EFS 아이디 입니다. EFS 페이지에 가시면 찾을 수 있습니다.
sudo mount -t efs fs-xxxxxxxx:/ /mnt/efs
df -h 명령어를 쳐보시면, 이제 제일 아래에 있는 것 과 같이 EFS가 마운트 된 것을 확인 해보실 수 있습니다.
![](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/image-64.png?resize=640%2C490&ssl=1)
이제 인스턴스가 재부팅이 되도 자동으로 마운팅이 될 수 있도록 설정을 하겠습니다. 아래 명령어를 입력해주세요.
echo "fs-xxxxxxxx.efs.us-east-1.amazonaws.com:/ /mnt/efs efs _netdev,tls,iam 0 0" | sudo tee -a /etc/fstab
한번 재부팅을 한 다음에 EFS가 할당 되었는지 보세요!
![](https://i1.wp.com/codethief.io/wp-content/uploads/2020/10/image-65.png?resize=640%2C490&ssl=1)
왜 그런지는 모르겠지만, 주소가 127.0.01로 바뀌었네요.. 그런데, 동작하는데는 크게 문제가 없는 것 같습니다!
![](https://i0.wp.com/codethief.io/wp-content/uploads/2020/10/image-66.png?resize=640%2C490&ssl=1)
Happy coding!
보안 그룹과 같이 몇몇 세팅이 최적의 세팅이 아닌 것 같은데, 그 부분은 EFS의 네트워크 탭에 가셔서 여러분만의 보안 그룹으로 바꾸실 수 있습니다 (default가 아닌)
References
- https://docs.aws.amazon.com/efs/latest/ug/whatisefs.html