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

news/2024/10/5 5:24:00

                                              作者:尹正杰

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

目录
  • 一.Swift概述
    • 1.Switft API接口概述
    • 2.swift实现的基本逻辑
  • 二.swift命令行配置实战
    • 1.创建swift的实践用户
    • 2.基于现有用户创建子用户
    • 3.基于子用户生成secret_key信息
    • 4.安装swift命令
    • 5.配置swift的环境变量
  • 三swift常用的命令实操
    • 1.查看存储桶列表
    • 2.创建存储桶
    • 3.删除存储桶
    • 4.上传文件或目录
    • 5.下载文件或目录
    • 6.删除文件或目录

一.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-pip2.安装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 statAccount: v1Containers: 1Objects: 1Bytes: 35Containers in policy "default-placement": 1Objects in policy "default-placement": 1Bytes in policy "default-placement": 35
Objects in policy "default-placement-bytes": 0Bytes in policy "default-placement-bytes": 0X-Timestamp: 1725028907.96608X-Account-Bytes-Used-Actual: 4096X-Trans-Id: tx000003b4b5d13346aa241-0066d1da2b-12179-defaultX-Openstack-Request-Id: tx000003b4b5d13346aa241-0066d1da2b-12179-defaultAccept-Ranges: bytesContent-Type: text/plain; charset=utf-8Connection: 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 ~]# 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.ryyt.cn/news/54864.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

【靶场搭建】搭建Metasploitable2漏洞靶场

原创 Kali与编程NEW有学员问我,如何合法进行渗透测试,总不能拿真实的网站来练手,一来成功率不高,二来容易被请喝茶。 其实很简单,自己搭建实验靶场,尽情把完,不犯法! Metasploitable2 是基于 Ubuntu 操作系统构建的,它故意配置了大量已知的安全漏洞,这次我就教会你如…

代码随想录算法day4 - 链表2

题目1 24. 两两交换链表中的节点 给你一个链表,两两交换其中相邻的节点,并返回交换后链表的头节点。你必须在不修改节点内部的值的情况下完成本题(即,只能进行节点交换)。 示例 1:输入:head = [1,2,3,4] 输出:[2,1,4,3]示例 2: 输入:head = [] 输出:[]示例 3: 输入…

【Shell脚本】查看Linux网卡实时流量

原创 唐哥 成长的小学生在Linux操作系统中,查询网卡流量并不是特别方便,而且统计方式也不直观,下面给大家整理了一个脚本,直接复制到服务器上运行即可,不存在什么依赖关系。脚本内容 将内容保存到一个文件中,文件名称可以自定义,比如:vi catnet.sh将以下内容保存到脚本…

.Net 5.0 WebAPI 发布至 CentOS 7 系统

本文先安装 .net 5.0 的环境,再创建一个示例项目并发布至 CentOS 上,同时列明了一些注意的点;最后将 dotnet 命令添加到系统自启动服务。〇、前言 本文主要介绍了在 CentOS 7 上部署 WebAPI 项目的过程。 先安装 .net 5.0 的环境,再创建一个示例项目并发布至 CentOS 上,同…

高德地图,只有部分marker显示InfoWindow并可点击

高德地图,只有部分marker显示InfoWindow并可点击 原因: 加了 MarkerCluster 之后,出现不稳定现象“有部分marker显示InfoWindow并可点击”。// 将所有的标记点添加到marker cluster // marker cluster// markerLayer.setMarkers(markers); // marker cluster // th…

【漏洞分析】OSN 代币攻击事件:一笔资金伪造多个分红大户

背景 OSN 是一种 fee on transfer 代币,会根据用户分红账户的余额对用户发放分红。攻击者利用漏洞增发分红账户的余额,随后触发分红机制完成获利。 OSN:https://bscscan.com/address/0x810f4c6ae97bcc66da5ae6383cc31bd3670f6d13#code 攻击由三笔交易组成:https://app.bloc…

IDEA 使用教程

概述 视频教程:【尚硅谷IDEA安装idea实战教程(百万播放,新版来袭)】 jetbrains 中文官网 IDEA 官网 IDEA 从 IDEA 2022.1 版本开始支持 JDK 17,也就是说如果想要使用 JDK 17,那么就要下载 IDEA 2022.1 或者之后的版本。 Jetbrains 公司旗下还有其它产品,比如:WebStorm:…