Ceph Reef(18.2.X)之Swift操作对象存储网关

本文涉及的产品
对象存储 OSS,20GB 3个月
对象存储 OSS,恶意文件检测 1000次 1年
对象存储 OSS,内容安全 1000次 1年
简介: 这篇文章详细介绍了Ceph Reef(18.2.X)中通过Swift API操作对象存储网关的方法,包括创建用户、子用户、配置环境变量、以及使用swift命令行工具进行存储桶和对象的管理。

                                              作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.Swift概述

1.Switft API接口概述

swift的用户账号对应radosgw中的subuser(子用户),它隶属于某个事先存在的user(用户账号)。

Swift API的上下文中,存储桶以container表示,而非S3中的bucket,但二者在功能上相似,都是对象数据的容器。

Python swiftclient时一个用于和swift API交互的python客户端程序,它包含了Python API(swift模块)和一个swift命令。

swift命令可以通过Swift API完成容器和对象数据的管理操作。

2.swift实现的基本逻辑

- 1.创建专属的用户名和子用户授权;
- 2.安装专属的客户端命令和python模块;
- 3.配置专属的认证配置文件;
- 4.综合测试swift的资源对象管理;

二.swift命令行配置实战

1.创建swift的实践用户

    1.创建账号
[root@ceph141 ~]# radosgw-admin user create --uid "yinzhengjie" --display-name "尹正杰"
{
    "user_id": "yinzhengjie",
    "display_name": "尹正杰",
    "email": "",
    "suspended": 0,
    "max_buckets": 1000,
    "subusers": [],
    "keys": [
        {
            "user": "yinzhengjie",
            "access_key": "M25RJ5F8XLNVUY4ORF6Z",
            "secret_key": "lk7c4eNCAkTOfaI3BuOcct70peebF2CCPUKpR6s5"
        }
    ],
    "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": []
}

[root@ceph141 ~]# 


    2.查看账号列表
[root@ceph141 ~]# radosgw-admin user list
[
    "dashboard",
    "yinzhengjie"
]
[root@ceph141 ~]#

2.基于现有用户创建子用户

[root@ceph141 ~]# radosgw-admin subuser create --uid yinzhengjie --subuser=yinzhengjie:swift --access=full
{
    "user_id": "yinzhengjie",
    "display_name": "尹正杰",
    "email": "",
    "suspended": 0,
    "max_buckets": 1000,
    "subusers": [
        {
            "id": "yinzhengjie:swift",
            "permissions": "full-control"
        }
    ],
    "keys": [
        {
            "user": "yinzhengjie",
            "access_key": "M25RJ5F8XLNVUY4ORF6Z",
            "secret_key": "lk7c4eNCAkTOfaI3BuOcct70peebF2CCPUKpR6s5"
        }
    ],
    "swift_keys": [
        {
            "user": "yinzhengjie:swift",
            "secret_key": "JW9ZWMFX7fZsiaWVMBvbg1q8JA5NA4FA69Ab6z4W"
        }
    ],
    "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": []
}

[root@ceph141 ~]#

3.基于子用户生成secret_key信息

[root@ceph141 ~]# radosgw-admin key create --subuser=yinzhengjie:swift --key-type=swift --gen-secret
{
    "user_id": "yinzhengjie",
    "display_name": "尹正杰",
    "email": "",
    "suspended": 0,
    "max_buckets": 1000,
    "subusers": [
        {
            "id": "yinzhengjie:swift",
            "permissions": "full-control"
        }
    ],
    "keys": [
        {
            "user": "yinzhengjie",
            "access_key": "M25RJ5F8XLNVUY4ORF6Z",
            "secret_key": "lk7c4eNCAkTOfaI3BuOcct70peebF2CCPUKpR6s5"
        }
    ],
    "swift_keys": [
        {
            "user": "yinzhengjie:swift",
            "secret_key": "trAYFVL6Gb26BLLqdaDznoS1vhBfs1ZR8K18jUjR"
        }
    ],
    "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": []
}

