IBM Cloud의 S3 호환 Object Storage인 ICOS를 리눅스 특정 폴더에 마운트 해 보도록 하자.

사실 Object Storage를 Block Storage로 마운트 하는건 권장하지 않는 사항이다.

왜냐면 랜덤엑세스가 자주일어나는 Block Storage를 http api로 동작하는 Object Storage로 연동하는게 사실 성능 적인 면에서 매우 좋지 않기 때문이다.

Object Stoage는 모든 동작이 https의 api를 통해서 이루어진다. OS의 System Call과 1:1 맵핑을 다한다고 하더라도
OS와 Disk사이에서 직접 콜이 이루어지는 것이  https api를 통해서 원거리의 서버와 call이 하나하나 이루어진다면 얼마나 비효율적일지 생각해 보라.

다만 ICOS로 전송을 위한 게이트웨이나 버퍼역할을 하는거라면 고려 해 볼 수도 있겠다.

어째든 용도에 맞게 선택해야 하며

일반적인 용도라면 AWS CLI를 활용하길 권장한다. (aws s3 sync라는 훌륭한 커맨드가 있습니다.)


어째든 필요하면 써야하므로, s3fs보다는 성능이 좋다는 goofys를 쓸것이다. (riofs도 나름 빠른데.. goofys 때문에 어째 묻혔다.)

https://github.com/kahing/goofys

사실 그냥 github에서 실행 파일 하나만 받고 마운트만 해주면 끝.

물론 ICOS는 AWS에서 처럼 서버에 role설정이 안되기 때문에 credential 파일을 따로 만들어 주어야 한다.


아래 예제에서 5개 값만 바꾸신후 쉘에서 붙여넣기 하시면 된다.

MOUNT_DIR="/icos" =S3 마운트 할 디렉토리 명.
ACCESS_KEY="yNXRmWIP****" ICOS 엑세스 키입니다. 포털에서 확인 가능.
SECRET_KEY="r5aeBB6******" ICOS 시크릿키입니다. 포털에서 확인 가능.
ICOS_BUCKET_NAME="cloudz"  ICOS의 마운트할 버킷 명. 미리 해당 버킷을 만들어 두어야 한다.
ICOS_ENDPOINT="https://s3.seo-ap-geo.objectstorage.service.networklayer.com" SEO01의 ICOS 사설 엔트포인트로 포털에서 확인 가능. 한국/일본/홍콩은 크로스 리전이여서 자동 동기화(async) 되며 가까운 곳으로 접속하면 된다.
공인으로 하면 트래픽 비용이 나오므로 꼭 사설로 하길 권장한다.

#=============================================================================
MOUNT_DIR="/icos"
ACCESS_KEY="yNXRmWIP9T1**********"
SECRET_KEY="r5aeBB6CnI9qeQgdb*************"
ICOS_BUCKET_NAME="cloudz****"
ICOS_ENDPOINT="https://s3.seo-ap-geo.objectstorage.service.networklayer.com"

#=============================================================================
yum install -y fuse

wget http://bit.ly/goofys-latest -O /usr/local/bin/goofys
chmod 755 /usr/local/bin/goofys

mkdir -p ~/.aws
cat << EOF >> ~/.aws/credentials
[icos]
aws_access_key_id = $ACCESS_KEY
aws_secret_access_key = $SECRET_KEY
EOF
chmod 600  ~/.aws/credentials

mkdir -p $MOUNT_DIR
# goofys --endpoint=$ICOS_ENDPOINT --profile=icos --dir-mode=0777 --file-mode=0666 $ICOS_BUCKET_NAME $MOUNT_DIR
cat << EOF >> /etc/fstab
goofys#$ICOS_BUCKET_NAME  $MOUNT_DIR  fuse  _netdev,allow_other,--endpoint=$ICOS_ENDPOINT,--profile=icos,--dir-mode=0777,--file-mode=0666 0  0
EOF
mount -a


캐시로 체감을 올릴려면 catfs를 적용해서 테스트 해보길 바란다. 앞서 말했지만 Object Storage는 마운트해서 쓰라고 만든게 아니다. 다만, 캐시로 어느정도 극복은 가능하다.

https://github.com/kahing/catfs


