AWS/AWS 일반

[AWS] EC2에 S3 Mount 하기 - ubuntu.16.04 (with. s3fs)

yubi5050 2022. 6. 12. 17:29

S3FS(s3fs-fuse)는 AWS S3를 로컬에 Mount 시켜 FileSystem 처럼 활용 할 수 있게 하는 라이브러리 이다.

EC2에서 S3를 Mount 하는 방법을 적어보았다. 

 

👉 1. EC2 Update, Upgrade 진행

sudo apt-get update
sudo apt-get upgrade

 

👉 2. 관련 패키지 설치

# 패키지 설치
sudo apt-get install build-essential git libfuse-dev libcurl4-openssl-dev libxml2-dev mime-support automake libtool
sudo apt-get install pkg-config libssl-dev

 

👉 3. Git S3FS 다운로드

 # Git S3FS Donwload
git clone https://github.com/s3fs-fuse/s3fs-fuse

 

👉 4. S3FS Install

 # Intall S3FS 
cd s3fs-fuse/
./autogen.sh
./configure --prefix=/usr --with-openssl
make
sudo make install

 

👉 5. S3FS 설정

passwd-s3fs 파일에 IAM 사용자에서 받아온 키를 <Access Key,>:<Secret Key> 형태로 입력

# passwd-s3fs에 IAM 사용자 Access Key, Secret Key 등록
sudo nano /etc/passwd-s3fs
# 파일 내 <Access Key,>:<Secret Key> 형태 작성

 

👉 6. 파일 권한 설정 (READ 삭제)

# 파일 권한 READ 삭제
sudo chmod 640 /etc/passwd-s3fs

 

👉 7. fuse 설정 파일 열어서 user_allow_other 주석 삭제

user_allow_other는 모든 유저의 접근을 허용시켜주는 옵션

# S3FS 환경설정 파일 열어서 user_allow_other 주석 삭제하기
sudo nano /etc/fuse.conf
# user_allow_other 주석 삭제

 

👉 8. Mount 할 폴더명 설정 및 Bucket 연결

# sudo mkdir /mnt/<마운트할 폴더명>
sudo mkdir /mnt/luckyseven-s3
# sudo /usr/bin/s3fs <버킷 이름> <마운트 폴더명> -o allow_other -o use_cache=/tmp
sudo /usr/bin/s3fs luckyseven-todaylunch /mnt/luckyseven-s3 -o allow_other -o use_cache=/tmp

 

👉 9. 해당 경로에 들어가서 데이터 확인

cd /mnt/luckyseven-s3/
ls

S3 -> /mnt/<폴더명> 확인

 

👉 10. 현재 Mount 된 FileSystem 확인 (df -h 명령어)

# 마운트 된 FileSystem 확인
df -h

현재 FileSystem 확인

 

참고링크

- https://securecoding4u.com/2016/02/13/ec2-ubuntu-s3-mount/

- https://junghyeonsu.tistory.com/69