ceph學習筆記


1. ceph對象存儲簡介

1.1 核心概念
用戶
對象存儲的使用者,存儲桶的擁有者
存儲桶
作為存放對象的容器
對象
用戶實際上傳的文件
1.用戶
RGW兼容AWS S3和OpenStack Swift。RGW user對應S3 user,RGW user對應Swift Account,RGW subuser對應Swift user。
用戶數據信息包含:
  • 用戶認證信息:S3(access key, secret key), Swift(secret key)
  • 訪問控制權限信息:包含操作訪問權限(read、write、delete等)和訪問控制列表ACL
  • 用戶配額信息:防止某些用戶占用過多存儲空間,根據用戶付費情況配置存儲空間。
2.存儲桶(bucket)
存儲桶是對象的容器,是為了方便管理和操作具有相同屬性的一類對象而引入的一級管理單元。
存儲桶信息包含:
  • 基礎信息:(保存在對應RADOS對象的數據部分)RGW關注的信息,包含bucket配額信息(最大對象數目或最大對象大小總和),bucket placement rule,bucket中的索引對象數目等等。
  • 擴展信息:(保存在對應RADOS對象的擴展屬性)對RGW透明的一些信息,如用戶自定義的元數據信息
對於bucket placement rule,
3.對象
RGW中的應用對象對應RADOS對象。應用對象上傳分整體上傳和分段上傳,不同的上傳方式應用對象對應RADOS對象的方式不同。
首先介紹三個概念:
  • rgw_max_chunk_size:分塊大小,RGW下發至RADOS集群的單個IO的大小。
  • rgw_obj_stripe_size:條帶大小,multipart除首對象外的分段其他大小
  • class RGWObjManifest:管理應用對象和RADOS對象的對應關系。
3.1 整體上傳
  • 應用對象大小小於等於分塊大小:用戶上傳的一個對象只對應一個 RADOS 對象,該 RADOS 對象以應用對象名稱命名,應用對象元數據也保存在該 RADOS 對象的擴展屬性中。
  • 應用對象大小大於分塊大小:應用對象被分解成一個大小等於分塊大小的首對象,多個大小等於條帶大小的中間對象,和一個大小小於等於條帶大小的尾對象。首對象以應用對象名稱命名,在 RGW 中將該對象稱為head_obj,該對象的數據部分保存了應用對象前 rgw_max_chunk_size 字節的數據,擴展屬性部分保存了應用對象的元數據信息和manifest信息。中間對象和尾對象保存應用對象剩余的數據,對象名稱為“shadow_” + “.” + “32bit 隨機字符串” + “_” + “條帶編號”,其中條帶編號從1開始。
3.2 分段上傳
RGW依照條帶大小將應用對象的每一個分段分成多個RADOS對象,每個分段的第一個 RADOS 對象名稱為:
  • “_multipart_” + “用戶上傳對象名稱” + “分段上傳ID” + “分段編號”
其余對象的名稱為:
  • “_shadow_” + “用戶上傳對象名稱” + “分段上傳ID” + “分段編號” +
 “_” + “條帶編號”
當所有的分段上傳結束后,RGW 會從 data_extra_pool 中的分段上傳臨時對象中讀取各個分段信息,主要是各分段的 manifest 信息,組成一個 manifest;然后生成一個新的 RADOS 對象,即 head obj,用來保存分段上傳的應用對象的元數據信息和各分段的manifest。
 
架構
HTTP-RGW IO路徑
RGW-RADOS IO棧
FRONTEND
l  Civetweb(可嵌入的C++實現的HTTP服務端庫)
l  Loadgen(測試專用,並不處理數據IO)
l  FCGI(作為Apache模塊,支持CGI協議)
l  其他
各個池的作用
對象存儲中,包含兩種類型的pool,一種是保存元數據的,例如.rgw.buckets.index,users.uid等,另一種是保存數據的.rgw.buckets
.rgw.root
       region和zone的信息
.rgw.control
在RGW上電時,在control pool創建若干個對象用於watch-notify,主要作用為當一個zone對應多個RGW,且cache使能時, 保證數據的一致性,其基本原理為利用librados提供的對象watch-notify功能,當有數據更新時,通知其他RGW刷新cache, 后面會有文檔專門描述RGW cache。
.rgw
       包含容器名稱,歸屬信息(項目ID+工程名稱),讀寫權限等bucket屬性信息
