Ceph configure S3 and swift interfaces to access the cluster
To use the REST interface, we first create an initial Ceph object gateway user for the S3 interface, then create a sub-user for the Swift interface, and finally, we need to verify that the created user can access the gateway.
Create a radosgw user to access the S3 interface
Execute the following command to create a user, and record access_key and secret_key. It doesn't matter if you don't remember, you can use radosgw-admin user info-- uid=s3 to view it.
[root@ceph-node1] # radosgw-admin user create-- uid= "S3"-- display-name= "S3 user"
{
"user_id": "S3"
"display_name": "S3 user"
"email":
"suspended": 0
"max_buckets": 1000
"auid": 0
"subusers": []
"keys": [
{
"user": "S3"
"access_key": "WNXRGPK6XGWO8XRLWRUA"
"secret_key": "Segqx8fZ8H5arM1Pvpygiewp4gl9Qjkrymi09aVP"
}
]
"swift_keys": []
"caps": []
"op_mask": "read, write, delete"
"default_placement":
"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": []
}
Create a radosgw user to access the swift interface
To access the swift interface, you need to create a Swift sub-user and record the secret_key of s3:swift.
[root@ceph-node1] # radosgw-admin subuser create-uid=s3-subuser=s3:swift-access=full
{
"user_id": "S3"
"display_name": "S3 user"
"email":
"suspended": 0
"max_buckets": 1000
"auid": 0
"subusers": [
{
"id": "s3:swift"
"permissions": "full-control"
}
]
"keys": [
{
"user": "S3"
"access_key": "WNXRGPK6XGWO8XRLWRUA"
"secret_key": "Segqx8fZ8H5arM1Pvpygiewp4gl9Qjkrymi09aVP"
}
]
"swift_keys": [
{
"user": "s3:swift"
"secret_key": "czb1ExW6XRy7iE41gFLL0xQNlamLLc569DC9FG1r"
}
]
"caps": []
"op_mask": "read, write, delete"
"default_placement":
"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": []
}
Test S3 interface
We need to write and run a Python test script to verify S3 access. The S3 access test script will connect to radosgw, create a new bucket and list all buckets. The values of access_key_id and secret_access_key are taken from the access_key and secret_key values of the S3 user returned by the radosgw-admin command. We also need to modify the hostname (host) and port (port).
[root@ceph-node1 ~] yum install python-boto-y
[root@ceph-node1 ~] vim s3test.py
Import botoimport boto.s3.connectionaccess_key = 'WNXRGPK6XGWO8XRLWRUA'secret_key =' Segqx8fZ8H5arM1Pvpygiewp4gl9Qjkrymi09aVP'conn = boto.connect_s3 (aws_access_key_id = access_key, aws_secret_access_key = secret_key, host = 'ceph-node1', port=7480, is_secure=False, calling_format = boto.s3.connection.OrdinaryCallingFormat () ) bucket = conn.create_bucket ('my-first-s3-bucket') for bucket in conn.get_all_buckets (): print "{name}\ t {created}" .format (name = bucket.name, created = bucket.creation_date,)
Root@ceph-node1 ~] python s3test.py
My-first-s3-bucket 2019-12-13T02:58:44.604Z
You can also use s3cmd as a command line tool
Root@ceph-node1 ~] yum install s3cmd-y
Root@ceph-node1 ~] s3cmd-- configure
In the configuration, you need to enter the secret_key and access_key of S3 users, as well as S3 Endpoint and target Amazon S3, the hostnames and ports of the two hosts that enter radosgw, such as ceph-node1:7480
Root@ceph-node1 ~] s3cmd ls # View existing bucket
2019-12-13 02:58 s3://my-first-s3-bucket
Root@ceph-node1 ~] s3cmd mb s3://my-second-s3-bucket # create a bucket
Root@ceph-node1 ~] s3cmd put / etc/hosts s3://my-second-s3-bucket # put a file in the bucket you just created
[root@ceph-node1] # s3cmd ls s3://my-second-s3-bucket # View the files in the bucket
2019-12-13 03:08 575 s3://my-second-s3-bucket/hosts
Test the swift interface
Root@ceph-node1 ~] yum install python-pip-y
Root@ceph-node1 ~] pip install-- upgrade python-swiftclient
Create a bucket
[root@liuning S3] # swift- A http://glusterfs-node1:7480/auth/1.0-U s3:swift-K e58xcqROWx2bMMSo36KnNWUYpEUrdPbDruNWezqr post my-first-swift-bucket
Use the swift interface to view the existing bucket
[root@liuning S3] # swift-A http://glusterfs-node1:7480/auth/1.0-U s3:swift-K e58xcqROWx2bMMSo36KnNWUYpEUrdPbDruNWezqr list
My-first-s3-bucket
My-first-swift-bucket
My-second-s3-bucket
Note that the following error may occur. Just wait a moment. If not, delete the previous user and create a new one, using the new secret_key.
Auth GET failed: http://ceph-node1:7480/auth/1.0 403 Forbidden [first 60 chars of response] {"Code": "AccessDenied", "RequestId": "tx000000000000000000013-"
Failed Transaction ID: tx000000000000000000013-005df3022d-e2a1-default
At this point, the construction and testing of S3 and swift interfaces have been completed. For more use examples and api, please refer to the official website of man or ceph.