goofys --help를 보면 아래 같은 내용이 나온다.
이 중 --uid 와 --gid 를 활용하면 특정 User와 Group ID로 해당 마운트되는 디렉토리 및 파일의 소유자를 설정할 수 있다.
기본은 유저가 root이므로 애플리케이션에서 Wirte를 못하는 권한 문제가 발생할 수 있다.
특정 유저로 파일이 써져야 한다면 --uid value  --gid value 를 추가하면 해당 권한으로 파일이 생성 된다.

따라서, --dir-mode 와 --file-mode 를 상기에서는 Others모두 오픈 했으나, uid,gid를 부여하고 mode는 755,644등 적절한 값으로 조정해서 보안을 좀 더 강화 할 수 있다.

--acl=public-read를 활용하면 오픈 파일을 외부에서 아무 권한없이 https주소를 통해 가져 갈 수 있다. 일반적으로 쓸 일이 없겠지만, Object Storage 자체를 WebServer로 쓴다거나 CDN의 Origin으로 쓸 때는 꼭 필요한 옵션이다. (AWS의 S3를 쓴다면 acl보다는 policy 설정을 권장한다. Softlayer ICOS는 policy 설정이 안되서;;;)


조금 테스트 해보 았다면, 파일을 다른 방법으로 올리거나, 파일명을 바꾸었을때 바로 폴더에 반영 안되는것을 알수 있을 것이다. (기본 1분 필요)
--stat-cache-ttl와 --type-cache-ttl값을 보면 알수 있을 것이다. 허용가능한 수준으로 바꾸되 너무 짧게 하는 건 API Call이 그만큼 자주 발생할 것이므로 비추천한다. (비용과 서버 부하도 모두 증가하게 된다)

NAME:
   goofys - Mount an S3 bucket locally

USAGE:
   goofys [global options] bucket[:prefix] mountpoint

VERSION:
   0.19.0-943e017724ea820eb4185419ef3c41d6f921a324

GLOBAL OPTIONS:
   -o value            Additional system-specific mount options. Be careful!
   --cache value       Directory to use for data cache. Requires catfs and `-o allow_other'. Can also pass in other catfs options (ex: --cache "--free:10%:$HOME/cache") (default: off)
   --dir-mode value    Permission bits for directories. (default: 0755) (default: 493)
   --file-mode value   Permission bits for files. (default: 0644) (default: 420)
   --uid value         UID owner of all inodes. (default: 0)
   --gid value         GID owner of all inodes. (default: 0)
   --endpoint value    The non-AWS endpoint to connect to. Possible values: http://127.0.0.1:8081/
   --profile value     Use a named profile from $HOME/.aws/credentials instead of "default"
   --use-content-type  Set Content-Type according to file extension and /etc/mime.types (default: off)

TUNING OPTIONS:
   --cheap                 Reduce S3 operation costs at the expense of some performance (default: off)
   --no-implicit-dir       Assume all directory objects ("dir/") exist (default: off)
   --stat-cache-ttl value  How long to cache StatObject results and inode attributes. (default: 1m0s)
   --type-cache-ttl value  How long to cache name -> file/dir mappings in directory inodes. (default: 1m0s)

AWS S3 OPTIONS:
   --region value         The region to connect to. Usually this is auto-detected. Possible values: us-east-1, us-west-1, us-west-2, eu-west-1, eu-central-1, ap-southeast-1, ap-southeast-2, ap-northeast-1, sa-east-1, cn-north-1 (default: "us-east-1")
   --storage-class value  The type of storage to use when writing objects. Possible values: REDUCED_REDUNDANCY, STANDARD, STANDARD_IA. (default: "STANDARD")
   --sse                  Enable basic server-side encryption at rest (SSE-S3) in S3 for all writes (default: off)
   --sse-kms key-id       Enable KMS encryption (SSE-KMS) for all writes using this particular KMS key-id. Leave blank to Use the account's CMK - customer master key (default: off)
   --acl value            The canned ACL to apply to the object. Possible values: private, public-read, public-read-write, authenticated-read, aws-exec-read, bucket-owner-read, bucket-owner-full-control (default: off)

MISC OPTIONS:
   --help, -h     Print this help text and exit successfully.
   --debug_fuse   Enable fuse-related debugging output.
   --debug_s3     Enable S3-related debugging output.
   -f             Run goofys in foreground.
   --version, -v  print the version


+ Recent posts