본문 바로가기
Cloud/AWS

AWS#2 EC2 인스턴스에 S3 마운트 하는 법(goofys)

by 짜깡이 2021. 2. 17.

 

1) S3 버킷 생성하기

AWS 검색창에 S3입력

 

오른쪽 상단 버킷 만들기 

 

버킷 이름 설정
설정 건드릴 필요없이 디폴트로 생성

 

버킷 생성 완료

 

2) EC2 인스턴스에 goofys 설치하기

[root@test ~]# yum -y install golang fuse git   

  *golang 패키지가 없을 경우 직접 설치
  [root@test ~]#cd /usr/lib/golang/
  [root@test ~]#wget https://golang.org/dl/go1.15.8.linux-amd64.tar.gz
  [root@test ~]#tar -zxvf go1.15.8.linux-amd64.tar.gz
  [root@test ~]#cd go
  [root@test ~]#mv * .. 
  [root@test ~]#cd ..
  [root@test ~]#rm -rf go


[root@test ~]#
mkdir -p /usr/local/golang      (go get으로 받아올 GOPATH 경로 디렉터리 생성)

[root@test ~]#vim /etc/profile

export GOROOT=/usr/lib/golang                          (golang 설치된 디렉터리 지정)
export GOBIN=$GOROOT/bin                    
export GOPATH=/usr/local/golang                         (미리 만든 경로 디렉터리) 
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

:wq!

     

[root@test ~]source /etc/profile          (환경변수 업로드)

[root@test ~]go version    (go 버전확인)

[root@test ~]go env (go 환경변수 GOROOT, GOBIN, GOPATH 제대로 지정 되었는지 확인)

[root@test ~]go get  github.com/kahing/goofys  (이거 용량이 커서 오래걸리니 기다려주셔야 합니다..)

[root@test ~]go install github.com/kahing/goofys

여기까지 완료되면 goofys 설치 끝

 

3) S3 액세스 키 설정

[root@test ~]mkdir -p ~/.aws

[root@test ~]vim ~/.aws/credentials        (aws에서는 이 경로를 이용해 자격정보를 가져옴)

[default]
aws_access_key_id= 액세스 키
aws_secret_access_key= 비밀 액세스 키

 

4) S3 마운트

[root@test ~]mkdir -p /goofys  (마운트 폴더 만들어주기)

[root@test ~]goofys goofys-test /goofys (S3 버킷 마운트)

[root@test ~]df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  482M     0  482M   0% /dev
tmpfs          tmpfs     492M     0  492M   0% /dev/shm
tmpfs          tmpfs     492M  436K  492M   1% /run
tmpfs          tmpfs     492M     0  492M   0% /sys/fs/cgroup
/dev/xvda1     xfs       8.0G  3.5G  4.6G  43% /
tmpfs          tmpfs      99M     0   99M   0% /run/user/1000
goofys-test   fuse      1.0P     0  1.0P   0% /goofys

하지만 이렇게 마운트하면 재접속시 마운트가 해제됨

따라서 fstab에 등록하는 영구마운트 과정 필요

 

-영구마운트 
[root@test ~]vim /etc/fstab
/usr/lib/golang/bin/goofys#goofys-test /goofys fuse _netdev,allow_other 0 0    
:wq!

[root@test ~]mount -a  (마운트, 인스턴스 재부팅 후 확인하면 끝)

↑fstab안에   goofys위치#S3버킷이름 마운트포인트 파일시스템  마운트옵션  덤프 검사  양식으로 작성


마운트 옵션
defaults
설정되지 않은 값에 대해서는 기본 설정을 따릅니다.

_netdev
네트워크 드라이브임을 의미하며, 마운트 시도 전 네트워크가 올바르게 설정되어 있는지 검사합니다.

delay_connect
부팅 과정에서 아직 네트워크 설정이 끝나지 않아 마운트를 하지 못하는 경우에 대비하여 시간을 지연하여 연결합니다.

allow_other
마운트된 디렉토리에 일반 유저의 접근을 허용합니다.

uid, gid
마운트된 디렉토리의 소유(Ownership)을 지정합니다. 특정 유저의 uid및 gid는 'id {username}'명령으로 확인할 수 있습니다.

IdentifyFile
인증에 사용할 Key를 지정합니다. 마운트는 root권한으로 실행되므로 Key가 root의 홈디렉토리에 존재하지 않는 경우 이렇게 수동으로 지정해 줘야 합니다.

5) S3와 연동 확인

 

[root@test ~]mkdir -p /goofys/goofys-test/Test  
[root@test ~]cd /goofys/goofys-test/Test
[root@test ~]touch ABC

[root@test ~]touch readme.txt

파일 생성 확인

 

댓글