Ceph 基础篇 -对象存储使用

存储 存储软件
Ceph 对象存储主要是由 Ceph 对象网关守护程序(radosgw)实现的,它是一个用于与 Ceph 存储集群交互的 HTTP 服务器。

[[426989]]

对象存储 RGW

基本概念

Ceph Object Gateway is an object storage interface built on top of librados to provide applications with a RESTful gateway to Ceph Storage Clusters. Ceph Object Storage supports two interfaces:

Ceph 对象网关是一个对象存储接口,它建立在 librados 上面提供 RESTful 网关的Ceph 对象存储集群,Ceph 对象存储支持两种接口;

1.S3-compatible: Provides object storage functionality with an interface that is compatible with a large subset of the Amazon S3 RESTful API.

兼容S3:提供对象存储功能,与大部分 AWS S3 RESTful API 子集兼容;

2.Swift-compatible: Provides object storage functionality with an interface that is compatible with a large subset of the OpenStack Swift API.

兼容Swift:提供对象存储功能,与大部分 OpenStack Swift API 子集兼容;

Ceph Object Storage uses the Ceph Object Gateway daemon (radosgw), which is an HTTP server for interacting with a Ceph Storage Cluster. Since it provides interfaces compatible with OpenStack Swift and Amazon S3, the Ceph Object Gateway has its own user management. Ceph Object Gateway can store data in the same Ceph Storage Cluster used to store data from Ceph File System clients or Ceph Block Device clients. The S3 and Swift APIs share a common namespace, so you may write data with one API and retrieve it with the other.

Ceph 对象存储主要是由 Ceph 对象网关守护程序(radosgw)实现的,它是一个用于与 Ceph 存储集群交互的 HTTP 服务器。因为它提供了兼容 S3 与 Switf 的接口,Ceph 对象网关拥有自己的用户管理,Ceph 对象网关能存储数据在同一个 Ceph 存储集群,同时存储CephFS和块设备客户。S3和Swift API共享一个公共名称空间,因此您可以用一个API编写数据,然后用另一个API检索数据。

Ceph 对象网关主要是由 radosgw 接受用户请求,然后与后端librados交互;它主要起到承上启下的功能,对外它能兼容两种接口,一种是S3,另一种是Openstack Swift 接口,这两种接口,都有各自的用户认证机制,所以 Ceph 也提供了一套独立的用户管理机制,这套用户管理机制能同时兼容S3和Swift接口,最终数据会落在 OSD 上面,无论使用 S3 还是 Swift ,它们落到 OSD 上面,都是相同的名称空间;所以你使用 S3 存储的,也可以使用 Swift 进行访问。这是对象存储的一个基本架构,所以如果要使用它,我们需要部署radosgw,才能访问到集群,默认是没有安装的。

bucket 是什么?可以理解为装载对象的容器,它的后端是无限可扩展的存储空间,并且具备安全可靠性。Ceph 对象存储它后端是借助 ceph rados 实现数据容灾的机制,那么他能提供哪些功能呢?

基本功能

  • RESTful Interface # RESTful风格的接口,实现上传下载及管理功能;
  • S3- and Swift-compliant APIs # 提供两种风格的 API 接口,兼容 S3 和 Swift;
  • S3-style subdomains
  • Unified S3/Swift namespace # 扁平化、统一的的S3/Swift的名称空间;
  • User management # 为了安全性,也提供用户管理,可以限制对象是可以公共访问,还是授权访问;
  • Usage tracking # 追踪用户使用情况 rados df
  • Striped objects # 支持分片上传
  • Cloud solution integration # 支持云解决方案集成
  • Multi-site deployment # 支持多站点部署
  • Multi-site replication # 支持多站点复制

安装 RGW

1. 软件安装

  1. [root@ceph-node01 ~]# rpm -qa |grep ceph 
  2. ceph-base-14.2.11-0.el7.x86_64 
  3. ceph-mon-14.2.11-0.el7.x86_64 
  4. ceph-deploy-2.0.1-0.noarch 
  5. python-ceph-argparse-14.2.11-0.el7.x86_64 
  6. libcephfs2-14.2.11-0.el7.x86_64 
  7. ceph-common-14.2.11-0.el7.x86_64 
  8. ceph-selinux-14.2.11-0.el7.x86_64 
  9. ceph-mds-14.2.11-0.el7.x86_64 
  10. ceph-14.2.11-0.el7.x86_64 
  11. python-cephfs-14.2.11-0.el7.x86_64 
  12. ceph-osd-14.2.11-0.el7.x86_64 
  13. ceph-mgr-14.2.11-0.el7.x86_64 
  14. ceph-radosgw-14.2.11-0.el7.x86_64 # 直接使用 yum 安装即可 
  15. [root@ceph-node01 ~]# 

2. 启动服务,默认启动在7480端口

  1. [root@ceph-node01 ceph-deploy]# ceph-deploy rgw create ceph-node01 

