记一次云主机如何挂载对象存储

时间:2022-12-23 11:05:17

@TOC



前言


随着云计算的发展,公有云成为中小型企业建设业务系统的首选,而对象存储则是存储里面必不可少的存储产品,对象存储不仅可以提供海量、高可靠、安全的服务,而且价格相对普通存储来说会便宜很多,并且不受带宽的限制,仅限于本地下载和上传的网速,对象存储应用场景更适用于静态网站托管、多媒体存储、数据备份等等应用场景;对象存储使用相对来说是比较简单的我这里就不重点说了;

为什么会有云主机挂载对象存储的需求呢?这个还要来源于业务系统的要求,正常来说对象存储基本上都提供S3的一个接口提供上传下载,更是各大云厂商都提供S3的工具,华为云的OBS Browser+以及移动云的S3 Browser等等,不过这些工具无法实现自动化的操作,你想自动化操作有两种方式一种是直接程序调用对象存储的S3接口,另一个方法就说直接将对象存储挂载为本地文件夹或映射为磁盘的方式进行操作,接下来我要说的就是如何将对象存储挂载到云主机,这次采用的是RCLONE这个管理工具,下面使用linux系统进行演示,windows其实和linux操作步骤几乎一致,不过参数可能多少有点不一样,后面也把windows的简单教程放到了最后。



一、RCLONE是什么?


Rclone是一款免费的云存储管理工具,能够像使用本地文件一样便捷的使用云存储,被誉为“云存储界的瑞士军刀”。

您可以使用Rclone工具,对对象存储进行数据导入、数据同步、迁移备份或者挂载等操作。

通过使用Rclone,您可以轻松的完成以下工作:

名称

概述


| 数据导入 | 支持将存放在其它数据源上的数据导入到对象存储 |

|数据同步|支持在对象存储不同的桶之间,或者对象存储和其它数据源之间进行数据同步|

|数据迁移备份|支持在对象存储不同的桶之间进行数据迁移、备份操作|

|挂载到本地磁盘| 支持将对象存储挂载为本地磁盘,像操作本地文件一样,对云存储的数据进行操作|

二、操作步骤


1.下载和安装


下载链接:https://download.csdn.net/download/KH_FC/85448323


2.配置对象存储数据源


windows打开CMD程序执行窗口,输入rclone config命令执行

linux系统直接输入rclone config命令执行

执行后屏幕将显示如下的配置向导菜单,如果已有配置编辑输入“e”,如无配置新建配置输入“n”即可;我这里新建配置


No remotes found - make a new one

n) New remote

s) Set configuration password

q) Quit config

n/s/q> n

输入自定义的连接配置的别名后回车,此处以”test“为例:


name> EOS


选择存储类型,输入”s3“后回车:


Option Storage.

Type of storage to configure.

Choose a number from below, or type in your own value.

1 / 1Fichier

\ (fichier)

2 / Akamai NetStorage

\ (netstorage)

3 / Alias for an existing remote

\ (alias)

4 / Amazon Drive

\ (amazon cloud drive)

5 / Amazon S3 Compliant Storage Providers including AWS, Alibaba, Ceph, ChinaMobile, Digital Ocean, Dreamhost, IBM COS, Lyve Cloud, Minio, RackCorp, SeaweedFS, and Tencent COS

\ (s3)

6 / Backblaze B2

\ (b2)

7 / Better checksums for other remotes

\ (hasher)

8 / Box

\ (box)

9 / Cache a remote

\ (cache)

10 / Citrix Sharefile

\ (sharefile)

11 / Compress a remote

\ (compress)

12 / Dropbox

\ (dropbox)

13 / Encrypt/Decrypt a remote

\ (crypt)

14 / Enterprise File Fabric

\ (filefabric)

15 / FTP Connection

\ (ftp)

16 / Google Cloud Storage (this is not Google Drive)

\ (google cloud storage)

17 / Google Drive

\ (drive)

18 / Google Photos

\ (google photos)

19 / Hadoop distributed file system

\ (hdfs)

20 / Hubic

\ (hubic)

21 / In memory object storage system.

\ (memory)

22 / Jottacloud

\ (jottacloud)

23 / Koofr, Digi Storage and other Koofr-compatible storage providers

\ (koofr)

24 / Local Disk

\ (local)

25 / Mail.ru Cloud

\ (mailru)

26 / Mega

\ (mega)

27 / Microsoft Azure Blob Storage

\ (azureblob)

28 / Microsoft OneDrive

\ (onedrive)

29 / OpenDrive

\ (opendrive)

30 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)

\ (swift)

31 / Pcloud

\ (pcloud)

32 / Put.io

\ (putio)

33 / QingCloud Object Storage

\ (qingstor)

34 / SSH/SFTP Connection

\ (sftp)

35 / Sia Decentralized Cloud

\ (sia)

36 / Storj Decentralized Cloud Storage

\ (storj)

37 / Sugarsync

\ (sugarsync)

38 / Transparently chunk/split large files

\ (chunker)

39 / Union merges the contents of several upstream fs

\ (union)

40 / Uptobox

\ (uptobox)

41 / Webdav

\ (webdav)

42 / Yandex Disk

\ (yandex)

43 / Zoho

\ (zoho)

44 / http Connection

\ (http)

45 / premiumize.me

\ (premiumizeme)

46 / seafile

\ (seafile)

Storage> s3

选择服务提供商,这个选择自己的对象存储云厂商即可,我这里采用的移动云的对象存储,所以选用”ChinaMobile“即可,输入”ChinaMobile“后回车:

Option provider.

Choose your S3 provider.

Choose a number from below, or type in your own value.

Press Enter to leave empty.

1 / Amazon Web Services (AWS) S3

\ (AWS)

2 / Alibaba Cloud Object Storage System (OSS) formerly Aliyun

\ (Alibaba)

3 / Ceph Object Storage

\ (Ceph)

4 / China Mobile Ecloud Elastic Object Storage (EOS)

\ (ChinaMobile)

5 / Digital Ocean Spaces

\ (DigitalOcean)

6 / Dreamhost DreamObjects

\ (Dreamhost)

7 / IBM COS S3

\ (IBMCOS)

8 / Seagate Lyve Cloud

\ (LyveCloud)

9 / Minio Object Storage

\ (Minio)

10 / Netease Object Storage (NOS)

\ (Netease)

11 / RackCorp Object Storage

\ (RackCorp)

12 / Scaleway Object Storage

\ (Scaleway)

13 / SeaweedFS S3

\ (SeaweedFS)

14 / StackPath Object Storage

\ (StackPath)

15 / Storj (S3 Compatible Gateway)

\ (Storj)

16 / Tencent Cloud Object Storage (COS)

\ (TencentCOS)

17 / Wasabi Object Storage

\ (Wasabi)

18 / Any other S3 compatible provider

\ (Other)

provider> ChinaMobile

选择是否开启验证,输入”false“后回车:


Option env_auth.

Get AWS credentials from runtime (environment variables or EC2/ECS meta data if no env vars).

Only applies if access_key_id and secret_access_key is blank.

Choose a number from below, or type in your own boolean value (true or false).

Press Enter for the default (false).

1 / Enter AWS credentials in the next step.

\ (false)

2 / Get AWS credentials from the environment (env vars or IAM).

\ (true)

env_auth> false

输入用户API认证信息中的AccessID,不同云厂商叫法不同华为云上面是使用AK/SK,其实就是名字不同而已其实都是一样:

Option access_key_id.

AWS Access Key ID.

Leave blank for anonymous access or runtime credentials.

Enter a value. Press Enter to leave empty.

access_key_id> AccessID

输入用户API认证信息中的AccessSecretKey,这里就是指的AK/SK,这个是成对出现的:

Option secret_access_key.

AWS Secret Access Key (password).

Leave blank for anonymous access or runtime credentials.

Enter a value. Press Enter to leave empty.

secret_access_key> AccessSecretKey

选择对象存储服务接口地址,这个接口地址是指的云厂商所提供的对象存储接口地址,这个云厂商一般按照资源池来定的,输入对应的数字后回车即可,我这里是移动云的,选择不同的就会出现不同的地址:

Option endpoint.

Endpoint for China Mobile Ecloud Elastic Object Storage (EOS) API.

Choose a number from below, or type in your own value.

Press Enter to leave empty.

/ The default endpoint - a good choice if you are unsure.

1 | East China (Suzhou)

\ (eos-wuxi-1.cmecloud.cn)

2 / East China (Jinan)

\ (eos-jinan-1.cmecloud.cn)

3 / East China (Hangzhou)

\ (eos-ningbo-1.cmecloud.cn)

4 / East China (Shanghai-1)

\ (eos-shanghai-1.cmecloud.cn)

5 / Central China (Zhengzhou)

\ (eos-zhengzhou-1.cmecloud.cn)

6 / Central China (Changsha-1)

\ (eos-hunan-1.cmecloud.cn)

7 / Central China (Changsha-2)

\ (eos-zhuzhou-1.cmecloud.cn)

