1. ceph對象存儲簡介
- 用戶認證信息:S3(access key, secret key), Swift(secret key)
- 訪問控制權限信息:包含操作訪問權限(read、write、delete等)和訪問控制列表ACL
- 用戶配額信息:防止某些用戶占用過多存儲空間,根據用戶付費情況配置存儲空間。
- 基礎信息:(保存在對應RADOS對象的數據部分)RGW關注的信息,包含bucket配額信息(最大對象數目或最大對象大小總和),bucket placement rule,bucket中的索引對象數目等等。
- 擴展信息:(保存在對應RADOS對象的擴展屬性)對RGW透明的一些信息,如用戶自定義的元數據信息
- rgw_max_chunk_size:分塊大小,RGW下發至RADOS集群的單個IO的大小。
- rgw_obj_stripe_size:條帶大小,multipart除首對象外的分段其他大小
- class RGWObjManifest:管理應用對象和RADOS對象的對應關系。
- 應用對象大小小於等於分塊大小:用戶上傳的一個對象只對應一個 RADOS 對象,該 RADOS 對象以應用對象名稱命名,應用對象元數據也保存在該 RADOS 對象的擴展屬性中。
- 應用對象大小大於分塊大小:應用對象被分解成一個大小等於分塊大小的首對象,多個大小等於條帶大小的中間對象,和一個大小小於等於條帶大小的尾對象。首對象以應用對象名稱命名,在 RGW 中將該對象稱為head_obj,該對象的數據部分保存了應用對象前 rgw_max_chunk_size 字節的數據,擴展屬性部分保存了應用對象的元數據信息和manifest信息。中間對象和尾對象保存應用對象剩余的數據,對象名稱為“shadow_” + “.” + “32bit 隨機字符串” + “_” + “條帶編號”,其中條帶編號從1開始。

- “_multipart_” + “用戶上傳對象名稱” + “分段上傳ID” + “分段編號”
- “_shadow_” + “用戶上傳對象名稱” + “分段上傳ID” + “分段編號” + “_” + “條帶編號”




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