3. 服务检测

  1. [root@ceph-node01 ceph-deploy]# systemctl status ceph-radosgw@rgw.ceph-node01 
  2. ● ceph-radosgw@rgw.ceph-node01.service - Ceph rados gateway 
  3.    Loaded: loaded (/usr/lib/systemd/system/ceph-radosgw@.service; enabled; vendor preset: disabled) 
  4.    Active: active (running) since 一 2020-10-05 20:34:36 EDT; 14s ago 
  5.  Main PID: 33574 (radosgw) 
  6.    CGroup: /system.slice/system-ceph\x2dradosgw.slice/ceph-radosgw@rgw.ceph-node01.service 
  7.            └─33574 /usr/bin/radosgw -f --cluster ceph --name client.rgw.ceph-node01 --setuser ceph --setgroup ceph 
  8.  
  9. 10月 05 20:34:36 ceph-node01 systemd[1]: Started Ceph rados gateway. 
  10. 10月 05 20:34:36 ceph-node01 systemd[1]: [/usr/lib/systemd/system/ceph-radosgw@.service:13] Unknown lvalue 'LockPersonality' in section 'Service' 
  11. 10月 05 20:34:36 ceph-node01 systemd[1]: [/usr/lib/systemd/system/ceph-radosgw@.service:14] Unknown lvalue 'MemoryDenyWriteExecute' in ...Service' 
  12. 10月 05 20:34:36 ceph-node01 systemd[1]: [/usr/lib/systemd/system/ceph-radosgw@.service:17] Unknown lvalue 'ProtectControlGroups' in se...Service' 
  13. 10月 05 20:34:36 ceph-node01 systemd[1]: [/usr/lib/systemd/system/ceph-radosgw@.service:19] Unknown lvalue 'ProtectKernelModules' in se...Service' 
  14. 10月 05 20:34:36 ceph-node01 systemd[1]: [/usr/lib/systemd/system/ceph-radosgw@.service:20] Unknown lvalue 'ProtectKernelTunables' in s...Service' 
  15. Hint: Some lines were ellipsized, use -l to show in full
  16. [root@ceph-node01 ceph-deploy]# netstat -antp |grep 7480 
  17. tcp 0 0 0.0.0.0:7480 0.0.0.0:* LISTEN 33574/radosgw 
  18. [root@ceph-node01 ceph-deploy]# ceph -s 
  19.   cluster: 
  20.     id: cc10b0cb-476f-420c-b1d6-e48c1dc929af 
  21.     health: HEALTH_OK 
  22.  
  23.   services: 
  24.     mon: 3 daemons, quorum ceph-node01,ceph-node02,ceph-node03 (age 2d) 
  25.     mgr: ceph-node01(active, since 2d), standbys: ceph-node02, ceph-node03 
  26.     osd: 3 osds: 3 up (since 2d), 3 in (since 2d) 
  27.     rgw: 1 daemon active (ceph-node01) 
  28.  
  29.   task status: 
  30.  
  31.   data: 
  32.     pools: 5 pools, 256 pgs 
  33.     objects: 507 objects, 1.1 GiB 
  34.     usage: 5.3 GiB used, 395 GiB / 400 GiB avail 
  35.     pgs: 256 active+clean 
  36.  
  37.   io: 
  38.     client: 23 KiB/s rd, 0 B/s wr, 35 op/s rd, 23 op/s wr 
  39.  
  40. [root@ceph-node01 ceph-deploy]# 

4. 首次访问服务

  1. [root@ceph-node01 ceph-deploy]# curl http://ceph-node01:7480/ 
  2. <?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>[root@ceph-node01 ceph-deploy]# 

提示错误,使用了 anonymous 匿名用户请求所有列表,到这里说明安装完毕了;

5. 修改 RGW 的 默认端口 7480 到 80

  1. [root@ceph-node01 ceph-deploy]# cat ceph.conf 
  2. 。。。 
  3.  
  4. [client.rgw.ceph-node01] 
  5. rgw_frontends = "civetweb port=80" 
  6. [root@ceph-node01 ceph-deploy]# 

修改配置文件ceph.conf,为什么修改这个文件呢?因为后面添加节点时,默认是copy的这个配置文件,修改这个配置文件,可以确保集群的唯一性,下面推送配置文件到所有节点;

  1. [root@ceph-node01 ceph-deploy]# ceph-deploy --overwrite-conf config push ceph-node01 ceph-node02 ceph-node03 

--overwrite-conf 注意需要使用这个选项,否则提示无法覆盖;

6. 重启服务

  1. [root@ceph-node01 ceph-deploy]# systemctl restart ceph-radosgw@rgw.ceph-node01 
  2. [root@ceph-node01 ceph-deploy]# netstat -antp |grep 80|grep radosgw 
  3. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 34352/radosgw 
  4. tcp 0 0 100.73.18.152:36100 100.73.18.153:6800 ESTABLISHED 34352/radosgw 
  5. tcp 0 0 100.73.18.152:53018 100.73.18.152:6800 ESTABLISHED 34352/radosgw 
  6. tcp 0 0 100.73.18.152:36118 100.73.18.153:6800 ESTABLISHED 34352/radosgw 
  7. tcp 0 0 100.73.18.152:39680 100.73.18.152:6802 ESTABLISHED 34352/radosgw 
  8. tcp 0 0 100.73.18.152:56320 100.73.18.128:6800 ESTABLISHED 34352/radosgw 
  9. tcp 0 0 100.73.18.152:39666 100.73.18.152:6802 ESTABLISHED 34352/radosgw 
  10. tcp 0 0 100.73.18.152:56336 100.73.18.128:6800 ESTABLISHED 34352/radosgw 
  11. tcp 0 0 100.73.18.152:53034 100.73.18.152:6800 ESTABLISHED 34352/radosgw 
  12. [root@ceph-node01 ceph-deploy]# 

7. 验证 80 端口

  1. [root@ceph-node01 ceph-deploy]# curl http://ceph-node01/ 
  2. <?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>[root@ceph-node01 ceph-deploy]# 