[root@ceph141 ~]#

4.安装swift命令

    1.安装工具包
[root@ceph141 ~]# apt -y install python-setuptools python3-pip

    2.安装python-swiftclient
[root@ceph141 ~]# pip install python-swiftclient==4.6.0


温馨提示:
    - 1.安装swiftclient命令时一定要注意版本python 3.6+
    - 2.swiftclient官方链接: 
        https://pypi.org/project/python-swiftclient/    
    - 3.swift命令格式解析:
        swift -A 认证URL/auth -U 用户名:swift -K secret_key COMMAND

5.配置swift的环境变量

    1.如上图所示,swift命令测试效果没有需配置环境变量,但是会让命令后很长
[root@ceph141 ~]# s3cmd ls s3://yinzhengjie-rgw/
2024-08-29 23:55           35  s3://yinzhengjie-rgw/blog.txt
[root@ceph141 ~]# 
[root@ceph141 ~]# swift -A http://ceph142/auth -U yinzhengjie:swift -K trAYFVL6Gb26BLLqdaDznoS1vhBfs1ZR8K18jUjR list yinzhengjie-rgw
blog.txt
[root@ceph141 ~]# 


    2.配置swift环境变量
[root@ceph141 ~]# cat > ~/.swift <<EOF
export ST_AUTH=http://ceph142/auth
export ST_USER=yinzhengjie:swift
export ST_KEY=trAYFVL6Gb26BLLqdaDznoS1vhBfs1ZR8K18jUjR
EOF
[root@ceph141 ~]# 
[root@ceph141 ~]# source ~/.swift 
[root@ceph141 ~]# 

    3.如下图所示,测试效果很明显,无需在命令行中加一堆参数啦
[root@ceph141 ~]# swift list  # 查看所有的存储桶
yinzhengjie-rgw
[root@ceph141 ~]# 
[root@ceph141 ~]# swift list yinzhengjie-rgw  # 查看指定存储桶的对象名称
blog.txt
[root@ceph141 ~]# 
[root@ceph141 ~]# swift stat
                                    Account: v1
                                 Containers: 1
                                    Objects: 1
                                      Bytes: 35
   Containers in policy "default-placement": 1
      Objects in policy "default-placement": 1
        Bytes in policy "default-placement": 35
Objects in policy "default-placement-bytes": 0
  Bytes in policy "default-placement-bytes": 0
                                X-Timestamp: 1725028907.96608
                X-Account-Bytes-Used-Actual: 4096
                                 X-Trans-Id: tx000003b4b5d13346aa241-0066d1da2b-12179-default
                     X-Openstack-Request-Id: tx000003b4b5d13346aa241-0066d1da2b-12179-default
                              Accept-Ranges: bytes
                               Content-Type: text/plain; charset=utf-8
                                 Connection: Keep-Alive
[root@ceph141 ~]#

三swift常用的命令实操

1.查看存储桶列表

[root@ceph141 ~]# swift list 
yinzhengjie-rgw
[root@ceph141 ~]#
[root@ceph141 ~]# swift list yinzhengjie-rgw  # 查看指定存储桶的对象
blog.txt
[root@ceph141 ~]#

2.创建存储桶

[root@ceph141 ~]# swift post yinzhengjie-swift
[root@ceph141 ~]# 
[root@ceph141 ~]# swift list 
yinzhengjie-rgw
yinzhengjie-swift
[root@ceph141 ~]#

3.删除存储桶

[root@ceph141 ~]# swift delete yinzhengjie-swift
yinzhengjie-swift
[root@ceph141 ~]# 
[root@ceph141 ~]# swift list 
yinzhengjie-rgw
[root@ceph141 ~]#

4.上传文件或目录

    1.上传文件
