且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将S3存储桶作为文件系统挂载在AWS ECS容器上

更新时间:2022-11-07 13:26:01

您使用rexray/s3fs驱动程序的方法是正确的.

Your approach of using the rexray/s3fs driver is correct.

这些是我要在Amazon Linux 1上运行的步骤.

These are the steps I followed to get things working on Amazon Linux 1.

首先,您需要安装s3fs.

First you will need to install s3fs.

yum install -y gcc libstdc+-devel gcc-c+ fuse fuse-devel curl-devel libxml2-devel mailcap automake openssl-devel git gcc-c++
git clone https://github.com/s3fs-fuse/s3fs-fuse
cd s3fs-fuse/
./autogen.sh
./configure --prefix=/usr --with-openssl
make
make install

现在安装驱动程序.您可能需要在此处修改一些选项,例如使用IAM角色而不是访问密钥和AWS区域.

Now install the driver. There are some options here you might want to modify such as using an IAM role instead of Access Key and AWS region.

docker plugin install rexray/s3fs:latest S3FS_REGION=ap-southeast-2 S3FS_OPTIONS="allow_other,iam_role=auto,umask=000" LIBSTORAGE_INTEGRATION_VOLUME_OPERATIONS_MOUNT_ROOTPATH=/ --grant-all-permissions

现在是重新启动ECS代理程序非常重要的步骤.我也做了很好的更新.

Now the very important step of restarting the ECS agent. I also update for good measure.

yum update -y ecs-init
service docker restart && start ecs

您现在应该准备创建任务定义.重要的部分是您的卷配置,如下所示.

You should now be ready to create your task definition. The important part is your volume configuration which is shown below.

"volumes": [
  {
    "name": "name-of-your-s3-bucket",
    "host": null,
    "dockerVolumeConfiguration": {
      "autoprovision": false,
      "labels": null,
      "scope": "shared",
      "driver": "rexray/s3fs",
      "driverOpts": null
    }
  }
]

现在,您只需要在容器定义中指定安装点:

Now you just need to specify the mount point in the container definition:

"mountPoints": [
  {
    "readOnly": null,
    "containerPath": "/where/ever/you/want",
    "sourceVolume": "name-of-your-s3-bucket"
  }
]

现在,只要您具有访问s3存储桶的适当IAM权限,容器就应该启动,并且可以继续使用s3作为卷.

Now as long as you have appropriate IAM permissions for accessing the s3 bucket your container should start and you can get on with using s3 as a volume.

如果在执行"ATTRIBUTE"任务时遇到错误,请仔细检查插件是否已成功安装在ec2实例上,并且ecs代理已重新启动.还要仔细检查您的驱动程序名称是"rexray/s3fs".

If you get an error running the task that says "ATTRIBUTE" double check that the plugin has been successfully installed on the ec2 instance and the ecs agent has been restarted. Also double check your driver name is "rexray/s3fs".