.rgw.gc
       RGW中大文件數據一般在后台刪除,該pool用於記錄那些待刪除的文件對象。
.users.uid
       包含用戶的ID,默認為項目ID
.users
包含用戶信息
.rgw.buckets.index
       buckets索引,格式為.dir.<region_or_zone_name>.<ID>,存儲元數據
.rgw.buckets
包括所有容器里面的對象,對象名字,ACL等信息
 
基本命令
 
查看所有用戶
radosgw-admin metadata list user
查看用戶信息
radosgw-admin user info --uid=test
創建用戶
radosgw-admin user create --uid=test --display-name=test
創建子賬號
       創建一個swift子賬號
radosgw-admin subuser create --uid=test --subuser=test:swift --access=full
查看所有桶
radosgw-admin bucket list
查看桶內對象
radosgw-admin bucket list --bucket=asdas
查看桶信息
radosgw-admin bucket stats --bucket=asdas
查看配額
radosgw-admin user info --uid=test | grep -A 4 "user_quota"

2. ceph對象存儲配置對象網關

2.1 配置RADOS網關

2.1.1 創建RGW用戶和keyring,生成keyring

[root@ceph-jewel-node1 ~]# ceph-authtool --create-keyring /etc/ceph/ceph.client.radosgw.keyring

[root@ceph-jewel-node1 ~]# chmod +x /etc/ceph/ceph.client.radosgw.keyring

2.1.2 為RGW實例生成網關用戶和秘鑰,網關的實例名稱是gateway

[root@ceph-jewel-node1 ~]# ceph-authtool /etc/ceph/ceph.client.radosgw.keyring -n client.radosgw.gateway --gen-key

2.1.3 給秘鑰添加權限

[root@ceph-jewel-node1 ~]# ceph-authtool -n client.radosgw.gateway --cap osd 'allow rwx' --cap mon 'allow rwx' /etc/ceph/ceph.client.radosgw.keyring

2.1.4 將秘鑰添加到ceph集群

[root@ceph-jewel-node1 ~]# ceph -k /etc/ceph/ceph.client.admin.keyring auth add client.radosgw.gateway -i /etc/ceph/ceph.client.radosgw.keyring

2.1.5 將秘鑰分配給ceph RGW 節點

[root@ceph-jewel-node1 ~]# scp /etc/ceph/ceph.client.radosgw.keyring  ceph-jewel-node2:/etc/ceph/

[root@ceph-jewel-node1 ~]# scp /etc/ceph/ceph.client.radosgw.keyring  ceph-jewel-node3:/etc/ceph/

2.1.6 創建對應的資源池

[root@ceph-jewel-node1 ~]# ceph osd pool create .rgw 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .rgw.root 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .rgw.control 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .rgw.gc 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .rgw.buckets 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .rgw.buckets.index 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .rgw.buckets.extra 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .log 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .intent-log 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .usage 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .users 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .users.email 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .users.swift 128 128
[root@ceph-jewel-node1 ~]# ceph osd pool create .users.uid 128 128

2.1.7 查看對應的資源池

[root@ceph-jewel-node1 ~]# rados lspools

2.1.8 檢查集群狀態

[root@ceph-jewel-node1 ~]# ceph -s

注意:使用ceph -s命令查看檢查集群健康情況,一般新建很多pool的時候集群容易出現異常,這樣即使我們后面啟動了網關,也無法使用。會報錯libcurl doesn’t support curl_multi_wait()。

2.1.9 修改配置文件

[root@ceph-jewel-node1 ~]# vim /etc/ceph/ceph.conf

[client.radosgw.gateway]
rgw frontends=fastcgi socket_port=9000 socket_host=0.0.0.0
host=ceph-jewel-node1
keyring=/etc/ceph/ceph.client.radosgw.keyring
log file=/var/log/radosgw/client.radosgw.gateway.log
rgw socket path=/var/run/ceph/ceph.radosgw.gateway.fastcgi.sock
rgw print continue=false
rgw content length compat = true

[root@ceph-jewel-node1 ~]# mkdir -p /var/log/radosgw
[root@ceph-jewel-node1 ~]# chown 777 /var/log/radosgw
[root@ceph-jewel-node1 ~]# chown 777 /var/run/ceph

2.1.10 分配配置文件

