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.
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
# 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
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.
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.
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
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
Use df -h
to check if the mounting is successful. If it shows the following result, it means it is OK.
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
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.