直此,RGW 服务部署完成;

使用 S3 访问 RGW

1. 创建 s3 的兼容用户

  1. [root@ceph-node01 ceph-deploy]# radosgw-admin user create --uid ceph-s3-user --display-name "Ceph S3 User Demo" 
  2.     "user_id""ceph-s3-user"
  3.     "display_name""Ceph S3 User Demo"
  4.     "email"""
  5.     "suspended": 0, 
  6.     "max_buckets": 1000, 
  7.     "subusers": [], 
  8.     "keys": [ 
  9.         { 
  10.             "user""ceph-s3-user"
  11.             "access_key""V3J9L4M1WKV5O5ECAKPU"
  12.             "secret_key""f5LqLVYOVNu38cuQwi0jXC2ZTboCSJDmdvB8oeYw" 
  13.         } 
  14.     ], 
  15.     "swift_keys": [], 
  16.     "caps": [], 
  17.     "op_mask""read, write, delete"
  18.     "default_placement"""
  19.     "default_storage_class"""
  20.     "placement_tags": [], 
  21.     "bucket_quota": { 
  22.         "enabled"false
  23.         "check_on_raw"false
  24.         "max_size": -1, 
  25.         "max_size_kb": 0, 
  26.         "max_objects": -1 
  27.     }, 
  28.     "user_quota": { 
  29.         "enabled"false
  30.         "check_on_raw"false
  31.         "max_size": -1, 
  32.         "max_size_kb": 0, 
  33.         "max_objects": -1 
  34.     }, 
  35.     "temp_url_keys": [], 
  36.     "type""rgw"
  37.     "mfa_ids": [] 
  38.  
  39. [root@ceph-node01 ceph-deploy]# 

注意上面的 access_key 与 secret_key 很重要,要记下来,以备后用; 不记录也没有关系,我们可以使用以下命令查看;

  1. [root@ceph-node01 ceph-deploy]# radosgw-admin user info --uid ceph-s3-user 

2. 使用 Ceph SDK 访问 Ceph 集群

官方SDK 使用说明:https://docs.ceph.com/en/latest/radosgw/s3/python/#using-s3-api-extensions

  1. [root@ceph-node01 ~]# cat s3client.py 
  2. import boto 
  3. import boto.s3.connection 
  4. access_key = 'V3J9L4M1WKV5O5ECAKPU' 
  5. secret_key = 'f5LqLVYOVNu38cuQwi0jXC2ZTboCSJDmdvB8oeYw' 
  6.  
  7. conn = boto.connect_s3( 
  8.         aws_access_key_id = access_key, 
  9.         aws_secret_access_key = secret_key, 
  10.         host = 'ceph-node01', port = 80, 
  11.         is_secure=False, # uncomment if you are not using ssl 
  12.         calling_format = boto.s3.connection.OrdinaryCallingFormat(), 
  13.         ) 
  14. bucket = conn.create_bucket("ceph-s3-bucket"
  15. for bucket in conn.get_all_buckets(): 
  16.         print "{name}\t{created}".format( 
  17.                 name = bucket.name
  18.                 created = bucket.creation_date, 
  19.         ) 
  20. [root@ceph-node01 ~]# 
  21. [root@ceph-node01 ~]# python s3client.py 
  22. ceph-s3-bucket 2020-10-06T04:13:10.629Z 
  23. [root@ceph-node01 ~]# 

安装完rgw后,会自动创建3个pool,一个是rgw.control、rgw.meta、rgw.log,当我们创建bucket后,还会创建一个rgw.buckets.index pool池;

  1. [root@ceph-node01 ~]# ceph osd lspools 
  2. 1 ceph-demo 
  3. 2 .rgw.root 
  4. default.rgw.control 
  5. default.rgw.meta 
  6. default.rgw.log 
  7. default.rgw.buckets.index 
  8. [root@ceph-node01 ~]# 

3. 使用命令行方式操作 rgw

安装命令行工具

  1. [root@ceph-node01 ~]# yum -y install s3cmd 

配置命令行工具

  1. [root@ceph-node01 ~]# s3cmd --configure 
  2.  
  3. Enter new values or accept defaults in brackets with Enter. 
  4. Refer to user manual for detailed description of all options. 
  5.  
  6. Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables. 
  7. Access Key: V3J9L4M1WKV5O5ECAKPU 
  8. Secret Key: f5LqLVYOVNu38cuQwi0jXC2ZTboCSJDmdvB8oeYw 
  9. Default Region [US]: 
  10.  
  11. Use "s3.amazonaws.com" for S3 Endpoint and not modify it to the target Amazon S3. 
  12. S3 Endpoint [s3.amazonaws.com]: 100.73.18.152:80 
  13.  
  14. Use "%(bucket)s.s3.amazonaws.com" to the target Amazon S3. "%(bucket)s" and "%(location)s" vars can be used 
  15. if the target S3 system supports dns based buckets. 
  16. DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: 100.73.18.152:80/%(bucket)s 
  17.  
  18. Encryption password is used to protect your files from reading 
  19. by unauthorized persons while in transfer to S3 
  20. Encryption password
  21. Path to GPG program [/usr/bin/gpg]: 
  22.  
  23. When using secure HTTPS protocol all communication with Amazon S3 
  24. servers is protected from 3rd party eavesdropping. This method is 
  25. slower than plain HTTP, and can only be proxied with Python 2.7 or newer 
  26. Use HTTPS protocol [Yes]: no 
  27.  
  28. On some networks all internet access must go through a HTTP proxy. 
  29. Try setting it here if you can't connect to S3 directly 
  30. HTTP Proxy server name
  31.  
  32. New settings: 
  33.   Access Key: V3J9L4M1WKV5O5ECAKPU 
  34.   Secret Key: f5LqLVYOVNu38cuQwi0jXC2ZTboCSJDmdvB8oeYw 
  35.   Default Region: US 
  36.   S3 Endpoint: 100.73.18.152:80 
  37.   DNS-style bucket+hostname:port template for accessing a bucket: 100.73.18.152:80/%(bucket)s 
  38.   Encryption password
  39.   Path to GPG program: /usr/bin/gpg 
  40.   Use HTTPS protocol: False 
  41.   HTTP Proxy server name
  42.   HTTP Proxy server port: 0 
  43.  
  44. Test access with supplied credentials? [Y/n] y 
  45. Please wait, attempting to list all buckets... 
  46. Success. Your access key and secret key worked fine :-) 
  47.  
  48. Now verifying that encryption works... 
  49. Not configured. Never mind. 
  50.  
  51. Save settings? [y/N] y 
  52. Configuration saved to '/root/.s3cfg' 
  53. [root@ceph-node01 ~]# 