[root@ceph-jewel-node1 ~]# cd /opt/ceph-cluster/
[root@ceph-jewel-node1 ceph-cluster]# ceph-deploy --overwrite-conf config push ceph-jewel-node1 ceph-jewel-node2 ceph-jewel-node3

2.1.11 創建對象

[root@ceph-jewel-node1 ceph-cluster]# ceph-deploy --overwrite-conf rgw create ceph-jewel-node1

2.1.12 重啟服務

查看radosgw服務狀態:

ps -ef | grep radosgw
sudo systemctl status ceph-radosgw.service #centos7
重啟RGW使用命令

sudo systemctl restart ceph-radosgw.service #centos7

如果報錯ibcurl doesn’t support curl_multi_wait()說明沒有權限認證或者需要的資源池沒有創建好。

[zzq@localhost myceph]$ sudo service ceph-radosgw restart
Starting client.rgw.admin... [FAILED]
/usr/bin/dirname: extra operand `-n'
Try `/usr/bin/dirname --help' for more information.
2018-05-27 18:07:21.747065 7ff716144820 -1 WARNING: libcurl doesn't support curl_multi_wait()
2018-05-27 18:07:21.747066 7ff716144820 -1 WARNING: cross zone / region transfer performance may be affected

2.1.13 測試

[root@ceph-jewel-node1 ceph-cluster]# curl http://ceph-jewel-node1:7480
<?xml version="1.0" encoding="UTF-8"?><ListAllMyBucketsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Owner><ID>anonymous</ID><DisplayName></DisplayName></Owner><Buckets></Buckets></ListAllMyBucketsResult>

2.2 創建對象網關用戶

2.2.1 測試訪問集群

[root@ceph-jewel-node1 ceph-cluster]# ceph -s -k /etc/ceph/ceph.client.radosgw.keyring --name client.radosgw.gateway

2.2.2 創建對象網關用戶

[root@ceph-jewel-node1 ceph-cluster]# radosgw-admin user create --uid="rgwuser" --display-name="This is firstt user"

[root@ceph-jewel-node1 ceph-cluster]# radosgw-admin subuser create --uid=rgwuser --subuser=rgwuser:swift --access=full

2.3 測試S3訪問

[root@ceph-jewel-node1 ceph-cluster]# yum -y install python-boto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@ceph - jewel - node1 ceph - cluster] # cat s3.py
import boto
import boto.s3.connection
access_key = '9AU33Z0DM35P1VHG8EIL'
secret_key = 'nRqVeHPWAo9b2p9UqZ1olu2anDsXSTnU9Ao886Zp'
conn = boto.connect_s3(
     aws_access_key_id = access_key,
     aws_secret_access_key = secret_key,
     host = 'admin' , port = 7480 ,
     is_secure = False ,
     calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)
bucket = conn.create_bucket( 'my-first-s3-bucket' )
for bucket in conn.get_all_buckets():
         print "{name}\t{created}" . format (
                 name = bucket.name,
                 created = bucket.creation_date,
)

[root@ceph-jewel-node1 ceph-cluster]# python s3.py

2.4 s3cmd方法測試s3

[root@ceph-jewel-node1 ceph-cluster]# yum -y install s3cmd

[root@ceph-jewel-node1 ceph-cluster]# s3cmd --configure

[root@ceph-jewel-node1 ~]# cat /root/.s3cfg
[default]
access_key = 9AU33Z0DM35P1VHG8EIL
secret_key = nRqVeHPWAo9b2p9UqZ1olu2anDsXSTnU9Ao886Zp
host_base = http://192.168.101.205:7480
host_bucket = 192.168.101.205/my-first-s3-bucket
use_https = False

2、列舉所有 Buckets。(bucket 相當於根文件夾)

1
s3cmd ls

3、創建 bucket,且 bucket 名稱是唯一的,不能重復。

1
s3cmd mb s3://my-bucket-name

4、刪除空 bucket

1
s3cmd rb s3://my-bucket-name

5、列舉 Bucket 中的內容

1
s3cmd ls s3://my-bucket-name

6、上傳 file.txt 到某個 bucket,

1
s3cmd put file.txt s3://my-bucket-name/file.txt

7、上傳並將權限設置為所有人可讀

1
s3cmd put --acl-public file.txt s3://my-bucket-name/file.txt