8 / South China (Guangzhou-2)

\ (eos-guangzhou-1.cmecloud.cn)

9 / South China (Guangzhou-3)

\ (eos-dongguan-1.cmecloud.cn)

10 / North China (Beijing-1)

\ (eos-beijing-1.cmecloud.cn)

11 / North China (Beijing-2)

\ (eos-beijing-2.cmecloud.cn)

12 / North China (Beijing-3)

\ (eos-beijing-4.cmecloud.cn)

13 / North China (Huhehaote)

\ (eos-huhehaote-1.cmecloud.cn)

14 / Southwest China (Chengdu)

\ (eos-chengdu-1.cmecloud.cn)

15 / Southwest China (Chongqing)

\ (eos-chongqing-1.cmecloud.cn)

16 / Southwest China (Guiyang)

\ (eos-guiyang-1.cmecloud.cn)

17 / Nouthwest China (Xian)

\ (eos-xian-1.cmecloud.cn)

18 / Yunnan China (Kunming)

\ (eos-yunnan.cmecloud.cn)

19 / Yunnan China (Kunming-2)

\ (eos-yunnan-2.cmecloud.cn)

20 / Tianjin China (Tianjin)

\ (eos-tianjin-1.cmecloud.cn)

21 / Jilin China (Changchun)

\ (eos-jilin-1.cmecloud.cn)

22 / Hubei China (Xiangyan)

\ (eos-hubei-1.cmecloud.cn)

23 / Jiangxi China (Nanchang)

\ (eos-jiangxi-1.cmecloud.cn)

24 / Gansu China (Lanzhou)

\ (eos-gansu-1.cmecloud.cn)

25 / Shanxi China (Taiyuan)

\ (eos-shanxi-1.cmecloud.cn)

26 / Liaoning China (Shenyang)

\ (eos-liaoning-1.cmecloud.cn)

27 / Hebei China (Shijiazhuang)

\ (eos-hebei-1.cmecloud.cn)

28 / Fujian China (Xiamen)

\ (eos-fujian-1.cmecloud.cn)

29 / Guangxi China (Nanning)

\ (eos-guangxi-1.cmecloud.cn)

30 / Anhui China (Huainan)

\ (eos-anhui-1.cmecloud.cn)

endpoint> 1

选择”location_constraint“,需要与之前的对象存储服务接口地址保持一致,一般这里让你选择你对象存储所存在的资源池,输入对应的数字后回车:


Option location_constraint.

Location constraint - must match endpoint.

Used when creating buckets only.

Choose a number from below, or type in your own value.

Press Enter to leave empty.

1 / East China (Suzhou)

\ (wuxi1)

2 / East China (Jinan)

\ (jinan1)

3 / East China (Hangzhou)

\ (ningbo1)

4 / East China (Shanghai-1)

\ (shanghai1)

5 / Central China (Zhengzhou)

\ (zhengzhou1)

6 / Central China (Changsha-1)

\ (hunan1)

7 / Central China (Changsha-2)

\ (zhuzhou1)

8 / South China (Guangzhou-2)

\ (guangzhou1)

9 / South China (Guangzhou-3)

\ (dongguan1)

10 / North China (Beijing-1)

\ (beijing1)

11 / North China (Beijing-2)

\ (beijing2)

12 / North China (Beijing-3)

\ (beijing4)

13 / North China (Huhehaote)

\ (huhehaote1)

14 / Southwest China (Chengdu)

\ (chengdu1)

15 / Southwest China (Chongqing)

\ (chongqing1)

16 / Southwest China (Guiyang)

\ (guiyang1)

17 / Nouthwest China (Xian)

\ (xian1)

18 / Yunnan China (Kunming)

\ (yunnan)

19 / Yunnan China (Kunming-2)

\ (yunnan2)

20 / Tianjin China (Tianjin)

\ (tianjin1)

21 / Jilin China (Changchun)

\ (jilin1)

22 / Hubei China (Xiangyan)

\ (hubei1)

23 / Jiangxi China (Nanchang)

\ (jiangxi1)

24 / Gansu China (Lanzhou)

\ (gansu1)

25 / Shanxi China (Taiyuan)

\ (shanxi1)

26 / Liaoning China (Shenyang)

\ (liaoning1)

27 / Hebei China (Shijiazhuang)

\ (hebei1)

28 / Fujian China (Xiamen)

\ (fujian1)

29 / Guangxi China (Nanning)

\ (guangxi1)

30 / Anhui China (Huainan)

\ (anhui1)

location_constraint> 1

