Mounting COS to Tencent Cloud Server Using COS-Fuse Tool

Publish: 2017-05-05 | Modify: 2017-05-05

COS is an object storage service provided by Tencent Cloud. COS-Fuse allows you to mount COS to the local file system in Linux system, so that you can conveniently operate objects on COS through the local file system and achieve data sharing. The effect is the same as the article "Mounting Alibaba Cloud OSS to ECS with OSSFS on CentOS 6" shared before. This article uses CentOS 7 as an example.

COS

一、Install Dependencies

Please run the following command to install the required dependencies:

sudo yum -y install automake gcc-c++ git libcurl-devel libxml2-devel fuse-devel make openssl-devel

二、Compile and Install

# Download COS-Fuse
wget https://mc.qcloudimg.com/static/archive/144302cd3e6afb2bf2758a8c0c1d9bb9/cosfs-v4.2.1-master.zip
# Unzip
tar -zxvf cosfs-v4.2.1-master.zip
# Rename
mv cosfs-v4.2.1-master cosfs
# Compile and install
cd cosfs
./autogen.sh
./configure
make
sudo make install

三、Configure and Run

In Tencent Cloud Console - Cloud Products - Storage and CDN - Object Storage Service, create a bucket and record the bucket name and region. They will be used later.

Create Bucket

In Object Storage Service - Key Management, record your APPID, SecretId, and SecretKey. Or you can directly visit Key Management (login required) to view the keys.

View Keys

Use the following command to save the bucket, SecretId, and SecretKey to the /etc/passwd-cosfs file:

echo my-bucket:my-access-key-id:my-access-key-secret > /etc/passwd-cosfs
chmod 640 /etc/passwd-cosfs

Mount COS

Use the following command to mount COS to the server. There are 4 parameters in the command, explained below.

# Create mount directory
mkdir -p /home/cosfs
# Mount
cosfs my-appid:my-bucket my-mount-point -ourl=my-cos-endpoint
  • my-appid: Corresponds to APPID, please refer to Figure 3-2.
  • my-bucket: The bucket name, as shown in Figure 3-1.
  • my-mount-point: The directory to be mounted, such as /home/cosfs.
  • -ourl: It is the endpoint of COS, http://cn-south.myqcloud.com corresponds to South China Guangzhou region, cn-south corresponds to North China Tianjin region, cn-east corresponds to East China Shanghai region. Please modify it according to the region where the bucket is located.

The following is the demonstration code:

echo my-bucket:faint:123 > /etc/passwd-cosfs
chmod 640 /etc/passwd-cosfs
mkdir -p /home/cosfs
cosfs appid:my-bucket mkdir -p /home/cosfs -ourl=http://cn-south.myqcloud.com

Test

Use df -h to check if the mounting is successful. If it shows the following result, it means it is OK.

Mounting Result

Summary

COS intranet traffic is free. Mounting COS for backup is a good solution. However, if you plan to store website programs or frequently read/write files, it may not be the best solution.

This article refers to the official documentation: COS-Fuse Tool


Comments