Red Hat Training

A Red Hat training course is available for Red Hat Ceph Storage

2.10.3. 测试 S3 访问

您需要编写并运行 Python 测试脚本来验证 S3 访问权限。S3 访问测试脚本将连接到 radosgw,创建一个新 bucket 并列出所有存储桶。aws_access_key_idaws_secret_access_key 的值取自 radosgw _admin 命令返回的 access _key 和 secret _ key 的值。

执行以下步骤:

  1. 启用 common 存储库。

    # subscription-manager repos --enable=rhel-7-server-rh-common-rpms
  2. 安装 python-boto 软件包。

    sudo yum install python-boto
  3. 创建 Python 脚本:

    vi s3test.py
  4. 在文件中添加以下内容:

    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,
    )
    1. <zone> 替换为您配置网关服务的主机的区域名称。也就是说,网关主机。确保 主机 设置通过 DNS 解析。将 <port> 替换为网关的端口号。
    2. $access$secret 替换为 Create an S3 User 部分中的 access _key 和 secret_key 值。
  5. 运行脚本:

    python s3test.py

    输出结果类似如下:

    my-new-bucket 2015-02-16T17:09:10.000Z