七、Ceph之物件儲存RadosGW使用
1、RadosGW物件儲存說明
RadosGW 是物件儲存(OSS,Object Storage Service)的一種實現方式,RADOS 閘道器也稱為Ceph物件閘道器、RADOSGW、RGW,是一種服務,使客戶端能夠利用標準物件儲存API 來訪問Ceph叢集,它支援AWS S3 和Swift API,rgw 運行於librados 之上,在ceph 0.8 版本之後使用Civetweb的web 伺服器來響應api 請求,可以使用nginx 或或者apache 替代,客戶端基於http/https協議通過RESTful API 與rgw 通訊,而rgw 則使用librados 與ceph 叢集通訊,rgw 客戶端通過s3 或者swift api 使用rgw 使用者進行身份驗證,然後rgw 閘道器代表使用者利用cephx 與ceph儲存進行身份驗證。
S3 由Amazon 於2006 年推出,全稱為Simple Storage Service,S3 定義了物件儲存,是物件儲存事實上的標準,從某種意義上說,S3 就是物件儲存,物件儲存就是S3,它物件儲存市場的霸主,後續的物件儲存都是對S3 的模仿。
1)通過物件儲存將資料儲存為物件,每個物件除了包含資料,還包含資料自身的元資料。 2)物件通過Object ID 來檢索,無法通過普通檔案系統的方式通過檔案路徑及檔名稱操作來直接訪問物件,只能通過API 來訪問,或者第三方客戶端(實際上也是對API 的封裝)。 3)物件儲存中的物件不整理到目錄樹中,而是儲存在扁平的名稱空間中,Amazon S3 將這個扁平名稱空間稱為bucket,而swift 則將其稱為容器。 4)無論是bucket 還是容器,都不能巢狀。 5)bucket 需要被授權才能訪問到,一個帳戶可以對多個bucket 授權,而許可權可以不同。 6)方便橫向擴充套件、快速檢索資料。 7)不支援客戶端掛載,且需要客戶端在訪問的時候指定檔名稱。 8)不是很適用於檔案過於頻繁修改及刪除的場景。
ceph 使用bucket 作為儲存桶(儲存空間),實現物件資料的儲存和多使用者隔離,資料儲存在bucket 中,使用者的許可權也是針對bucket 進行授權,可以設定使用者對不同的bucket 擁有不通的許可權,以實現許可權管理
bucket 特性:
1)儲存空間是您用於儲存物件(Object)的容器,所有的物件都必須隸屬於某個儲存空間,可以設定和修改儲存空間屬性用來控制地域、訪問許可權、生命週期等,這些屬性設定直接作用於該儲存空間內所有物件,因此您可以通過靈活建立不同的儲存空間來完成不同的管理功能。 2)同一個儲存空間的內部是扁平的,沒有檔案系統的目錄等概念,所有的物件都直接隸屬於其對應的儲存空間。 3)每個使用者可以擁有多個儲存空間 4)儲存空間的名稱在OSS 範圍內必須是全域性唯一的,一旦建立之後無法修改名稱。 5)儲存空間內部的物件數目沒有限制。
bucket 命名規範:
1)只能包括小寫字母、數字和短橫線(-)。 2)必須以小寫字母或者數字開頭和結尾。 3)長度必須在3-63 位元組之間
Radosgw的架構圖
Radosgw的邏輯圖
1)Amazon S3:提供了user、bucket 和object 分別表示使用者、儲存桶和物件,其中bucket 隸屬於user,可以針對user 設定不同bucket 的名稱空間的訪問許可權,而且不同使用者允許訪問相同的bucket。 2)OpenStack Swift:提供了user、container 和object 分別對應於使用者、儲存桶和物件,不過它還額外為user 提供了父級元件account,用於表示一個專案或租戶,因此一個account 中可包含一到多個user,它們可共享使用同一組container,併為container 提供名稱空間。 3)RadosGW:提供了user、subuser、bucket 和object,其中的user 對應於S3 的user,而subuser則對應於Swift 的user,不過user 和subuser 都不支援為bucket 提供名稱空間,因此,不同使用者的儲存桶也不允許同名;不過,自Jewel 版本起,RadosGW 引入了tenant(租戶)用於為user 和bucket 提供名稱空間,但它是個可選元件,RadosGW 基於ACL 為不同的使用者設定不同的許可權控制,如: Read 讀加執行許可權 Write 寫許可權 Readwrite 只讀 full-control 全部控制權限
radosgw是部署在ceph-mgr1和ceph-mgr2上
4.2自定義radosgw的埠
配置檔案可以在ceph deploy 伺服器修改然後統一推送,或者單獨修改每個radosgw 伺服器的配置為同一配置。
修改預設埠7480為8080埠,在ceph-deploy上配置,並推送個其它所有節點。
ceph-deploy上修改ceph.conf檔案
[global] fsid = d1f2683e-ac8d-4a02-8b94-9f7517d32c50 public_network = 192.168.1.0/24 cluster_network = 192.168.88.0/24 mon_initial_members = ceph-mon1 mon_host = 192.168.1.203 auth_cluster_required = cephx auth_service_required = cephx auth_client_required = cephx #增加以下內容,client.rgw後面為主機名 [client.rgw.ceph-rgw2] rgw_host = ceph-rgw2 rgw_frontends = civetweb port=8080 [client.rgw.ceph-rgw1] rgw_host = ceph-rgw1 rgw_frontends = civetweb port=8080
將配置檔案推送到叢集其它節點中
# 推送完成之後,所有節點的/etc/ceph/ceph.conf配置檔案將和上面一致 cephadmin@ceph-deploy:~/ceph-cluster$ ceph-deploy --overwrite-conf config push ceph-mgr{1..2} cephadmin@ceph-deploy:~/ceph-cluster$ ceph-deploy --overwrite-conf config push ceph-mon{1..3} cephadmin@ceph-deploy:~/ceph-cluster$ ceph-deploy --overwrite-conf config push ceph-node{1..4}
重啟前檢視radosgw的埠為7480
root@ceph-mgr2:~# ss -antlp|grep 7480 LISTEN 0 128 0.0.0.0:7480 0.0.0.0:* users:(("radosgw",pid=13832,fd=74)) LISTEN 0 128 [::]:7480 [::]:* users:(("radosgw",pid=13832,fd=75))
重啟radosgw服務
root@ceph-mgr1:~# ps -ef|grep radosgw ceph 13551 1 0 15:19 ? 00:00:58 /usr/bin/radosgw -f --cluster ceph --name client.rgw.ceph-rgw1 --setuser ceph --setgroup ceph root@ceph-mgr2:~# ps -ef|grep radosgw ceph 13832 1 0 15:19 ? 00:00:55 /usr/bin/radosgw -f --cluster ceph --name client.rgw.ceph-rgw2 --setuser ceph --setgroup ceph root@ceph-mgr1:~# systemctl restart [email protected] root@ceph-mgr2:~# systemctl restart [email protected] #檢視radosgw的埠該為了8080 root@ceph-mgr2:~# ss -antlp|grep 8080 LISTEN 0 128 0.0.0.0:8080 0.0.0.0:* users:(("radosgw",pid=15954,fd=69))
驗證
cephadmin@ceph-deploy:~/ceph-cluster$ curl 192.168.1.201:8080 <?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> cephadmin@ceph-deploy:~/ceph-cluster$ curl 192.168.1.201:8080 <?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>
4.3 啟用radosgw的ssl配置
僅在ceph-mgr1上配置
在ceph-mgr1上配置自簽名證書
root@ceph-mgr1:/etc/ceph/certs# openssl genrsa -out civetweb.key 2048 Generating RSA private key, 2048 bit long modulus (2 primes) .........+++++ ............+++++ e is 65537 (0x010001) root@ceph-mgr1:/etc/ceph/certs# openssl req -new -x509 -key civetweb.key -out civetweb.crt -subj "/CN=rgw.zhrx.com" Can't load /root/.rnd into RNG 140555313983936:error:2406F079:random number generator:RAND_load_file:Cannot open file:../crypto/rand/randfile.c:88:Filename=/root/.rnd root@ceph-mgr1:/etc/ceph/certs# cat civetweb.key civetweb.crt > civetweb.pem root@ceph-mgr1:/etc/ceph/certs# tree . ├── civetweb.crt ├── civetweb.key └── civetweb.pem 0 directories, 3 files
注意:在生產案例中ceph-mgr1和ceph-mgr2都要配置,並且所有節點的ceph.conf的配置檔案都必須一樣
root@ceph-mgr1:/etc/ceph/certs# vim /etc/ceph/ceph.conf [global] fsid = d1f2683e-ac8d-4a02-8b94-9f7517d32c50 public_network = 192.168.1.0/24 cluster_network = 192.168.88.0/24 mon_initial_members = ceph-mon1 mon_host = 192.168.1.203 auth_cluster_required = cephx auth_service_required = cephx auth_client_required = cephx #增加以下內容,client.rgw後面為主機名 [client.rgw.ceph-rgw2] rgw_host = ceph-rgw2 rgw_frontends = civetweb port=8080 [client.rgw.ceph-rgw1] rgw_host = ceph-rgw1 rgw_frontends = "civetweb port=8080+8443s ssl_certificate=/etc/ceph/certs/civetweb.pem"
在ceph-mgr1上重啟radosgw
root@ceph-mgr1:/etc/ceph/certs# ps -ef|grep radosgw ceph 4865 1 0 16:30 ? 00:00:02 /usr/bin/radosgw -f --cluster ceph --name client.rgw.ceph-rgw1 --setuser ceph --setgroup ceph root 5555 2150 0 16:43 pts/0 00:00:00 grep --color=auto radosgw root@ceph-mgr1:/etc/ceph/certs# systemctl restart [email protected]
在ceph-mgr1上驗證埠
root@ceph-mgr1:/etc/ceph/certs# ss -antlp|grep 8443 LISTEN 0 128 0.0.0.0:8443 0.0.0.0:* users:(("radosgw",pid=5611,fd=64))
驗證
cephadmin@ceph-deploy:~/ceph-cluster$ curl 192.168.1.201:8080 <?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>cephadmin@ceph-deploy:~/ceph-cluster$ cephadmin@ceph-deploy:~/ceph-cluster$ cephadmin@ceph-deploy:~/ceph-cluster$ curl -k https://192.168.1.201:8443 <?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></ListAllMyBucketsRe
#建立日誌目錄 root@ceph-mgr1:/etc/ceph/certs# mkdir /var/log/radosgw root@ceph-mgr1:/etc/ceph/certs# chown ceph.ceph /var/log/radosgw #修改ceph-mgr1的ceph.conf配置 root@ceph-mgr1:/etc/ceph/certs# vim /etc/ceph/ceph.conf [global] fsid = d1f2683e-ac8d-4a02-8b94-9f7517d32c50 public_network = 192.168.1.0/24 cluster_network = 192.168.88.0/24 mon_initial_members = ceph-mon1 mon_host = 192.168.1.203 auth_cluster_required = cephx auth_service_required = cephx auth_client_required = cephx #增加以下內容,client.rgw後面為主機名 [client.rgw.ceph-rgw2] rgw_host = ceph-rgw2 rgw_frontends = civetweb port=8080 [client.rgw.ceph-rgw1] rgw_host = ceph-rgw1 rgw_frontends = "civetweb port=8080+8443s ssl_certificate=/etc/ceph/certs/civetweb.pem request_timeout_ms=3000 error_log_file=/var/log/radosgw/civetweb.error.log access_log_file=/var/log/radosgw/civetweb.access.log num_threads=100"
重啟ceph-mgr1上radosgw
root@ceph-mgr1:/etc/ceph/certs# ps -ef|grep radosgw ceph 18459 1 0 23:41 ? 00:00:01 /usr/bin/radosgw -f --cluster ceph --name client.rgw.ceph-rgw1 --setuser ceph --setgroup ceph root@ceph-mgr1:/etc/ceph/certs# systemctl restart [email protected]
訪問測試:
cephadmin@ceph-deploy:~/ceph-cluster$ curl -k https://192.168.1.201:8443 cephadmin@ceph-deploy:~/ceph-cluster$ curl -k https://192.168.1.201:8443 cephadmin@ceph-deploy:~/ceph-cluster$ curl -k https://192.168.1.201:8443 #在ceph-mgr1上檢視訪問日誌 root@ceph-mgr1:/etc/ceph/certs# tail -10 /var/log/radosgw/civetweb.access.log 192.168.1.200 - - [04/Apr/2022:16:48:56 +0800] "GET / HTTP/1.1" 200 413 - curl/7.58.0 192.168.1.200 - - [04/Apr/2022:16:49:01 +0800] "GET / HTTP/1.1" 200 413 - curl/7.58.0 192.168.1.200 - - [04/Apr/2022:16:49:02 +0800] "GET / HTTP/1.1" 200 413 - curl/7.58.0
5.1、建立radosgw使用者
cephadmin@ceph-deploy:~/ceph-cluster$ radosgw-admin user create --uid=radosgwadmin --display-name='radosgwadmin' { "user_id": "radosgwadmin", "display_name": "radosgwadmin", "email": "", "suspended": 0, "max_buckets": 1000, "subusers": [], "keys": [ { "user": "radosgwadmin", "access_key": "JENGPGFNGO63XOHLB03X", "secret_key": "EbfvXpE15YQ1D8teS40TottEu5GDUnj1m8WjHIxw" } ], "swift_keys": [], "caps": [], "op_mask": "read, write, delete", "default_placement": "", "default_storage_class": "", "placement_tags": [], "bucket_quota": { "enabled": false, "check_on_raw": false, "max_size": -1, "max_size_kb": 0, "max_objects": -1 }, "user_quota": { "enabled": false, "check_on_raw": false, "max_size": -1, "max_size_kb": 0, "max_objects": -1 }, "temp_url_keys": [], "type": "rgw", "mfa_ids": [] } #使用下面命令檢視已建立的賬戶資訊 cephadmin@ceph-deploy:~/ceph-cluster$ radosgw-admin user info --uid=radosgwadmin --display-name='radosgwadmin'
root@ceph-client:~# apt install -y s3cmd
root@ceph-client:~# s3cmd --configure Enter new values or accept defaults in brackets with Enter. Refer to user manual for detailed description of all options. Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables. Access Key: JENGPGFNGO63XOHLB03X # 貼上服務端生成的Access Key Secret Key: EbfvXpE15YQ1D8teS40TottEu5GDUnj1m8WjHIxw # 貼上服務端生成的Secret Key Default Region [US]: # 直接回車即可 Use "s3.amazonaws.com" for S3 Endpoint and not modify it to the target Amazon S3. S3 Endpoint [s3.amazonaws.com]: 192.168.1.201:8080 # 輸入物件儲存的IP地址,可以為域名和radosgw的VIP Use "%(bucket)s.s3.amazonaws.com" to the target Amazon S3. "%(bucket)s" and "%(location)s" vars can be used if the target S3 system supports dns based buckets. DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: 192.168.1.201:8080/%(bucket) # 輸入物件儲存的bucket地址 Encryption password is used to protect your files from reading by unauthorized persons while in transfer to S3 Encryption password: # 空密碼回車 Path to GPG program [/usr/bin/gpg]: # /usr/bin/gpg命令路徑 回車 When using secure HTTPS protocol all communication with Amazon S3 servers is protected from 3rd party eavesdropping. This method is slower than plain HTTP, and can only be proxied with Python 2.7 or newer Use HTTPS protocol [Yes]: No # 是否使用https,選no On some networks all internet access must go through a HTTP proxy. Try setting it here if you can't connect to S3 directly HTTP Proxy server name: # haproxy 留空回車 New settings: Access Key: JENGPGFNGO63XOHLB03X Secret Key: EbfvXpE15YQ1D8teS40TottEu5GDUnj1m8WjHIxw Default Region: US S3 Endpoint: 192.168.1.201:8080 DNS-style bucket+hostname:port template for accessing a bucket: 192.168.1.201:8080/%(bucket) Encryption password: Path to GPG program: /usr/bin/gpg Use HTTPS protocol: False HTTP Proxy server name: HTTP Proxy server port: 0 Test access with supplied credentials? [Y/n] y #測試通過會提示儲存 Please wait, attempting to list all buckets... Success. Your access key and secret key worked fine :-) Now verifying that encryption works... Not configured. Never mind. Save settings? [y/N] y # y 要儲存配置檔案 Configuration saved to '/root/.s3cfg' # 最後配置檔案儲存的位置/root.s3cfg
# 建立my-bucket桶 root@ceph-client:~# s3cmd mb s3://my-bucket Bucket 's3://my-bucket/' created # 檢視所有的桶 root@ceph-client:~# s3cmd ls 2022-04-04 08:59 s3://my-bucket # 向指定桶中上傳/etc/hosts/檔案 root@ceph-client:~# s3cmd put /etc/hosts s3://my-bucket upload: '/etc/hosts' -> 's3://my-bucket/hosts' [1 of 1] 486 of 486 100% in 1s 275.83 B/s done # 向指定目錄下載檔案 root@ceph-client:~# s3cmd get s3://my-bucket/hosts /tmp/ download: 's3://my-bucket/hosts' -> '/tmp/hosts' [1 of 1] 486 of 486 100% in 0s 9.38 kB/s done # 顯示my-bucket中的檔案 root@ceph-client:~# s3cmd ls s3://my-bucket 2022-04-04 08:59 486 s3://my-bucket/hosts # 刪除my-bucket中的hosts檔案 root@ceph-client:~# s3cmd del s3://my-bucket/hosts delete: 's3://my-bucket/hosts' root@ceph-client:~# s3cmd ls s3://my-bucket root@ceph-client:~# # 刪除my-bucket root@ceph-client:~# s3cmd rb s3://my-bucket Bucket 's3://my-bucket/' removed root@ceph-client:~# s3cmd ls root@ceph-client:~# #注意:修改bucket儲存的資訊,就是重新上傳修改後的資訊