简单使用命令行工具

  1. [root@ceph-node01 ~]# s3cmd ls 
  2. 2020-10-06 04:13 s3://ceph-s3-bucket 
  3. [root@ceph-node01 ~]# s3cmd mb s3://s3cmd-demo 
  4. ERROR: S3 error: 403 (SignatureDoesNotMatch) 

这是需要修改版本,启用v2版本即可

  1. [root@ceph-node01 ~]# sed -i '/signature_v2/s/False/True/g' /root/.s3cfg 
  2. [root@ceph-node01 ~]# 

再次创建

  1. [root@ceph-node01 ~]# s3cmd mb s3://s3cmd-demo 
  2. Bucket 's3://s3cmd-demo/' created 
  3. [root@ceph-node01 ~]# 

上传单个文件

  1. [root@ceph-node01 ~]# s3cmd put /etc/fstab s3://s3cmd-demo/fatab-demo 
  2. upload: '/etc/fstab' -> 's3://s3cmd-demo/fatab-demo' [1 of 1] 
  3.  465 of 465 100% in 0s 1751.66 B/s done 
  4. ERROR: S3 error: 416 (InvalidRange) 
  5. [root@ceph-node01 ~]# 

出现错误 ERROR: S3 error: 416 (InvalidRange),原因是上传object对象的时候,需要创建 pool 存储数据,创建 pool 是需要 pg,当 pg 数量不够的情况下,可以将现有的 pg 数量调小,或者修改配置文件调整参数,然后重启 mon 进程,调整方法有三种:

  1. 调整 pg_num 和 pgp_num ,默认参数值均为8;
  2. 调整 mon_max_pg_per_osd 参数,默认是 300,适当增大;当每个 OSD 中的 PG数量超过这个参数值时,就会报错;https://www.suse.com/support/kb/doc/?id=000019402
  3. 增加更多的 OSD 进来;

