二、swift添加存储策略
系列导航
六、java操作swift对象存储(resultful方式实现)
上一章swift的安装中默认的存储策略是3副本,有的时候数据不是很重要,为了节约存储空间,可以同时设置另一种存储策略比如两副本,在创建容器的时候只要选择存储策略即可。那么如何实现呢请继续向下看。
一、存储策略添加新的策略(一台机器搞好同步到其他机器上)
1、vi /etc/swift/swift.conf
添加如下内容(注:原来的存储策略是policy:0,新增的是policy:1)
[storage-policy:0]
name = gold
default = yes
[storage-policy:1]
name = silver
2、给新的策略生成新的ring
cd /etc/swift
#注:这里设置副本数为2 这里的object-1 的-1跟storage-policy:1中的1是对应的一定要设置对
swift-ring-builder object-1.builder create 18 2 1
swift-ring-builder object-1.builder add z1-192.168.0.1:6000/sdb2 100
swift-ring-builder object-1.builder add z2-192.168.0.2:6000/sdb2 100
swift-ring-builder object-1.builder add z3-192.168.0.3:6000/sdb2 100
确认
swift-ring-builder object-1.builder
生成ring
swift-ring-builder object-1.builder rebalance
3、将/opt/soft/swift/etc 下的 container-reconciler.conf-sample 拷贝到 /etc/swift/下 重命名为container-reconciler.conf
cd /etc/swift
mv container-reconciler.conf-sample container-reconciler.conf
修改文件内容
sed -i "s/# user.*/user = $USER/g" /etc/swift/container-reconciler.conf
4、 vi /etc/swift/proxy-server.conf
如下添加 list-endpoints
[pipeline:main]
pipeline = healthcheck cache tempauth proxy-logging slo list-endpoints proxy-server
[filter:list-endpoints]
use = egg:swift#list_endpoints
5、启动服务查看存储策略有哪些
swift -A http://127.0.0.1:8080/auth/v1.0 -U admin:admin -K admin info
存储策略相关的内容如下:
policies: [{'default': True, 'name': 'gold'}, {'name': 'silver'}]
五、验证
------------------按照默认策略policy:0 创建容器 并向里放入文件-------------------
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 containerpolicy0
curl http://127.0.0.1:8080/auth/v1.0 -v -H 'X-Storage-User: admin:admin' -H 'X-Storage-Pass: admin'
curl http://127.0.0.1:8080/v1/AUTH_admin/containerpolicy0 -X PUT -H "X-Auth_Token: AUTH_tk7c21eddae31d449db36a5e8596d0cb71"
curl http://127.0.0.1:8080/v1/AUTH_admin/containerpolicy0/1.txt -X PUT -T 1.txt -H "X-Auth_Token: AUTH_tk7c21eddae31d449db36a5e8596d0cb71"
查看对象存储的位置
curl -X GET -v http://127.0.0.1:8080/endpoints/AUTH_admin/containerpolicy0/1.txt
"http://192.168.0.2:6000/sdb1/66136/AUTH_admin/containerpolicy0/1.txt",
"http://192.168.0.3:6000/sdb1/66136/AUTH_admin/containerpolicy0/1.txt",
"http://192.168.0.1:6000/sdb1/66136/AUTH_admin/containerpolicy0/1.txt
客户端方式查看
swift-get-nodes -a /etc/swift/object.ring.gz AUTH_admin containerpolicy0 1.txt
ssh 192.168.0.2 "ls -lah ${DEVICE:-/srv/node*}/sdb1/objects/66136/e0e/40960127e639c0aa7960174fe4fb8e0e"
ssh 192.168.0.3 "ls -lah ${DEVICE:-/srv/node*}/sdb1/objects/66136/e0e/40960127e639c0aa7960174fe4fb8e0e"
ssh 192.168.0.1 "ls -lah ${DEVICE:-/srv/node*}/sdb1/objects/66136/e0e/40960127e639c0aa7960174fe4fb8e0e"
---------------------------按照策略policy:1 创建容器 并向里放入文件-----------------------------
curl http://127.0.0.1:8080/v1/AUTH_admin/containerpolicy1 -X PUT -H "X-Auth_Token: AUTH_tk7c21eddae31d449db36a5e8596d0cb71" -H "X-Storage-Policy: silver"
curl http://127.0.0.1:8080/v1/AUTH_admin/containerpolicy1/2.txt -X PUT -T 2.txt -H "X-Auth_Token: AUTH_tk7c21eddae31d449db36a5e8596d0cb71"
curl -X GET -v http://127.0.0.1:8080/endpoints/AUTH_admin/containerpolicy1/2.txt
"http://192.168.0.1:6000/sdb1/79293/AUTH_admin/containerpolicy1/2.txt",
"http://192.168.0.2:6000/sdb2/79293/AUTH_admin/containerpolicy1/2.txt"
swift-get-nodes -a /etc/swift/object-1.ring.gz AUTH_admin containerpolicy1 2.txt
ssh 192.168.0.1 "ls -lah ${DEVICE:-/srv/node*}/sdb1/objects-1/79293/214/4d6f4a719bb4c01687c4e7840ac36214"
ssh 192.168.0.2 "ls -lah ${DEVICE:-/srv/node*}/sdb2/objects-1/79293/214/4d6f4a719bb4c01687c4e7840ac36214"
六、查看所有的存储信息 如下两种方法都可以
curl -i -X HEAD -H 'X-Auth-Token: AUTH_tk7c21eddae31d449db36a5e8596d0cb71' http://127.0.0.1:8080/v1/AUTH_admin
swift -A http://127.0.0.1:8080/auth/v1.0 -U admin:admin -K admin stat
补充:查看容器存放的物理位置
curl -X GET -v http://127.0.0.1:8080/endpoints/AUTH_admin/jyzSfzContainer
客户端方式查看
swift-get-nodes -a /etc/swift/object.ring.gz AUTH_admin jyzSfzContainer