美文网首页
阿里云利用ossfs挂载本地目录

阿里云利用ossfs挂载本地目录

作者: Chting | 来源:发表于2024-04-10 16:20 被阅读0次

安装ossfs

  • Ubuntu系统
  • 以Ubuntu 16.04 (x64)版本为例,依次执行以下命令安装ossfs。
sudo wget https://gosspublic.alicdn.com/ossfs/ossfs_1.91.2_ubuntu16.04_amd64.deb
sudo apt-get update
sudo apt-get install gdebi-core
sudo gdebi ossfs_1.91.2_ubuntu16.04_amd64.deb
  • CentOS系统/Anolis系统
  • 以CentOS 7.0(x64)版本为例,安装命令如下:
sudo wget https://gosspublic.alicdn.com/ossfs/ossfs_1.91.2_centos7.0_x86_64.rpm
sudo yum install ossfs_1.91.2_centos7.0_x86_64.rpm
  • 查看ossfs是否安装成功
ossfs -h

配置挂载

  • 设置密码
echo bucket-test:LTAIbZcdVCmQ****:MOk8x0y9hxQ31coh7A5e2MZEUz**** > /etc/passwd-ossfs
chmod 640 /etc/passwd-ossfs
  • 创建挂载目录
mkdir /tmp/ossfs
ossfs bucket-test /tmp/ossfs -o url=http://oss-cn-hangzhou.aliyuncs.com
  • 设置权限允许非空目录
ossfs bucket-test /tmp/ossfs -o url=http://oss-cn-hangzhou.aliyuncs.com -o umask=007 -o allow_other -o nonempty
  • 赋予www用户权限
## 查看gid
id www
#如uid=1000(www) gid=1000(www) groups=1000(www)
##设置权限
ossfs bucket-test /tmp/ossfs -o url=http://oss-cn-hangzhou.aliyuncs.com -o umask=007 -o nonempty -o allow_other -o mp_umask=007 -o uid=1000 -o gid=1000
  • 测试挂载是否成功,如果能看到ossfs就说明成功啦
df -h
  • 如果您不希望继续挂载此Bucket,您可以将其卸载。
sudo fusermount -u /tmp/ossfs

设置开机启动

CentOS 7.0及以上的系统通过开机自动启动脚本进行挂载

  1. 在/etc/init.d/目录下建立文件ossfs 内容为
#! /bin/bash
#
# ossfs      Automount Aliyun OSS Bucket in the specified direcotry.
#
# chkconfig: 2345 90 10
# description: Activates/Deactivates ossfs configured to start at boot time.

ossfs bucket-test /tmp/ossfs -o url=http://oss-cn-hangzhou.aliyuncs.com -o umask=007 -o allow_other -o nonempty
  1. 为新建立的ossfs脚本赋予可执行权限:

    chmod a+x /etc/init.d/ossfs
    

    命令执行完成后,您可以尝试执行该脚本,如果脚本文件内容无误,那么此时OSS中的Bucket已经挂载到您指定的目录下了。

  2. 把ossfs启动脚本作为其他服务,开机自动启动:

    chkconfig ossfs on
    
  3. 验证开机启动

##查看所有的开机启动项
chkconfig --list | grep ':on'
##查看ossfs的配置
systemctl status ossfs.service

参考https://help.aliyun.com/zh/oss/developer-reference/use-ossfs-to-mount-an-oss-bucket-to-the-local-directories-of-an-ecs-instance/

相关文章

网友评论

      本文标题:阿里云利用ossfs挂载本地目录

      本文链接:https://www.haomeiwen.com/subject/flgqxjtx.html