記一次雲主機如何掛載物件儲存

2022-05-24 15:02:39

@


前言

隨著雲端計算的發展,公有云成為中小型企業建設業務系統的首選,而物件儲存則是儲存裡面必不可少的儲存產品,物件儲存不僅可以提供海量、高可靠、安全的服務,而且價格相對普通儲存來說會便宜很多,並且不受頻寬的限制,僅限於本地下載和上傳的網速,物件儲存應用場景更適用於靜態網站託管、多媒體儲存、資料備份等等應用場景;物件儲存使用相對來說是比較簡單的我這裡就不重點說了;
為什麼會有云主機掛載物件儲存的需求呢?這個還要來源於業務系統的要求,正常來說物件儲存基本上都提供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「引數設定快取時間
2. 如果需要刪除桶中的物件,建議從系統中刪除,如果在物件儲存控制檯刪除的話,會出現所掛載的目錄中還是有這個檔案的問題

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