七、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 的模仿。

2、對象存儲的特點

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的邏輯圖

3、對象存儲的訪問對比

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 全部控制權限

4、RadosGW的服務配置

radosgw是部署在ceph-mgr1和ceph-mgr2上

4.1 radosgw的高可用架構

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 ceph-radosgw@rgw.ceph-rgw1
root@ceph-mgr2:~# systemctl restart ceph-radosgw@rgw.ceph-rgw2
#查看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.conf文件

注意:在生產案例中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 ceph-radosgw@rgw.ceph-rgw1.service

在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

4.4 radosgw的優化配置

#創建日志目錄
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 ceph-radosgw@rgw.ceph-rgw1.service

訪問測試:

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、使用S3 API 訪問對象存儲

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'

5.2、在客戶端安裝s3cmd軟件

s3cmd是一個通過命令行訪問ceph RGW實現創建存儲桶、上傳、下載及管理數據到對象存儲的命令行客戶端工具

root@ceph-client:~# apt install -y s3cmd

5.3、在客戶端生成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

5.4、s3cmd的驗證操作

# 創建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存儲的信息,就是重新上傳修改后的信息

  

 


免責聲明!

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



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