2.13.3. 测试 S3 访问
您需要编写并运行 Python 测试脚本来验证 S3 访问权限。S3 访问测试脚本将连接到 radosgw,创建一个新 bucket 并列出所有存储桶。aws_access_key_id 和 aws_secret_access_key 的值取自 radosgw key 的值。
_admin 命令返回的 access __key 和 secret
系统用户对整个区域必须具有 root 特权,因为输出中将包含用于维护元数据的其他 json 字段。
先决条件
-
root或sudo访问权限. - 安装了 Ceph 对象网关.
- 已创建的 S3 用户.
流程
为 Red Hat Enterprise Linux 7 启用通用软件仓库和 Red Hat Enterprise Linux 8 的 High Availability 软件仓库:
Red Hat Enterprise Linux 7
# subscription-manager repos --enable=rhel-7-server-rh-common-rpmsRed Hat Enterprise Linux 8
# subscription-manager repos --enable=rhel-8-for-x86_64-highavailability-rpms安装
python-boto软件包。Red Hat Enterprise Linux 7
# yum install python-botoRed Hat Enterprise Linux 8
# dnf install python3-boto3创建 Python 脚本:
vi s3test.py在文件中添加以下内容:
Red Hat Enterprise Linux 7
import boto import boto.s3.connection access_key = 'ACCESS' secret_key = 'SECRET' boto.config.add_section('s3') conn = boto.connect_s3( aws_access_key_id = access_key, aws_secret_access_key = secret_key, host = 's3.ZONE.hostname', port = PORT, is_secure=False, calling_format = boto.s3.connection.OrdinaryCallingFormat(), ) bucket = conn.create_bucket('my-new-bucket') for bucket in conn.get_all_buckets(): print "{name}\t{created}".format( name = bucket.name, created = bucket.creation_date, )Red Hat Enterprise Linux 8
import boto3 endpoint = "" # enter the endpoint URL along with the port "http://URL:_PORT_" access_key = 'ACCESS' secret_key = 'SECRET' s3 = boto3.client( 's3', endpoint_url=endpoint, aws_access_key_id=access_key, aws_secret_access_key=secret_key ) s3.create_bucket(Bucket='my-new-bucket') response = s3.list_buckets() for bucket in response['Buckets']: print("{name}\t{created}".format( name = bucket['Name'], created = bucket['CreationDate'] ))-
将
ZONE替换为您配置网关服务的主机的区域名称。也就是说,网关主机。确保host'setting 使用 DNS 解析。使用网关的端口号替换 'PORT。 -
使用《 红帽 Ceph 存储对象网关配置和管理指南》的" 创建 S3 用户" 部分中的
access值替换_key和 secret_keyACCESS和SECRET。
-
将
运行脚本:
Red Hat Enterprise Linux 7
python s3test.pyRed Hat Enterprise Linux 8
python3 s3test.py输出示例:
my-new-bucket 2021-08-16T17:09:10.000Z