ossfs is a tool that allows you to mount Object Storage Service (OSS) buckets to your local Linux operating system. This enables your application to directly access data stored in the OSS bucket from the file system, facilitating operations such as opening and reading the data. ossfs automatically converts these operations into OSS API calls.
ossfs has two versions: 1.0 and 2.0. Version 2.0 has been completely restructured for new compute-intensive applications, achieving comprehensive performance upgrades but with some limitations on POSIX semantics. It is the main development version for the future. If you are developing AI training, inference, autonomous driving simulation, or other new applications, and cannot conveniently use the OSS SDK and OSS Connector for AI/ML, we strongly recommend using ossfs 2.0 (Preview). In comparison, ossfs 1.0 provides more comprehensive POSIX semantics support and is suitable for daily use in scenarios without special performance requirements.
Prerequisites
You have registered an Alibaba Cloud account.
You have activated OSS and created an OSS bucket.
Install ossfs 2.0
Install ossfs on Alibaba Cloud Linux
Run the following command to download the package:
sudo wget https://gosspublic.alicdn.com/ossfs/ossfs2_2.0.0beta_linux_x86_64.rpm
Run the following command to install ossfs 2.0:
sudo yum install ossfs2_2.0.0beta_linux_x86_64.rpm
Run the following command to verify whether ossfs 2.0 is installed:
ossfs2 --version
The following figure shows that ossfs 2.0 is installed.
Configure ossfs 2.0
In practical use, to meet the mounting requirements of OSS buckets in different scenarios, you need to configure the ossfs 2.0 configuration file specifically. Then when mounting the OSS bucket, you can reference this configuration file to complete the mounting.
Create a RAM user AccessKey with OSS management permissions.
View the bucket's endpoint.
Go to the Bucket List page, select the target bucket and enter it, then click Overview in the left navigation bar. You can view the region of the target bucket in the Access Points section on the overview page. As shown in the figure, using a bucket in the Hangzhou region as an example.
Create an ossfs 2.0 configuration file.
You can freely set the file name and path of the ossfs 2.0 configuration file as needed. For example, create a
/etc/ossfs2.conf
file as the configuration file.sudo touch /etc/ossfs2.conf
Fill in the mounting information. Taking the read-only mounting of an entire bucket as an example.
Open the created ossfs 2.0 configuration file, configure it according to the following example (using the Hangzhou region internal endpoint as an example), and save it. Internal and OSS accelerator endpoints only support mounting instances within the same region's VPC, providing faster and more stable data transmission. Using the public endpoint to access ossfs is not recommended because it may cause various stuttering issues due to high latency and unstable Internet connections.
# Bucket endpoint (region node) --oss_endpoint=https://oss-cn-hangzhou-internal.aliyuncs.com # Bucket name --oss_bucket=bucketName # RAM user AccessKeyId and AccessKeySecret --oss_access_key_id=LTAI****************** --oss_access_key_secret=8CE4********************** # Mount in read-only mode --ro=true
Mount and access
Create a mount directory.
You can freely set the file name and path of the mount directory as needed. For example, create a
/tmp/ossfs2-bucket
directory as the mount directory.mkdir /tmp/ossfs2-bucket
Execute the mount command.
Execute the command to mount the bucket configured in the ossfs 2.0 configuration file
ossfs2.conf
in read-only mode to the local/tmp/ossfs2-bucket/
directory. If you need to use read-write mounting, remove the--ro=true
option from theossfs2.conf
configuration file.ossfs2 mount /tmp/ossfs2-bucket/ -c /etc/ossfs2.conf
Operate the mounted bucket.
After mounting is complete, you can operate on objects in the bucket as if you were accessing a local file system. For example, execute the
sudo ls -lh /tmp/ossfs2-bucket/
command to view the file list of the mounted bucket.Unmount the mounted bucket.
If you no longer need to mount this bucket, you can execute the following command to unmount it.
sudo umount /tmp/ossfs2-bucket/
References
Configure ossfs 2.0.
Mount an OSS bucket to a local system using ossfs 2.0.