8、批量上傳文件

1
s3cmd put ./* s3://my-bucket-name/

9、下載文件

1
s3cmd get s3://my-bucket-name/file.txt file.txt

10、批量下載

1
s3cmd get s3://my-bucket-name/* ./

11、刪除文件

1
s3cmd del s3://my-bucket-name/file.txt

12、來獲得對應的bucket所占用的空間大小

1
s3cmd du -H s3://my-bucket-name

以下命令都能將dir1 中的文件上傳至my-bucket-name,但效果只截然不同的。

1)dir1 不帶"/"斜杠,那么dir1會作為文件路徑的一部分,相當於上傳整個dir1目錄,即類似 "cp -r dir1/"

1
2
~/demo$ s3cmd put -r dir1 s3://my-bucket-name/
dir1/file1-1.txt -> s3://my-bucket-name/dir1/file1-1.txt  [1 of 1]

2)帶"/"斜杠的 dir1,相當於上傳dir1目錄下的所有文件,即類似 "cp ./* "

1
2
~/demo$ s3cmd put -r dir1/ s3://my-bucket-name/
dir1/file1-1.txt -> s3://my-bucket-name/file1-1.txt  [1 of 1]

這是s3cmd 使用難點,但卻是最實用的功能。官方使用說明見《s3cmd sync HowTo》

首先明確,同步操作是要進行MD5校驗的,只有當文件不同時,才會被傳輸。

1、同步當前目錄下所有文件

1
s3cmd sync  ./  s3://my-bucket-name/

2、加 "--dry-run"參數后,僅列出需要同步的項目,不實際進行同步。

1
s3cmd sync  --dry-run ./  s3://my-bucket-name/

3、加 " --delete-removed"參數后,會刪除本地不存在的文件。

1
s3cmd sync  --delete-removed ./  s3://my-bucket-name/

4、加 " --skip-existing"參數后,不進行MD5校驗,直接跳過本地已存在的文件。

1
s3cmd sync  --skip-existing ./  s3://my-bucket-name/

4.2.1、排除、包含規則(--exclude 、--include)

file1-1.txt被排除,file2-2.txt同樣是txt格式卻能被包含。

1
2
3
~/demo$ s3cmd sync --dry-run --exclude '*.txt' --include 'dir2/*' ./  s3://my-bucket-name/
exclude: dir1/file1-1.txt
upload: ./dir2/file2-2.txt -> s3://my-bucket-name/dir2/file2-2.txt

4.2.2、從文件中載入排除或包含規則。(--exclude-from、--include-from)

1
s3cmd sync  --exclude-from pictures.exclude ./  s3://my-bucket-name/

pictures.exclude 文件內容

1
2
3
# Hey, comments are allowed here ;-)
*.jpg
*.gif

4.2.3、排除或包含規則支持正則表達式

1
--rexclude 、--rinclude、--rexclude-from、--rinclude-from

2.5 swift API訪問ceph對象存儲

[root@ceph-jewel-node1 ~]# yum install python-setuptools

[root@ceph-jewel-node1 ~]# easy_install pip

[root@ceph-jewel-node1 ~]# pip install --upgrade setuptools

[root@ceph-jewel-node1 ~]# pip install --upgrade python-swiftclient

 

[root@ceph-jewel-node1 ~]# radosgw-admin user info --uid rgwuser    #獲取子用戶和秘鑰

[root@ceph-jewel-node1 ~]# swift -A http://192.168.101.205:7480/auth/1.0 -U rgwuser:swift -K IAU7Jt0Jv7o2L0RjtT8305AIiyUaz1RTTqKWsqfO list
my-first-s3-bucket
my-second-s3-bucket

[root@ceph-jewel-node1 ~]# swift -A http://192.168.101.205:7480/auth/1.0 -U rgwuser:swift -K IAU7Jt0Jv7o2L0RjtT8305AIiyUaz1RTTqKWsqfO post my-third-s3-bucket
[root@ceph-jewel-node1 ~]# swift -A http://192.168.101.205:7480/auth/1.0 -U rgwuser:swift -K IAU7Jt0Jv7o2L0RjtT8305AIiyUaz1RTTqKWsqfO list
my-first-s3-bucket
my-second-s3-bucket
my-third-s3-bucket

 

source:https://www.cnblogs.com/qiyedetonghua/articles/11060460.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM