简体   繁体   English

重启 EC2 实例后 AWS S3 存储桶未重新挂载

[英]AWS S3 bucket is not remounting after restarting EC2 Instance

I mounted my S3 bucket to my EC2 Instance using S3fs , and I was able to read, write to my S3 bucket.我使用S3fs将我的 S3 存储桶安装到我的 EC2 实例上,并且能够读取、写入我的 S3 存储桶。 But after restarting my EC2 Instance, S3 bucket is automatically unmounted.但重启我的 EC2 实例后,S3 存储桶会自动卸载。 I found that to make it persistent and automatically mount for every reboot we need to add below entries to /etc/rc.local我发现要使其持久化并在每次重新启动时自动挂载,我们需要将以下条目添加到 /etc/rc.local

/usr/bin/s3fs myS3bucket -o use_cache=/tmp -o allow_other -o multireq_max=5 /myS3bucket

But still It is not mounting on reboot.但它仍然没有在重新启动时安装。

Did you went through the official documentation ?你浏览过官方文档吗?

You can also mount on boot by entering the following line to /etc/fstab:您还可以通过在 /etc/fstab 中输入以下行来在启动时挂载:

s3fs#mybucket /path/to/mountpoint fuse _netdev,allow_other 0 0 s3fs#mybucket /path/to/mountpoint fuse _netdev,allow_other 0 0

or或者

(…) (……)

Note2: You may also need to make sure netfs service is start on boot注意 2:您可能还需要确保 netfs 服务在启动时启动

A network mount requires a network access in the first place.网络挂载首先需要网络访问。

I was able to make it work by running it as systemd service.我能够通过将其作为systemd服务运行来使其工作。

  • Create Service File - /usr/lib/systemd/system/mybucket-mount.service创建服务文件 - /usr/lib/systemd/system/mybucket-mount.service

     [Unit] Description = Mount S3 Bucket my-bucket Wants=network-online.target After=network.target network-online.target [Service] Type=oneshot RemainAfterExit=yes ExecStart = /usr/bin/s3fs my-bucket /MyBucketMount/ -o uid=500,gid=501,iam_role=MyRole,use_cache=/tmp,endpoint=ap-south-1,url=https://s3.amazonaws.com ExecStop=/bin/umount /MyBucketMount/ [Install] WantedBy = multi-user.target
  • Create Link创建链接

    ln  -sf /usr/lib/systemd/system/mybucket-mount.service /etc/systemd/system/multi-user.target.wants/mybucket-mount.service
  • Enable Service启用服务

    systemctl enable mybucket-mount.service
  • Start Service启动服务

    systemctl start mybucket-mount.service

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM