在開始對象存儲服務前,必須先建立初始的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
命令查看錯誤更加明晰,也說明配置文件中全部參數都最好頂格寫,不要預留空格。