[root@ceph141 ~]# swift list yinzhengjie-rgw
blog.txt
[root@ceph141 ~]# 
[root@ceph141 ~]# swift upload yinzhengjie-rgw /etc/os-release 
etc/os-release
[root@ceph141 ~]# 
[root@ceph141 ~]# swift list yinzhengjie-rgw
blog.txt
etc/os-release
[root@ceph141 ~]# 


    2.上传目录,和上传文件相同
[root@ceph141 ~]# ls /yinzhengjie/ -R
/yinzhengjie/:
data

/yinzhengjie/data:
rbd0  rbd1  rbd2  wp01

/yinzhengjie/data/rbd0:

/yinzhengjie/data/rbd1:

/yinzhengjie/data/rbd2:

/yinzhengjie/data/wp01:
[root@ceph141 ~]# 
[root@ceph141 ~]# swift upload yinzhengjie-rgw /yinzhengjie
yinzhengjie/data/rbd1
yinzhengjie/data/rbd2
yinzhengjie/data/rbd0
yinzhengjie/data/wp01
[root@ceph141 ~]#
[root@ceph141 ~]# swift list yinzhengjie-rgw
blog.txt
etc/os-release
yinzhengjie/data/rbd0
yinzhengjie/data/rbd1
yinzhengjie/data/rbd2
yinzhengjie/data/wp01
[root@ceph141 ~]#

5.下载文件或目录

    1.下载文件
[root@ceph141 ~]# swift download yinzhengjie-rgw etc/os-release
etc/os-release [auth 0.005s, headers 0.015s, total 0.015s, 0.036 MB/s]
[root@ceph141 ~]# 
[root@ceph141 ~]# ll etc/os-release 
-rw-r--r-- 1 root root 386 Feb 14  2024 etc/os-release
[root@ceph141 ~]# 


    2.下载目录
[root@ceph141 ~]# swift download yinzhengjie-rgw --prefix='yinzhengjie/data'
yinzhengjie/data/wp01 [auth 0.007s, headers 0.018s, total 0.019s, 0.000 MB/s]
yinzhengjie/data/rbd1 [auth 0.012s, headers 0.023s, total 0.025s, 0.000 MB/s]
yinzhengjie/data/rbd0 [auth 0.009s, headers 0.019s, total 0.019s, 0.000 MB/s]
yinzhengjie/data/rbd2 [auth 0.014s, headers 0.021s, total 0.022s, 0.000 MB/s]
[root@ceph141 ~]# 
[root@ceph141 ~]# ll yinzhengjie/data/
total 24
drwxr-xr-x 6 root root 4096 Aug 30 23:30 ./
drwxr-xr-x 3 root root 4096 Aug 30 23:30 ../
drwxr-xr-x 2 root root 4096 Aug 30 23:30 rbd0/
drwxr-xr-x 2 root root 4096 Aug 30 23:30 rbd1/
drwxr-xr-x 2 root root 4096 Aug 30 23:30 rbd2/
drwxr-xr-x 2 root root 4096 Aug 30 23:30 wp01/
[root@ceph141 ~]# 

    3.下载所有
[root@ceph141 ~]# swift download --all

6.删除文件或目录

    1.删除文件
[root@ceph141 ~]# swift list yinzhengjie-rgw
blog.txt
etc/os-release
yinzhengjie/data/rbd0
yinzhengjie/data/rbd1
yinzhengjie/data/rbd2
yinzhengjie/data/wp01
[root@ceph141 ~]# 
[root@ceph141 ~]# swift delete yinzhengjie-rgw etc/os-release
etc/os-release
[root@ceph141 ~]# 
[root@ceph141 ~]# swift list yinzhengjie-rgw
blog.txt
yinzhengjie/data/rbd0
yinzhengjie/data/rbd1
yinzhengjie/data/rbd2
yinzhengjie/data/wp01
[root@ceph141 ~]# 

    2.删除目录