输入默认权限,一般设置成公共可读写即可:


Option acl.

Canned ACL used when creating buckets and storing or copying objects.

This ACL is used for creating objects and if bucket_acl isn't set, for creating buckets too.

For more info visit https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl

Note that this ACL is applied when server-side copying objects as S3

doesn't copy the ACL from the source but rather writes a fresh one.

Choose a number from below, or type in your own value.

Press Enter to leave empty.

/ Owner gets FULL_CONTROL.

1 | No one else has access rights (default).

\ (private)

/ Owner gets FULL_CONTROL.

2 | The AllUsers group gets READ access.

\ (public-read)

/ Owner gets FULL_CONTROL.

3 | The AllUsers group gets READ and WRITE access.

| Granting this on a bucket is generally not recommended.

\ (public-read-write)

/ Owner gets FULL_CONTROL.

4 | The AuthenticatedUsers group gets READ access.

\ (authenticated-read)

acl> public-read-write

选择服务端加密方式,不使用该功能时直接回车:

Option server_side_encryption.

The server-side encryption algorithm used when storing this object in S3.

Choose a number from below, or type in your own value.

Press Enter to leave empty.

1 / None

\ ()

2 / AES256

\ (AES256)

server_side_encryption>

选择上传对象的默认存储类型,不选择时默认使用桶的存储类型:


Option storage_class.

The storage class to use when storing new objects in ChinaMobile.

Choose a number from below, or type in your own value.

Press Enter to leave empty.

1 / Default

\ ()

2 / Standard storage class

\ (STANDARD)

3 / Archive storage mode

\ (GLACIER)

4 / Infrequent access storage mode

\ (STANDARD_IA)

storage_class>

选择是否设置进阶配置,这里不设置,直接回车:


Edit advanced config?

y) Yes

n) No (default)

y/n>

确认刚才配置的连接信息,确认无误后输入”y“后回车,保存配置:

--------------------

[EOS]

type = s3

provider = ChinaMobile

access_key_id = AccessID

secret_access_key = AccessSecretKey

endpoint = eos-wuxi-1.cmecloud.cn

location_constraint = wuxi1

acl = private

--------------------

y) Yes this is OK (default)

e) Edit this remote

d) Delete this remote

y/e/d> y

此时回到了配置向导的初始菜单,刚才的配置会显示出来,可继续执行创建新的配置(输入“n”)、编辑已有的配置(输入“e”)、删除配置(输入“d”)等操作,或者完成配置向导退出(输入“q”):

Current remotes:

Name Type

====

EOS s3


e) Edit existing remote

n) New remote

d) Delete remote

r) Rename remote

c) Copy remote

s) Set configuration password

q) Quit config

e/n/d/r/c/s/q>

到这里配置文件配置已经完成了。



3.挂载到操作系统


3.1.挂载到windows操作系统


安装依赖软件:WINFSP

下载地址:https://ecloud.10086.cn/op-help-center/doc/article/resource/file/ced6e21813cf60f2828cfc1eb0f5993325f4da56564b5afd1fdfa244830573db

下载好后直接双运行即可,安装也是按照默认的选项走就可以的

记一次云主机如何挂载对象存储

记一次云主机如何挂载对象存储

记一次云主机如何挂载对象存储

记一次云主机如何挂载对象存储

记一次云主机如何挂载对象存储

一步步安装完成即可;

下面就是挂载对象存储了,挂载也比较简单一条命令搞定

rclone mount 配置文件名称:桶名称 挂载路径  --cache-dir 缓存路径 --vfs-cache-mode writes


输入敲回车即可,你会发现对象存储已经挂载到了你想要的挂载目录上面了,这样就可以上传下载文件了

3.2.挂载到linux操作系统


安装依赖软件:FUSE

centos安装:

yum -y install fuse


ubuntu安装:

apt -y insyall fuse


等待安装完成即可,下面就是挂载对象存储了

# 创建挂载路径
mkdir -p 挂载目录
rclone mount 配置文件名称:桶名称 挂载路径 --daemon --allow-other --cache-dir 缓存路径 --vfs-cache-mode writes


执行即可

注意事项


  1. 要注意缓存可能会和你上传文件的大小一样,默认缓存保存时间为1小时,如果需要设置缓存时间你可以加”--vfs-cache-max-age“参数设置缓存时间
  1. 果需要删除桶中的对象,建议从系统中删除,如果在对象存储控制台删除的话,会出现所挂载的目录中还是有这个文件的问题

CSDN地址:​​https://blog.csdn.net/KH_FC/article/details/124915989​