挂载阿里云oss到centos6以及其他linux服务器文件夹

内容目录

centos7 ubuntu等官方教程

安装ossfs :https://help.aliyun.com/zh/oss/developer-reference/use-ossfs-to-mount-an-oss-bucket-to-the-local-directories-of-an-ecs-instance
开机启动:https://help.aliyun.com/zh/oss/developer-reference/advanced-configurations
oss定价:https://www.aliyun.com/price/detail/oss

注意点

个人测试centos6 7 安装后直接输入ossfs
-bash: ossfs: command not found
可执行文件在 /usr/local/bin/ossfs
所以可以/usr/local/bin/ossfs 加命令运行
或者

ln -s /usr/local/bin/ossfs /usr/bin/ossfs

就可以单独使用ossfs不用输入路径了

centos6 挂载oss

官方文档是不支持的
参考教程 https://blog.csdn.net/gaoshanliushui131/article/details/104779009/
但是教程安装完fuse没有ldconfig
所以提示

/usr/local/bin/ossfs: error while loading shared libraries: libfuse.so.2: cannot open shared object file: No such file or directory

完整安装挂载开机启动命令

# 安装依赖
yum install automake  gcc-c++ git libcurl-devel libxml2-devel make openssl-devel

# 安装 fuse
wget https://github.com/libfuse/libfuse/releases/download/fuse-2.9.9/fuse-2.9.9.tar.gz
tar -zxvf fuse-2.9.9.tar.gz
cd fuse-2.9.9
./configure
make
make install

# 添加环境变量
vi /etc/profile
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

source /etc/profile
#刷新共享库缓存
ldconfig

# 查看版本
pkg-config --modversion fuse
#创建验证文件
sudo sh -c 'echo bucket-test:LTAIbZcdVCmQ****:MOk8x0y9hxQ31coh7A5e2MZEUz**** > /etc/passwd-ossfs'
sudo chmod 640 /etc/passwd-ossfs
#根据自己的地域  内网 外网 选择地址
sudo mkdir /tmp/ossfs
sudo ossfs bucket-test /tmp/ossfs -o url=http://oss-cn-hangzhou-internal.aliyuncs.com
#创建开机启动
 vim /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.
fusermount -u /tmp/ossfs
ossfs bucket-test /tmp/ossfs -ourl=http://oss-cn-hangzhou-internal.aliyuncs.com -oallow_other

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

卸载butket

fusermount -u 挂载路径

fusermount -u /mnt/oss-bucket

强制卸载

fusermount: failed to unmount /mnt/oss-bucket: Device or resource busy

fusermount -uz /mnt/oss-bucket

Ubuntu 22.04 上使用非 root 用户挂载 OSS

1. 安装 ossfs

首先,确保已经安装了 ossfs,可以使用以下命令下载并安装:

注意ubuntu系统版本号

sudo wget https://gosspublic.alicdn.com/ossfs/ossfs_1.91.4_ubuntu22.04_amd64.deb
sudo apt-get update
sudo apt-get install gdebi-core
sudo gdebi ossfs_1.91.4_ubuntu22.04_amd64.deb

或者可以通过阿里云官方提供的下载地址进行安装。

2. 配置 OSS 访问密钥

创建一个 passwd-ossfs 文件,用于保存 OSS 的 AccessKeyIdAccessKeySecret

echo "your-bucket-name:AccessKeyId:AccessKeySecret" > ~/.passwd-ossfs
chmod 640 ~/.passwd-ossfs  # 设置文件权限

3. 创建挂载目录

选择一个目录作为挂载点(例如 /mnt/oss),并确保该非 root 用户对这个目录有访问权限:

mkdir -p /mnt/oss
sudo chown your-user:your-group /mnt/oss

your-useryour-group 替换为具体的非 root 用户和用户组名。

4. 挂载 OSS 文件系统

使用非 root 用户执行挂载命令:

ossfs your-bucket-name /mnt/oss -ourl=http://oss-region.aliyuncs.com

其中,将 your-bucket-nameoss-region.aliyuncs.com 替换为具体的 OSS 桶名和地域节点 URL。

5. 配置自动挂载(可选)

脚本开机启动

crontab -e

开机启动

@reboot /home/user/oss.sh

脚本内容 注意URL endpoint要对

ossfs your-bucket-name /mnt/oss -o url=http://oss-region.aliyuncs.com -oallow_other

/etc/fstab开机启动

连不上网可以服务器启动可能卡住不推荐

可以将挂载信息添加到 /etc/fstab 中,以便系统启动时自动挂载。编辑 /etc/fstab 文件,添加以下内容:

ossfs#your-bucket-name /mnt/oss fuse _netdev,url=http://oss-region.aliyuncs.com,allow_other 0 0

保存后,通过以下命令重新挂载:

sudo mount -a

注意事项

  • 确保非 root 用户具有 /mnt/oss 目录的读写权限。
  • 配置 allow_other 选项时,需要在 /etc/fuse.conf 中去掉#号注释启用 user_allow_other 配置

English

Mount Alibaba Cloud OSS to CentOS 6/7 Server Directory

  1. Install ossfs:

  2. Startup Configuration:

  3. oss Pricing:

Notes:

During personal testing on CentOS 6 and 7, after installation, directly entering ossfs resulted in -bash: ossfs: command not found. The executable file is located at /usr/local/bin/ossfs. Therefore, you can run /usr/local/bin/ossfs followed by the command. Alternatively, you can create a symbolic link as follows:

ln -s /usr/local/bin/ossfs /usr/bin/ossfs

This allows using ossfs standalone without specifying the full path.

Mounting OSS on CentOS 6:

Official documentation does not support CentOS 6. However, you can refer to this tutorial. Note that after installation, the tutorial lacks the ldconfig command, resulting in the following error:

/usr/local/bin/ossfs: error while loading shared libraries: libfuse.so.2: cannot open shared object file: No such file or directory

Complete Installation, Mounting, and Startup Command:

# Install dependencies
yum install automake gcc-c++ git libcurl-devel libxml2-devel make openssl-devel

# Install fuse
wget https://github.com/libfuse/libfuse/releases/download/fuse-2.9.9/fuse-2.9.9.tar.gz
tar -zxvf fuse-2.9.9.tar.gz
cd fuse-2.9.9
./configure
make
make install

# Add environment variables
vi /etc/profile
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

source /etc/profile
# Refresh shared library cache
ldconfig

# Check version
pkg-config --modversion fuse

# Create authentication file
sudo sh -c 'echo bucket-test:LTAIbZcdVCmQ****:MOk8x0y9hxQ31coh7A5e2MZEUz**** > /etc/passwd-ossfs'
sudo chmod 640 /etc/passwd-ossfs

# Depending on your region (internal, external), choose the address
sudo mkdir /tmp/ossfs
sudo ossfs bucket-test /tmp/ossfs -o url=http://oss-cn-hangzhou-internal.aliyuncs.com

# Create startup script
vim /etc/init.d/ossfs

#! /bin/bash
#
# ossfs      Automount Aliyun OSS Bucket in the specified directory.
#
# chkconfig: 2345 90 10
# description: Activates/Deactivates ossfs configured to start at boot time.
fusermount -u /tmp/ossfs
ossfs bucket-test /tmp/ossfs -ourl=http://oss-cn-hangzhou-internal.aliyuncs.com -oallow_other

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

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注