[root@ceph141 ~]# swift list yinzhengjie-rgw
blog.txt
yinzhengjie/data/rbd0
yinzhengjie/data/rbd1
yinzhengjie/data/rbd2
yinzhengjie/data/wp01
[root@ceph141 ~]# 
[root@ceph141 ~]# swift delete yinzhengjie-rgw --prefix='yinzhengjie/data'
yinzhengjie/data/rbd1
yinzhengjie/data/rbd2
yinzhengjie/data/rbd0
yinzhengjie/data/wp01
[root@ceph141 ~]# 
[root@ceph141 ~]# swift list yinzhengjie-rgw
blog.txt
[root@ceph141 ~]# 

    3.删除所有存储桶
[root@ceph141 ~]# swift delete --all
yinzhengjie-rgw/blog.txt
yinzhengjie-rgw
[root@ceph141 ~]# 
[root@ceph141 ~]# swift list 
[root@ceph141 ~]#
相关实践学习
借助OSS搭建在线教育视频课程分享网站
本教程介绍如何基于云服务器ECS和对象存储OSS,搭建一个在线教育视频课程分享网站。
目录
相关文章
|
4月前
|
存储 Cloud Native API
oss云网关配置
配置阿里云OSS与云网关实现灵活数据传输和访问控制。步骤包括开通OSS服务,创建Bucket,获取访问凭证,可选配置CORS和生命周期规则。云网关配置涉及阿里云云原生网关的代理规则设定或使用云存储网关集成OSS访问,具体配置需参照产品文档,因产品更新可能会有变动。
77 1
|
11天前
|
存储 对象存储
Ceph Reef(18.2.X)的对象存储网关(rgw)组件搭建
这篇文章是关于Ceph Reef(18.2.X)版本中对象存储系统的配置和使用案例,包括对象存储网关的概述、核心资源介绍、Ceph RGW支持的接口、高可用radosgw的部署、s3cmd工具的使用以及如何通过HTTP方式访问对象存储。
29 3
Ceph Reef(18.2.X)的对象存储网关(rgw)组件搭建
|
12天前
|
存储 对象存储
radosgw高可用对象存储网关实战指南
关于radosgw高可用对象存储网关的实战指南,涵盖了从基本概念到具体操作案例,再到架构设计和使用技巧的全面介绍。
44 6
|
11天前
|
对象存储 Python
Ceph Reef(18.2.X)之python操作对象存储网关
这篇文章介绍了如何在Ceph Reef(18.2.X)环境中使用Python操作对象存储网关(rgw),包括环境搭建、账号创建、使用s3cmd工具以及编写和测试Python代码。
29 3
|
2月前
|
存储 关系型数据库 算法框架/工具
Ceph对象网关,多区域网关
Ceph对象网关,多区域网关
37 6
|
2月前
|
机器学习/深度学习 人工智能 专有云
人工智能平台PAI使用问题之怎么将DLC的数据写入到另一个阿里云主账号的OSS中
阿里云人工智能平台PAI是一个功能强大、易于使用的AI开发平台,旨在降低AI开发门槛,加速创新,助力企业和开发者高效构建、部署和管理人工智能应用。其中包含了一系列相互协同的产品与服务,共同构成一个完整的人工智能开发与应用生态系统。以下是对PAI产品使用合集的概述,涵盖数据处理、模型开发、训练加速、模型部署及管理等多个环节。
|
1月前
|
存储 机器学习/深度学习 弹性计算
阿里云EMR数据湖文件系统问题之OSS-HDFS全托管服务的问题如何解决
阿里云EMR数据湖文件系统问题之OSS-HDFS全托管服务的问题如何解决
|
2月前
|
消息中间件 分布式计算 DataWorks
DataWorks产品使用合集之如何使用Python和阿里云SDK读取OSS中的文件
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。
|
2月前
|
存储 运维 安全
阿里云OSS的优势
【7月更文挑战第19天】阿里云OSS的优势
101 2
|
2月前
|
存储 API 开发工具
阿里云OSS
【7月更文挑战第19天】阿里云OSS
89 1