我们采用第2种方法:

  1. [root@ceph-node01 ceph-deploy]# cat ceph.conf 
  2. [global
  3. fsid = cc10b0cb-476f-420c-b1d6-e48c1dc929af 
  4. public_network = 100.73.18.0/24 
  5. cluster_network = 100.73.18.0/24 
  6. mon_initial_members = ceph-node01 
  7. mon_host = 100.73.18.152 
  8. auth_cluster_required = cephx 
  9. auth_service_required = cephx 
  10. auth_client_required = cephx 
  11. mon_max_pg_per_osd = 1000 
  12.  
  13. [client.rgw.ceph-node01] 
  14. rgw_frontends = "civetweb port=80" 
  15. [root@ceph-node01 ceph-deploy]# 

重启下 monitor daemon 进程

  1. [root@ceph-node01 ceph-deploy]# systemctl restart ceph-mon@ceph-node01 
  2. [root@ceph-node01 ceph-deploy]# systemctl restart ceph-mon@ceph-node02 
  3. [root@ceph-node01 ceph-deploy]# systemctl restart ceph-mon@ceph-node03 

再次上传文件测试

  1. [root@ceph-node01 ceph-deploy]# s3cmd put /etc/fstab s3://s3cmd-demo/ 
  2. upload: '/etc/fstab' -> 's3://s3cmd-demo/fstab' [1 of 1] 
  3.  465 of 465 100% in 1s 337.90 B/s done 
  4. [root@ceph-node01 ceph-deploy]# 

4. 常用操作

  1. # 1. 列出所有 bucket 
  2. [root@ceph-node01 ~]# s3cmd ls 
  3. 2020-10-06 04:13 s3://ceph-s3-bucket 
  4. 2020-10-06 04:34 s3://s3cmd-demo 
  5. 2020-10-06 08:07 s3://swift-demo 
  6.  
  7. # 2. 创建 bucket 
  8. [root@ceph-node01 ~]# s3cmd mb s3://gwj-demo/ 
  9. Bucket 's3://gwj-demo/' created 
  10.  
  11. # 3. 删除空的bucket 
  12. [root@ceph-node01 ~]# s3cmd rb s3://gwj-demo/ 
  13. Bucket 's3://gwj-demo/' removed 
  14.  
  15. # 4. 上传文件到bucket 
  16. [root@ceph-node01 ~]# s3cmd put ip s3://s3cmd-demo/ 
  17. upload: 'ip' -> 's3://s3cmd-demo/ip' [1 of 1] 
  18.  78 of 78 100% in 0s 2.21 KB/s done 
  19.  
  20. # 5. 上传目录到 bucket 
  21. [root@ceph-node01 ~]# s3cmd put ./ s3://s3cmd-demo/ 
  22. ERROR: Parameter problem: Use --recursive to upload a directory: ./ 
  23.  
  24. [root@ceph-node01 ~]# s3cmd put ./ s3://s3cmd-demo/ --recursive 
  25. 。。。 
  26. upload: './ceph-deploy/get-pip.py' -> 's3://s3cmd-demo/ceph-deploy/get-pip.py' [36 of 39] 
  27.  1885433 of 1885433 100% in 0s 18.00 MB/s done 
  28. upload: './ip' -> 's3://s3cmd-demo/ip' [37 of 39] 
  29.  78 of 78 100% in 0s 4.60 KB/s done 
  30. upload: './s3client.py' -> 's3://s3cmd-demo/s3client.py' [38 of 39] 
  31.  655 of 655 100% in 0s 10.23 KB/s done 
  32. upload: './size.log' -> 's3://s3cmd-demo/size.log' [39 of 39] 
  33.  2448 of 2448 100% in 0s 33.82 KB/s done 
  34. [root@ceph-node01 ~]# 
  35.  
  36. # 6. 列举 bucket 中的内容 
  37. [root@ceph-node01 ~]# s3cmd ls s3://s3cmd-demo/ 
  38.                           DIR s3://s3cmd-demo/.cache/ 
  39.                           DIR s3://s3cmd-demo/.ssh/ 
  40.                           DIR s3://s3cmd-demo/ceph-deploy/ 
  41. 2020-10-06 10:24 19887 s3://s3cmd-demo/.bash_history 
  42. 2020-10-06 10:24 18 s3://s3cmd-demo/.bash_logout 
  43. 2020-10-06 10:24 176 s3://s3cmd-demo/.bash_profile 
  44. 2020-10-06 10:24 176 s3://s3cmd-demo/.bashrc 
  45. 2020-10-06 10:24 1077 s3://s3cmd-demo/.cephdeploy.conf 
  46. 2020-10-06 10:24 100 s3://s3cmd-demo/.cshrc 
  47. 2020-10-06 10:24 0 s3://s3cmd-demo/.history 
  48. 2020-10-06 10:24 2140 s3://s3cmd-demo/.s3cfg 
  49. 2020-10-06 10:24 12288 s3://s3cmd-demo/.swp 
  50. 2020-10-06 10:24 129 s3://s3cmd-demo/.tcshrc 
  51. 2020-10-06 10:24 5864 s3://s3cmd-demo/.viminfo 
  52. 2020-10-06 10:24 974 s3://s3cmd-demo/anaconda-ks.cfg 
  53. 2020-10-06 10:24 3454 s3://s3cmd-demo/ceph-deploy-ceph.log 
  54. 2020-10-06 08:57 465 s3://s3cmd-demo/fstab 
  55. 2020-10-06 10:24 78 s3://s3cmd-demo/ip 
  56. 2020-10-06 10:24 655 s3://s3cmd-demo/s3client.py 
  57. 2020-10-06 10:24 2448 s3://s3cmd-demo/size.log 
  58. [root@ceph-node01 ~]# 
  59.  
  60. # 7. 下载单个文件 
  61. [root@ceph-node01 gwj]# s3cmd get s3://s3cmd-demo/size.log 
  62. download: 's3://s3cmd-demo/size.log' -> './size.log' [1 of 1] 
  63.  2448 of 2448 100% in 0s 242.11 KB/s done 
  64. [root@ceph-node01 gwj]# ls 
  65. size.log 
  66. [root@ceph-node01 gwj]# 
  67.  
  68. # 8. 删除 bucket 中的内容 
  69. [root@ceph-node01 gwj]# s3cmd del s3://s3cmd-demo/size.log 
  70. delete's3://s3cmd-demo/size.log' 
  71. [root@ceph-node01 gwj]# s3cmd get s3://s3cmd-demo/size.log 
  72. ERROR: Parameter problem: File ./size.log already exists. Use either of --force / --continue / --skip-existing or give it a new name. 
  73. [root@ceph-node01 gwj]# 
  74.  
  75. # 9. 获取对应的bucket所占用的空间大小 
  76. [root@ceph-node01 gwj]# s3cmd du -H s3://s3cmd-demo/ 
  77.    3M 39 objects s3://s3cmd-demo/ 
  78. [root@ceph-node01 gwj]# s3cmd du -H s3://s3cmd-demo/.ssh 
  79.    3K 4 objects s3://s3cmd-demo/.ssh 
  80. [root@ceph-node01 gwj]# 
  81.  
  82. # 10. 查看bucket文件信息 
  83. [root@ceph-node01 gwj]# s3cmd info s3://s3cmd-demo/ip 
  84. s3://s3cmd-demo/ip (object): 
  85.    File size: 78 
  86.    Last mod: Tue, 06 Oct 2020 10:24:29 GMT 
  87.    MIME type: text/plain 
  88.    Storage: STANDARD 
  89.    MD5 sum: fd3066a2b8b805e905aeb073afd970cf 
  90.    SSE: none 
  91.    Policy: none 
  92.    CORS: none 
  93.    ACL: Ceph S3 User Demo: FULL_CONTROL 
  94.    x-amz-meta-s3cmd-attrs: atime:1601969067/ctime:1601287013/gid:0/gname:root/md5:fd3066a2b8b805e905aeb073afd970cf/mode:33188/mtime:1601287013/uid:0/uname:root 
  95. [root@ceph-node01 gwj]# 
  96.  
  97. # 11. 两个bucket之间相互cp 
  98. [root@ceph-node01 gwj]# s3cmd cp s3://s3cmd-demo/ip s3://test-demo/ 
  99. remote copy: 's3://s3cmd-demo/ip' -> 's3://test-demo/ip' 
  100. [root@ceph-node01 gwj]# s3cmd cp --recursive s3://s3cmd-demo/.ssh s3://test-demo/ 
  101. remote copy: 's3://s3cmd-demo/.ssh/authorized_keys' -> 's3://test-demo/.ssh/authorized_keys' 
  102. remote copy: 's3://s3cmd-demo/.ssh/id_rsa' -> 's3://test-demo/.ssh/id_rsa' 
  103. remote copy: 's3://s3cmd-demo/.ssh/id_rsa.pub' -> 's3://test-demo/.ssh/id_rsa.pub' 
  104. remote copy: 's3://s3cmd-demo/.ssh/known_hosts' -> 's3://test-demo/.ssh/known_hosts' 
  105. [root@ceph-node01 gwj]# 
  106.  
  107. # 12. 两个bucket之间进行mv操作 
  108. [root@ceph-node01 gwj]# s3cmd ls s3://s3cmd-demo/.swp 
  109. 2020-10-06 10:24 12288 s3://s3cmd-demo/.swp 
  110. [root@ceph-node01 gwj]# s3cmd mv s3://s3cmd-demo/.swp s3://test-demo/ 
  111. move's3://s3cmd-demo/.swp' -> 's3://test-demo/.swp' 
  112. [root@ceph-node01 gwj]# s3cmd ls s3://test-demo/.swp 
  113. 2020-10-06 10:36 12288 s3://test-demo/.swp 
  114. [root@ceph-node01 gwj]# s3cmd ls s3://s3cmd-demo/.swp 
  115. [root@ceph-node01 gwj]# 
  116.  
  117. # 13. 列出需要同步的文件和目录,但不进行同步 
  118. [root@ceph-node01 ~]# s3cmd sync --dry-run ./ s3://s3cmd-demo 
  119. upload: './.swp' -> 's3://s3cmd-demo/.swp' 
  120. upload: './ip' -> 's3://s3cmd-demo/ip' 
  121. upload: './.cache/abrt/lastnotification' -> 's3://s3cmd-demo/.cache/abrt/lastnotification' 
  122. remote copy: 'size.log' -> 'gwj/size.log' 
  123. WARNING: Exiting now because of --dry-run 
  124. [root@ceph-node01 ~]# 
  125.  
  126. # 14. 在bucket中删除本地不存在的文件 
  127. [root@ceph-node01 a]# ls 
  128. 10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 
  129. [root@ceph-node01 a]# 
  130. [root@ceph-node01 a]# s3cmd ls s3://test2-demo/ 
  131. 2020-10-06 11:17 43 s3://test2-demo/1.txt 
  132. 2020-10-06 11:17 43 s3://test2-demo/10.txt 
  133. 2020-10-06 11:17 43 s3://test2-demo/2.txt 
  134. 2020-10-06 11:17 43 s3://test2-demo/3.txt 
  135. 2020-10-06 11:17 43 s3://test2-demo/4.txt 
  136. 2020-10-06 11:17 43 s3://test2-demo/5.txt 
  137. 2020-10-06 11:17 43 s3://test2-demo/6.txt 
  138. 2020-10-06 11:17 43 s3://test2-demo/7.txt 
  139. 2020-10-06 11:17 43 s3://test2-demo/8.txt 
  140. 2020-10-06 11:17 43 s3://test2-demo/9.txt 
  141. [root@ceph-node01 a]# rm -rf 10.txt 
  142. [root@ceph-node01 a]# s3cmd sync --delete-removed ./ s3://test2-demo/ 
  143. delete's3://test2-demo/10.txt' 
  144. [root@ceph-node01 a]# s3cmd ls s3://test2-demo/ 
  145. 2020-10-06 11:17 43 s3://test2-demo/1.txt 
  146. 2020-10-06 11:17 43 s3://test2-demo/2.txt 
  147. 2020-10-06 11:17 43 s3://test2-demo/3.txt 
  148. 2020-10-06 11:17 43 s3://test2-demo/4.txt 
  149. 2020-10-06 11:17 43 s3://test2-demo/5.txt 
  150. 2020-10-06 11:17 43 s3://test2-demo/6.txt 
  151. 2020-10-06 11:17 43 s3://test2-demo/7.txt 
  152. 2020-10-06 11:17 43 s3://test2-demo/8.txt 
  153. 2020-10-06 11:17 43 s3://test2-demo/9.txt 
  154. [root@ceph-node01 a]# 

使用 swift 访问 RGW

1. 创建 swift 用户

  1. [root@ceph-node01 ceph-deploy]# radosgw-admin subuser create --uid ceph-s3-user --subuser=ceph-s3-user:swift --access=full 
  2.     "user_id""ceph-s3-user"
  3.     "display_name""Ceph S3 User Demo"
  4.     "email"""
  5.     "suspended": 0, 
  6.     "max_buckets": 1000, 
  7.     "subusers": [ 
  8.         { 
  9.             "id""ceph-s3-user:swift"
  10.             "permissions""full-control" 
  11.         } 
  12.     ], 
  13.     "keys": [ 
  14.         { 
  15.             "user""ceph-s3-user"
  16.             "access_key""V3J9L4M1WKV5O5ECAKPU"
  17.             "secret_key""f5LqLVYOVNu38cuQwi0jXC2ZTboCSJDmdvB8oeYw" 
  18.         } 
  19.     ], 
  20.     "swift_keys": [ 
  21.         { 
  22.             "user""ceph-s3-user:swift"
  23.             "secret_key""ZIOOU8Xcfe3m6ZZapK5P2rU0GGPaiS31chy9yvMW" 
  24.         } 
  25.     ], 
  26.     "caps": [], 
  27.     "op_mask""read, write, delete"
  28.     "default_placement"""
  29.     "default_storage_class"""
  30.     "placement_tags": [], 
  31.     "bucket_quota": { 
  32.         "enabled"false
  33.         "check_on_raw"false
  34.         "max_size": -1, 
  35.         "max_size_kb": 0, 
  36.         "max_objects": -1 
  37.     }, 
  38.     "user_quota": { 
  39.         "enabled"false
  40.         "check_on_raw"false
  41.         "max_size": -1, 
  42.         "max_size_kb": 0, 
  43.         "max_objects": -1 
  44.     }, 
  45.     "temp_url_keys": [], 
  46.     "type""rgw"
  47.     "mfa_ids": [] 
  48.  
  49. [root@ceph-node01 ceph-deploy]# 

2. 创建 swift 用户的secret

  1. [root@ceph-node01 ceph-deploy]# radosgw-admin key create --subuser=ceph-s3-user:swift --key-type=swift --gen-secret 
  2.     "user_id""ceph-s3-user"
  3.     "display_name""Ceph S3 User Demo"
  4.     "email"""
  5.     "suspended": 0, 
  6.     "max_buckets": 1000, 
  7.     "subusers": [ 
  8.         { 
  9.             "id""ceph-s3-user:swift"
  10.             "permissions""full-control" 
  11.         } 
  12.     ], 
  13.     "keys": [ 
  14.         { 
  15.             "user""ceph-s3-user"
  16.             "access_key""V3J9L4M1WKV5O5ECAKPU"
  17.             "secret_key""f5LqLVYOVNu38cuQwi0jXC2ZTboCSJDmdvB8oeYw" 
  18.         } 
  19.     ], 
  20.     "swift_keys": [ 
  21.         { 
  22.             "user""ceph-s3-user:swift"
  23.             "secret_key""0M1GdRTvMSU3fToOxEVXrBjItKLBKtu8xhn3DcEE" 
  24.         } 
  25.     ], 
  26.     "caps": [], 
  27.     "op_mask""read, write, delete"
  28.     "default_placement"""
  29.     "default_storage_class"""
  30.     "placement_tags": [], 
  31.     "bucket_quota": { 
  32.         "enabled"false
  33.         "check_on_raw"false
  34.         "max_size": -1, 
  35.         "max_size_kb": 0, 
  36.         "max_objects": -1 
  37.     }, 
  38.     "user_quota": { 
  39.         "enabled"false
  40.         "check_on_raw"false
  41.         "max_size": -1, 
  42.         "max_size_kb": 0, 
  43.         "max_objects": -1 
  44.     }, 
  45.     "temp_url_keys": [], 
  46.     "type""rgw"
  47.     "mfa_ids": [] 
  48.  
  49. [root@ceph-node01 ceph-deploy]# 

3. 需要使用 pip 安装 swift 客户端工具

  1. # 注意如果有pip的话,就不需要再安装了 
  2. [root@ceph-node01 ceph-deploy]# curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 
  3. 。。。 
  4. [root@ceph-node01 ceph-deploy]# python get-pip.py 
  5. 。。。 
  6. [root@ceph-node01 ceph-deploy]# pip install python-swiftclient 
  7. 。。。 

4. 使用 swift 命令行工具

  1. [root@ceph-node01 ceph-deploy]# swift -A http://100.73.18.152/auth -U ceph-s3-user:swift -K 0M1GdRTvMSU3fToOxEVXrBjItKLBKtu8xhn3DcEE list 
  2. ceph-s3-bucket 
  3. s3cmd-demo 
  4. [root@ceph-node01 ceph-deploy]# 

5. 配置成环境变量的形式

  1. [root@ceph-node01 ceph-deploy]# cat /etc/profile 
  2. 。。。 
  3. export ST_AUTH=http://100.73.18.152/auth 
  4. export ST_USER=ceph-s3-user:swift 
  5. export ST_KEY=0M1GdRTvMSU3fToOxEVXrBjItKLBKtu8xhn3DcEE 
  6. [root@ceph-node01 ceph-deploy]# source /etc/profile 
  7. [root@ceph-node01 ceph-deploy]# swift list 
  8. ceph-s3-bucket 
  9. s3cmd-demo 
  10. [root@ceph-node01 ceph-deploy]# 

6. 创建bucket

  1. [root@ceph-node01 ceph-deploy]# swift post swift-demo 
  2. [root@ceph-node01 ceph-deploy]# swift list 
  3. ceph-s3-bucket 
  4. s3cmd-demo 
  5. swift-demo 
  6. [root@ceph-node01 ceph-deploy]# 

7. 上传单个文件测试

  1. [root@ceph-node01 ceph-deploy]# swift upload swift-demo /etc/fstab 
  2. Object HEAD failed: http://100.73.18.152/swift/v1/swift-demo/etc/fstab 416 Requested Range Not Satisfiable 
  3. [root@ceph-node01 ceph-deploy]# 

8. 上传目录测试

  1. [root@ceph-node01 a]# swift upload swift-demo /etc/fstab 
  2. etc/fstab 
  3. [root@ceph-node01 a]# 

9. 常用操作

  1. # 1. 列举所有 bucket 
  2. [root@ceph-node01 a]# swift list 
  3. ceph-s3-bucket 
  4. s3cmd-demo 
  5. swift-demo 
  6. test-demo 
  7. test2-demo 
  8. [root@ceph-node01 a]# 
  9.  
  10. # 2. 列举所有 bucket 
  11. [root@ceph-node01 a]# swift list --lh 
  12.     0 0 2020-10-06 04:13:10 ceph-s3-bucket 
  13.    37 3.6M 2020-10-06 04:34:49 s3cmd-demo 
  14.  2360 33M 2020-10-06 08:07:55 swift-demo 
  15.     7 16K 2020-10-06 10:32:02 test-demo 
  16.     9 387 2020-10-06 11:17:00 test2-demo 
  17.  2.4K 36M 
  18. [root@ceph-node01 a]# 
  19.  
  20. # 3. 列举单个 bucket 
  21. [root@ceph-node01 a]# swift list swift-demo 
  22.  
  23. # 4. 上传单个文件到bucket 
  24. [root@ceph-node01 a]# swift upload swift-demo /etc/fstab 
  25. etc/fstab 
  26. [root@ceph-node01 a]# 
  27.  
  28. # 5. 上传目录到指定的bucket 
  29. [root@ceph-node01 a]# swift upload swift-demo /etc/ 
  30.  
  31. # 6. swift 状态信息 
  32. [root@ceph-node01 a]# swift stat 
  33.                                     Account: v1 
  34.                                  Containers: 5 
  35.                                     Objects: 2413 
  36.                                       Bytes: 38701415 
  37. Objects in policy "default-placement-bytes": 0 
  38.   Bytes in policy "default-placement-bytes": 0 
  39.    Containers in policy "default-placement": 5 
  40.       Objects in policy "default-placement": 2413 
  41.         Bytes in policy "default-placement": 38701415 
  42.                      X-Openstack-Request-Id: tx000000000000000001302-005f7c5afd-a638-default 
  43.                 X-Account-Bytes-Used-Actual: 45948928 
  44.                                  X-Trans-Id: tx000000000000000001302-005f7c5afd-a638-default 
  45.                                 X-Timestamp: 1601985277.38095 
  46.                                Content-Type: text/plain; charset=utf-8 
  47.                               Accept-Ranges: bytes 
  48. [root@ceph-node01 a]# 
  49.  
  50. # 7. 创建 bucket 
  51. [root@ceph-node01 a]# swift post swift-test 
  52. [root@ceph-node01 a]# swift list 
  53. ceph-s3-bucket 
  54. s3cmd-demo 
  55. swift-demo 
  56. swift-test 
  57. test-demo 
  58. test2-demo 
  59. [root@ceph-node01 a]# 
  60.  
  61. # 8. 删除 bucket 
  62. [root@ceph-node01 a]# swift delete swift-demo 
  63.  
  64. # 9. 删除指定 object 
  65. [root@ceph-node01 a]# swift delete swift-test root/a/1.txt 
  66. root/a/1.txt 
  67. [root@ceph-node01 a]# 
  68.  
  69. # 10. 上传大文件时可以使用-S指定分片大小 
  70. [root@ceph-node01 a]# swift upload swift-test /home/log.txt 
  71. home/log.txt 
  72. [root@ceph-node01 a]# swift upload swift-test -S 102400000 /home/log2.txt 
  73. home/log2.txt segment 5 
  74. home/log2.txt segment 3 
  75. home/log2.txt segment 1 
  76. home/log2.txt segment 0 
  77. home/log2.txt segment 2 
  78. home/log2.txt segment 4 
  79. home/log2.txt 
  80. [root@ceph-node01 a]# 

总结

从概念、安装、到实践使用,简单介绍了对象存储命令行工具。

本文转载自微信公众号「Linux点滴运维实践」,可以通过以下二维码关注。转载本文请联系Linux点滴运维实践公众号。

 

 

责任编辑:武晓燕 来源: Linux点滴运维实践
相关推荐

2018-05-22 08:37:02

Ceph存储存储系统

2017-12-06 14:35:01

OpenStackCeph存储

2018-05-23 08:39:18

AlluxioCeph对象存储

2018-07-13 08:45:57

Ceph对象存储混合云

2018-04-23 15:14:02

混合云云存储公有云

2017-02-19 10:22:33

Ceph对象存储

2017-03-06 09:32:50

CephKVM虚拟机

2018-04-08 08:25:15

Ceph对象存储混合云

2021-10-12 10:36:06

存储公有云同步

2021-05-06 21:26:00

BcacheCeph存储

2014-07-28 14:43:14

git开源

2018-03-12 08:53:36

Ceph对象存储

2009-06-12 11:42:28

EJB分布式

2017-06-06 13:35:28

2018-11-21 10:21:55

CephSwift存储系统

2021-01-26 06:58:03

AnsibleCeph集群运维

2015-04-03 10:43:49

2010-05-27 17:41:09

2022-02-17 08:02:45

对象存储RGW

2020-12-09 05:15:53

对象存储前端
点赞
收藏

51CTO技术栈公众号