远程服务器挂载oss

要在远程服务器上挂载阿里云 OSS(对象存储服务),通常使用 ossfs 工具,它可以将 OSS bucket 挂载为本地文件系统。以下是详细步骤:


一、前提条件

  1. 拥有阿里云账号,并已创建:

    • 一个 OSS Bucket
    • 一个具有访问该 Bucket 权限的 AccessKey(建议使用 RAM 用户的 AccessKey,并赋予最小权限)
  2. 远程服务器操作系统:本文以 Ubuntu/Debian 或 CentOS/RHEL 为例。


二、安装 ossfs

Ubuntu/Debian

# 添加 GPG 密钥(如需要)
sudo apt-get update
sudo apt-get install -y g++ git libfuse-dev libcurl4-openssl-dev libxml2-dev mime-support automake libtool

# 克隆 ossfs 源码(推荐使用最新版)
git clone https://github.com/aliyun/ossfs.git
cd ossfs
./autogen.sh
./configure
make
sudo make install

或者使用预编译包(如果可用):

wget https://github.com/aliyun/ossfs/releases/download/v1.93.0/ossfs_1.93.0_ubuntu22.04_amd64.deb
sudo dpkg -i ossfs_1.93.0_ubuntu22.04_amd64.deb

请根据你的系统版本选择对应 .deb 包:https://github.com/aliyun/ossfs/releases

sudo yum install -y gcc gcc-c++ make automake fuse fuse-devel curl-devel libxml2-devel openssl-devel mailcap

git clone https://github.com/aliyun/ossfs.git
cd ossfs
./autogen.sh
./configure
make
sudo make install

或使用 RPM 包(示例):

wget https://github.com/aliyun/ossfs/releases/download/v1.93.0/ossfs-1.93.0-centos7.x86_64.rpm
sudo rpm -ivh ossfs-1.93.0-centos7.x86_64.rpm

三、配置 AccessKey

创建密码文件(建议仅当前用户可读):

echo "your-bucket-name:your-access-key-id:your-access-key-secret" > ~/.passwd-ossfs
chmod 600 ~/.passwd-ossfs

四、创建挂载点并挂载

# 创建本地目录作为挂载点
sudo mkdir -p /mnt/oss

# 挂载(替换 your-bucket-name 和 endpoint)
ossfs your-bucket-name /mnt/oss -ourl=https://oss-cn-hangzhou.aliyuncs.com -o passwd_file=~/.passwd-ossfs

注意:

  • oss-cn-hangzhou.aliyuncs.com 是你的 Bucket 所在区域的 外网 endpoint。如果是内网(ECS 同地域),请使用内网 endpoint(如 oss-cn-hangzhou-internal.aliyuncs.com)以节省流量费用。
  • 可通过 -o allow_other 允许其他用户访问(需修改 /etc/fuse.conf 启用 user_allow_other)。

五、验证挂载

df -h | grep oss
ls /mnt/oss

六、设置开机自动挂载(可选)

编辑 /etc/fstab(谨慎操作):

your-bucket-name /mnt/oss fuse.ossfs _netdev,allow_other,passwd_file=/root/.passwd-ossfs,url=https://oss-cn-hangzhou-internal.aliyuncs.com 0 0
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容