四、swift大对象--静态态大对象
系列导航
六、java操作swift对象存储(resultful方式实现)
上一章讲解了如何使用动态的大对象,这一章讲解静态大对象。动态大对象和静态大对象有什么区别呢,个人感觉动态大对象的分段存储是由swift帮你完成的,你能操作的空间比较小必须按照它的规则去实现。静态大对象分段信息如何存放比较灵活但是切分数据和存储分段信息要由开发者来完成。两种都可以根据自己的需求去选择吧。
一、你的swift存储是否支持静态大对象。
执行语句: curl http://192.168.22.2:8080/info | python -mjson.tool
如果有红色slo部分说明你的存储已经支持静态大对象。
如果没有需要进行如下配置:
vi /etc/swift/proxy-server.conf
如下两个地方增加slo的服务 注:要注意顺序 顺序错了会报错
#把slo加进去
[pipeline:main]
pipeline = healthcheck cache tempauth proxy-logging slo proxy-server
[filter:slo]
use = egg:swift#slo
max_manifest_segments = 1000
max_manifest_size = 2097152
min_segment_size = 1048576
二、静态大对象实验
1、创建容器
swift -A http://127.0.0.1:8080/auth/v1.0 -U admin:admin -K admin post StaticContainer
2、查看容器
swift -A http://127.0.0.1:8080/auth/v1.0 -U admin:admin -K admin list
swift -A http://127.0.0.1:8080/auth/v1.0 -U admin:admin -K admin list StaticContainer
3、获取口令码
curl http://127.0.0.1:8080/auth/v1.0 -v -H 'X-Storage-User: admin:admin' -H 'X-Storage-Pass: admin'
4、切割
cd /opt
切割harbor-offline-installer-v1.5.0.tgz
split -b 200m harbor-offline-installer-v1.5.0.tgz segment_
5、上传分片数据
curl -v -X PUT -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" -T /opt/segment_aa -D- http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/segment_aa
curl -v -X PUT -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" -T /opt/segment_ab -D- http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/segment_ab
curl -v -X PUT -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" -T /opt/segment_ac -D- http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/segment_ac
curl -v -X PUT -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" -T /opt/segment_ad -D- http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/segment_ad
curl -v -X PUT -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" -T /opt/segment_ae -D- http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/segment_ae
查看属性
curl -v -X HEAD -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/segment_aa
curl -v -X HEAD -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/segment_ab
curl -v -X HEAD -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/segment_ac
curl -v -X HEAD -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/segment_ad
curl -v -X HEAD -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/segment_ae
6、创建分片分布信息
manifest.json 内容如下
[
{
"path": "StaticContainer/segment_aa",
"etag": "568b3101e4238291ec42aab183825885",
"size_bytes": 209715200
},
{
"path": "StaticContainer/segment_ab",
"etag": "3ca840e3027e38b8dd72e3a58e079325",
"size_bytes": 209715200
},
{
"path": "StaticContainer/segment_ac",
"etag": "aa32d6c5299aff1968373d06f986d032",
"size_bytes": 209715200
},
{
"path": "StaticContainer/segment_ad",
"etag": "54f6cbe2f6b304bf3cb7e8b4af7dd90d",
"size_bytes": 209715200
},
{
"path": "StaticContainer/segment_ae",
"etag": "d20d5fc6702590a9da38c086218749e6",
"size_bytes": 24886405
}
]
7、上传manifest 分片信息
curl -v -X PUT -H "X-Static-Large-Object: true" -H "X-Auth-Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" "http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/myLargeFile?multipart-manifest=put&heartbeat=on" -T /opt/manifest.json
8、验证分段的数据是否正确
curl -v -X HEAD -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" "http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/myLargeFile"
9、下载大对象
curl -v -X GET -H "X-Auth-Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" "http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/myLargeFile" -o /opt/myLargeFile
10、下载大对象的manifest文件内容
curl -v -X GET -H "X-Auth-Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" "http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/myLargeFile?multipart-manifest=get" -o ./manifestFile
11、删除测试
swift -A http://127.0.0.1:8080/auth/v1.0 -U admin:admin -K admin delete StaticContainer myLargeFile --整个文件都会被删除包含所有段文件也都删除
curl http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/myLargeFile -v -X DELETE -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" --只删除了myLargeFile,他关联的段文件都还在
curl http://127.0.0.1:8080/v1/AUTH_admin/StaticContainer/myLargeFile?multipart-manifest=delete -v -X DELETE -H "X-Auth_Token: AUTH_tk997cad0b1e13403a81d338b7e80dcc12" --myLargeFile和他关联的段都删除了
官网:https://docs.openstack.org/swift/queens/overview_large_objects.html 注:讲的不太清楚没有样例