作者:尹正傑
版權宣告:原創作品,謝絕轉載!否則將追究法律責任。
目錄
- 一.環境準備
- 1.Ceph Reef(18.2.X)的物件儲存閘道器(rgw)元件搭建
- 2.建立賬號
- 3.s3cmd工具
- 二.Python操作物件儲存
- 1.安裝python環境
- 2.編寫python程式
- 3.測試python程式碼
一.環境準備
1.Ceph Reef(18.2.X)的物件儲存閘道器(rgw)元件搭建
推薦閱讀:
https://www.cnblogs.com/yinzhengjie/p/18377291
2.建立賬號
[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 ~]#
3.s3cmd工具
1.安裝s3cmd
apt -y install s3cmd
2.檢視rgw所在節點
[root@ceph141 ~]# ceph orch ls | grep rgw
rgw.yinzhengjie ?:80 1/1 10m ago 31m ceph142
[root@ceph141 ~]#
[root@ceph141 ~]# echo 172.30.100.142 www.yinzhengjie.com >> /etc/hosts
[root@ceph141 ~]#
3.執行s3cmd的執行環境,生成"/root/.s3cfg"配置檔案
[root@ceph141 ~]# s3cmd --configure
Enter new values or accept defaults in brackets with Enter.
Refer to user manual for detailed description of all options.
Access key and Secret key are your identifiers for Amazon S3. Leave them empty for using the env variables.
Access Key: M25RJ5F8XLNVUY4ORF6Z
Secret Key: lk7c4eNCAkTOfaI3BuOcct70peebF2CCPUKpR6s5
Default Region [US]:
Use "s3.amazonaws.com" for S3 Endpoint and not modify it to the target Amazon S3.
S3 Endpoint [s3.amazonaws.com]: www.yinzhengjie.com
Use "%(bucket)s.s3.amazonaws.com" to the target Amazon S3. "%(bucket)s" and "%(location)s" vars can be used
if the target S3 system supports dns based buckets.
DNS-style bucket+hostname:port template for accessing a bucket [%(bucket)s.s3.amazonaws.com]: www.yinzhengjie.com/%(bucket)
Encryption password is used to protect your files from reading
by unauthorized persons while in transfer to S3
Encryption password:
Path to GPG program [/usr/bin/gpg]:
When using secure HTTPS protocol all communication with Amazon S3
servers is protected from 3rd party eavesdropping. This method is
slower than plain HTTP, and can only be proxied with Python 2.7 or newer
Use HTTPS protocol [Yes]: No
On some networks all internet access must go through a HTTP proxy.
Try setting it here if you can't connect to S3 directly
HTTP Proxy server name:
New settings:
Access Key: M25RJ5F8XLNVUY4ORF6Z
Secret Key: lk7c4eNCAkTOfaI3BuOcct70peebF2CCPUKpR6s5
Default Region: US
S3 Endpoint: www.yinzhengjie.com
DNS-style bucket+hostname:port template for accessing a bucket: www.yinzhengjie.com/%(bucket)
Encryption password:
Path to GPG program: /usr/bin/gpg
Use HTTPS protocol: False
HTTP Proxy server name:
HTTP Proxy server port: 0
Test access with supplied credentials? [Y/n] Y
Please wait, attempting to list all buckets...
Success. Your access key and secret key worked fine :-)
Now verifying that encryption works...
Not configured. Never mind.
Save settings? [y/N] y
Configuration saved to '/root/.s3cfg'
[root@ceph141 ~]#
二.Python操作物件儲存
1.安裝python環境
1.安裝python環境
[root@ceph141 ~]# apt -y install python3
2.配置pip3軟體源
[root@ceph141 ~]# mkdir ~/.pip
[root@ceph141 ~]# vim ~/.pip/pip.conf
[root@ceph141 ~]# cat ~/.pip/pip.conf
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[root@ceph141 ~]#
2.編寫python程式
參考連結:
https://docs.ceph.com/en/latest/radosgw/s3/python/
3.測試python程式碼