在开始对象存储服务前,必须先建立初始的account,container和object环(ring)。html
account服务器使用account ring来保存container列表。git
在controller节点上进行如下操做。github
/etc/swift
目录。account.builder
文件:# swift-ring-builder account.builder create 10 3 1
各个数字的含义:
10 - 每块区域最大拥有2^10 2^10 (1024)个分区(ode uses to determine and deploy the storage architecture. For simplicity, this guide uses one region and zone with 2^10 (1024) maximum partitions)
3 - 3个副本
1 - 移动一个分区超过一次时,每次操做间的最小间隔(1 hour minimum time between moving a partition more than once)swift
# swift-ring-builder account.builder add r1z1-STORAGE_NODE_MANAGEMENT_INTERFACE_IP_ADDRESS:6002/DEVICE_NAME DEVICE_WEIGHT
把STORAGE_NODE_MANAGEMENT_INTERFACE_IP_ADDRESS替换为object节点在management网络中的IP地址。把DEVICE_NAME替换为相应存储节点上存储设备的名字。对应每一个存储节点上的存储设备,都重复执行此命令。服务器
在本文的方案下,执行命令以下:
<pre># swift-ring-builder account.builder add r1z1-10.10.10.14:6002/sdb 100
</pre>
Device d0r1z1-10.10.10.14:6002R10.10.10.14:6002/sdb_"" with 100.0 weight got id 0
<pre># swift-ring-builder account.builder add r1z1-10.10.10.14:6002/sdc 100
</pre>
Device d1r1z1-10.10.10.14:6002R10.10.10.14:6002/sdc_"" with 100.0 weight got id 1
<pre># swift-ring-builder account.builder add r1z1-10.10.10.15:6002/sdb 100
</pre>
Device d2r1z1-10.10.10.15:6002R10.10.10.15:6002/sdb_"" with 100.0 weight got id 2
<pre># swift-ring-builder account.builder add r1z1-10.10.10.15:6002/sdc 100
</pre>网络
Device d3r1z1-10.10.10.15:6002R10.10.10.15:6002/sdc_"" with 100.0 weight got id 3
# swift-ring-builder account.builder
account.builder, build version 4
1024 partitions, 3.000000 replicas, 1 regions, 1 zones, 4 devices, 100.00 balance
The minimum number of hours before a partition can be reassigned is 1
Devices: id region zone ip address port replication ip replication port name weight partitions balance metassh
0 1 1 10.10.10.14 6002 10.10.10.14 6002 sdb 100.00 0 -100.00 1 1 1 10.10.10.14 6002 10.10.10.14 6002 sdc 100.00 0 -100.00 2 1 1 10.10.10.15 6002 10.10.10.15 6002 sdb 100.00 0 -100.00 3 1 1 10.10.10.15 6002 10.10.10.15 6002 sdc 100.00 0 -100.00 </code></pre>
# swift-ring-builder account.builder rebalance
Reassigned 1024 (100.00%) partitions. Balance is now 0.00.</pre>
<pre># swift-ring-builder account.builder
curl
account.builder, build version 4
1024 partitions, 3.000000 replicas, 1 regions, 1 zones, 4 devices, 0.00 balance
The minimum number of hours before a partition can be reassigned is 1
Devices: id region zone ip address port replication ip replication port name weight partitions balance meta
0 1 1 10.10.10.14 6002 10.10.10.14 6002 sdb 100.00 768 0.00 1 1 1 10.10.10.14 6002 10.10.10.14 6002 sdc 100.00 768 0.00 2 1 1 10.10.10.15 6002 10.10.10.15 6002 sdb 100.00 768 0.00 3 1 1 10.10.10.15 6002 10.10.10.15 6002 sdc 100.00 768 0.00 </code></pre>
container服务器使用container ring来保存object列表,但并不追踪object的位置。ide
在controller节点上进行如下操做。memcached
/etc/swift
目录。container.builder
文件:# swift-ring-builder container.builder create 10 3 1
# swift-ring-builder container.builder add r1z1-STORAGE_NODE_MANAGEMENT_INTERFACE_IP_ADDRESS:6001/DEVICE_NAME DEVICE_WEIGHT
在本文的方案下,执行命令以下:
<pre># swift-ring-builder container.builder add r1z1-10.10.10.14:6001/sdb 100
Device d0r1z1-10.10.10.14:6001R10.10.10.14:6001/sdb_"" with 100.0 weight got id 0</pre>
<pre># swift-ring-builder container.builder add r1z1-10.10.10.14:6001/sdc 100
</pre>
Device d1r1z1-10.10.10.14:6001R10.10.10.14:6001/sdc_"" with 100.0 weight got id 1
<pre># swift-ring-builder container.builder add r1z1-10.10.10.15:6001/sdb 100
</pre>
Device d2r1z1-10.10.10.15:6001R10.10.10.15:6001/sdb_"" with 100.0 weight got id 2
<pre># swift-ring-builder container.builder add r1z1-10.10.10.15:6001/sdc 100
</pre>
Device d3r1z1-10.10.10.15:6001R10.10.10.15:6001/sdc_"" with 100.0 weight got id 3
# swift-ring-builder container.builder
container.builder, build version 4
1024 partitions, 3.000000 replicas, 1 regions, 1 zones, 4 devices, 100.00 balance
The minimum number of hours before a partition can be reassigned is 1
Devices: id region zone ip address port replication ip replication port name weight partitions balance meta
0 1 1 10.10.10.14 6001 10.10.10.14 6001 sdb 100.00 0 -100.00 1 1 1 10.10.10.14 6001 10.10.10.14 6001 sdc 100.00 0 -100.00 2 1 1 10.10.10.15 6001 10.10.10.15 6001 sdb 100.00 0 -100.00 3 1 1 10.10.10.15 6001 10.10.10.15 6001 sdc 100.00 0 -100.00 </code></pre>
# swift-ring-builder container.builder rebalance
Reassigned 1024 (100.00%) partitions. Balance is now 0.00.</pre>
<pre># swift-ring-builder container.builder
container.builder, build version 4
1024 partitions, 3.000000 replicas, 1 regions, 1 zones, 4 devices, 0.00 balance
The minimum number of hours before a partition can be reassigned is 1
Devices: id region zone ip address port replication ip replication port name weight partitions balance meta
0 1 1 10.10.10.14 6001 10.10.10.14 6001 sdb 100.00 768 0.00 1 1 1 10.10.10.14 6001 10.10.10.14 6001 sdc 100.00 768 0.00 2 1 1 10.10.10.15 6001 10.10.10.15 6001 sdb 100.00 768 0.00 3 1 1 10.10.10.15 6001 10.10.10.15 6001 sdc 100.00 768 0.00 </code></pre>
object服务器使用object ring来保存当地设备上的object位置列表。
在controller节点上进行如下操做。
/etc/swift
目录。object.builder
文件:# swift-ring-builder object.builder create 10 3 1
# swift-ring-builder object.builder add r1z1-STORAGE_NODE_MANAGEMENT_INTERFACE_IP_ADDRESS:6000/DEVICE_NAME DEVICE_WEIGHT
在本文的方案下,执行命令以下:
<pre># swift-ring-builder object.builder add r1z1-10.10.10.14:6000/sdb 100
Device d0r1z1-10.10.10.14:6000R10.10.10.14:6000/sdb_"" with 100.0 weight got id 0</pre>
<pre># swift-ring-builder object.builder add r1z1-10.10.10.14:6000/sdc 100
</pre>
Device d1r1z1-10.10.10.14:6000R10.10.10.14:6000/sdc_"" with 100.0 weight got id 1
<pre># swift-ring-builder object.builder add r1z1-10.10.10.15:6000/sdb 100
</pre>
Device d2r1z1-10.10.10.15:6000R10.10.10.15:6000/sdb_"" with 100.0 weight got id 2
<pre># swift-ring-builder object.builder add r1z1-10.10.10.15:6000/sdc 100
</pre>
Device d3r1z1-10.10.10.15:6000R10.10.10.15:6000/sdc_"" with 100.0 weight got id 3
# swift-ring-builder object.builder
object.builder, build version 4
1024 partitions, 3.000000 replicas, 1 regions, 1 zones, 4 devices, 100.00 balance
The minimum number of hours before a partition can be reassigned is 1
Devices: id region zone ip address port replication ip replication port name weight partitions balance meta
0 1 1 10.10.10.14 6000 10.10.10.14 6000 sdb 100.00 0 -100.00 1 1 1 10.10.10.14 6000 10.10.10.14 6000 sdc 100.00 0 -100.00 2 1 1 10.10.10.15 6000 10.10.10.15 6000 sdb 100.00 0 -100.00 3 1 1 10.10.10.15 6000 10.10.10.15 6000 sdc 100.00 0 -100.00</code></pre>
# swift-ring-builder object.builder rebalance
Reassigned 1024 (100.00%) partitions. Balance is now 0.00.</pre>
<pre># swift-ring-builder object.builder
object.builder, build version 4
1024 partitions, 3.000000 replicas, 1 regions, 1 zones, 4 devices, 0.00 balance
The minimum number of hours before a partition can be reassigned is 1
Devices: id region zone ip address port replication ip replication port name weight partitions balance meta
0 1 1 10.10.10.14 6000 10.10.10.14 6000 sdb 100.00 768 0.00 1 1 1 10.10.10.14 6000 10.10.10.14 6000 sdc 100.00 768 0.00 2 1 1 10.10.10.15 6000 10.10.10.15 6000 sdb 100.00 768 0.00 3 1 1 10.10.10.15 6000 10.10.10.15 6000 sdc 100.00 768 0.00 </code></pre>
把account.ring.gz
,container.ring.gz
和object.ring.gz
拷贝到各个存储节点和运行代理服务的节点下/etc/swift
目录里。
在controller节点,object1和object2上分别执行:# apt-get install openssh-server
在controller节点上,进入/etc/swift
目录执行:# scp account.ring.gz container.ring.gz object.ring.gz controller@object1:~/
# scp account.ring.gz container.ring.gz object.ring.gz controller@object2:~/
在object节点上:# mv account.ring.gz object.ring.gz container.ring.gz /etc/swift/
/etc/swift/swift.conf
文件:# curl -o /etc/swift/swift.conf https://raw.githubusercontent...
# vi /etc/swift/swift.conf
文件:在[swift-hash]
部分,为环境设定hash path prefix和suffix:
<pre>[swift-hash]
...
swift_hash_path_suffix = HASH_PATH_PREFIX
swift_hash_path_prefix = HASH_PATH_SUFFIX</pre>
把 HASH_PATH_PREFIX和HASH_PATH_SUFFIX替换为合适的特定值。
在[storage-policy:0]
部分,设定默认的存储策略:
<pre>[storage-policy:0]
</pre>
...
name = Policy-0
default = yes
swift.conf
拷贝到各个存储节点和运行代理服务的节点下/etc/swift
目录里。# chown -R swift:swift /etc/swift
# service memcached restart
# service swift-proxy restart
# swift-init all start
因为此命令只是用来简化重启服务的命令,因此会有些没有运行在存储节点上的服务会报错,能够忽略。
如下操做在controller节点上执行。
demo
证书:$ source demo-openrc.sh
查看服务状态:
<pre>$ swift stat
Account: AUTH_d1f7caccc65840b68258997a759da07f
Containers: 0
Objects: 0 Bytes: 0
Content-Type: text/plain; charset=utf-8
X-Timestamp: 1449023734.57049
X-Trans-Id: tx9df6cf30763b4abaa05cd-00565e58f5
X-Put-Timestamp: 1449023734.57049</pre>
$ swift upload demo-container1 FILE
把FILE替换为测试文件的文件名,此文件将被上传至命名为demo-container1的container中。
<pre>$ swift upload demo-container1 test_file_for_swift.text
</pre>
test_file_for_swift.text
$ swift list
demo-container1</pre>
$ swift download demo-container1 FILE
把FILE替换为测试文件的文件名。
<pre>$ swift download demo-container1 test_file_for_swift.text
</pre>
test_file_for_swift.text [auth 0.105s, headers 0.131s, total 0.132s, 0.000 MB/s]
在安装完成执行重启服务操做时,出现以下错误提示:
<pre># service swift-proxy restart
</pre>
stop: Unknown instance:
start: Job failed to start
说明/etc/swift/proxy-server.conf
文件配置有问题,经查找后发现是在配置时没有注意[filter:authtoken]
和[filter:keystoneauth]
默认状态是注释掉的,将其取消注释后重启服务便可成功。在openstack【juno】入门 【swift篇】二十四:建立初始rings此文章中,做者用$ swift-init all start
命令查看错误更加明晰,也说明配置文件中全部参数都最好顶格写,不要预留空格。