OpenStack安装流程(juno版)- 添加对象存储服务(swift)- 创建初始环

ZhengZhenyu 2019-06-29

在开始对象存储服务前,必须先创建初始的account,container和object环(ring)。

Account ring

account服务器使用account ring来保存container列表。

创建环

在controller节点上进行以下操作。

  1. 进入/etc/swift目录。
  2. 创建基础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)

  1. 把各个存储节点添加进环

# 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<br>Device d0r1z1-10.10.10.14:6002R10.10.10.14:6002/sdb_"" with 100.0 weight got id 0</pre>
<pre># swift-ring-builder account.builder add r1z1-10.10.10.14:6002/sdc 100<br>Device d1r1z1-10.10.10.14:6002R10.10.10.14:6002/sdc_"" with 100.0 weight got id 1</pre>
<pre># swift-ring-builder account.builder add r1z1-10.10.10.15:6002/sdb 100<br>Device d2r1z1-10.10.10.15:6002R10.10.10.15:6002/sdb_"" with 100.0 weight got id 2</pre>
<pre># swift-ring-builder account.builder add r1z1-10.10.10.15:6002/sdc 100<br>Device d3r1z1-10.10.10.15:6002R10.10.10.15:6002/sdc_"" with 100.0 weight got id 3</pre>

  1. 验证环的内容:
    <pre># 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 meta

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>
  1. 重新平衡环:
    <pre># swift-ring-builder account.builder rebalance

Reassigned 1024 (100.00%) partitions. Balance is now 0.00.</pre>
<pre># swift-ring-builder account.builder<br>account.builder, build version 4<br>1024 partitions, 3.000000 replicas, 1 regions, 1 zones, 4 devices, 0.00 balance<br>The minimum number of hours before a partition can be reassigned is 1<br>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 Ring

container服务器使用container ring来保存object列表,但并不追踪object的位置。

创建环

在controller节点上进行以下操作。

  1. 进入/etc/swift目录。
  2. 创建基础container.builder文件:

# swift-ring-builder container.builder create 10 3 1

  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<br>Device d1r1z1-10.10.10.14:6001R10.10.10.14:6001/sdc_"" with 100.0 weight got id 1</pre>
<pre># swift-ring-builder container.builder add r1z1-10.10.10.15:6001/sdb 100<br>Device d2r1z1-10.10.10.15:6001R10.10.10.15:6001/sdb_"" with 100.0 weight got id 2</pre>
<pre># swift-ring-builder container.builder add r1z1-10.10.10.15:6001/sdc 100<br>Device d3r1z1-10.10.10.15:6001R10.10.10.15:6001/sdc_"" with 100.0 weight got id 3</pre>

  1. 验证环的内容:
    <pre># 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>
  1. 重新平衡环:
    <pre># swift-ring-builder container.builder rebalance

Reassigned 1024 (100.00%) partitions. Balance is now 0.00.</pre>
<pre># swift-ring-builder container.builder<br>container.builder, build version 4<br>1024 partitions, 3.000000 replicas, 1 regions, 1 zones, 4 devices, 0.00 balance<br>The minimum number of hours before a partition can be reassigned is 1<br>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 ring

object服务器使用object ring来保存当地设备上的object位置列表。

创建环

在controller节点上进行以下操作。

  1. 进入/etc/swift目录。
  2. 创建基础object.builder文件:

# swift-ring-builder object.builder create 10 3 1

  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<br>Device d1r1z1-10.10.10.14:6000R10.10.10.14:6000/sdc_"" with 100.0 weight got id 1</pre>
<pre># swift-ring-builder object.builder add r1z1-10.10.10.15:6000/sdb 100<br>Device d2r1z1-10.10.10.15:6000R10.10.10.15:6000/sdb_"" with 100.0 weight got id 2</pre>
<pre># swift-ring-builder object.builder add r1z1-10.10.10.15:6000/sdc 100<br>Device d3r1z1-10.10.10.15:6000R10.10.10.15:6000/sdc_"" with 100.0 weight got id 3</pre>

  1. 验证环的内容:
    <pre># 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>
  1. 重新平衡环:
    <pre># swift-ring-builder object.builder rebalance

Reassigned 1024 (100.00%) partitions. Balance is now 0.00.</pre>
<pre># swift-ring-builder object.builder<br>object.builder, build version 4<br>1024 partitions, 3.000000 replicas, 1 regions, 1 zones, 4 devices, 0.00 balance<br>The minimum number of hours before a partition can be reassigned is 1<br>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.gzcontainer.ring.gzobject.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/

完成安装

设定hashes和默认的存储策略

  1. 从对象存储的源码仓库中取得/etc/swift/swift.conf文件:
    # curl -o /etc/swift/swift.conf <a href="https://raw.githubusercontent.com/openstack/swift/stable/juno/etc/swift.conf-sample" rel="nofollow noreferrer">https://raw.githubusercontent...</a>
  2. 编辑# 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]<br>...<br>name = Policy-0<br>default = yes</pre>

  1. swift.conf拷贝到各个存储节点和运行代理服务的节点下/etc/swift目录里。
  2. 在所有相关节点上,确保配置文件目录权限正确:

# chown -R swift:swift /etc/swift

  1. 在控制节点和其他运行代理服务的节点,重启对象存储代理服务和它的依赖服务:

# service memcached restart
# service swift-proxy restart

  1. 在存储节点,启动对象存储服务:

# swift-init all start
由于此命令只是用来简化重启服务的命令,所以会有些没有运行在存储节点上的服务会报错,可以忽略。

验证操作

以下操作在controller节点上执行。

  1. 启动demo证书:

$ source demo-openrc.sh

  1. 查看服务状态:
    <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>

  1. 上传一个测试文件:

$ swift upload demo-container1 FILE
把FILE替换为测试文件的文件名,此文件将被上传至命名为demo-container1的container中。
<pre>$ swift upload demo-container1 test_file_for_swift.text<br>test_file_for_swift.text</pre>

  1. 列出container:
    <pre>$ swift list

demo-container1</pre>

  1. 下载测试文件:

$ swift download demo-container1 FILE
把FILE替换为测试文件的文件名。
<pre>$ swift download demo-container1 test_file_for_swift.text<br>test_file_for_swift.text [auth 0.105s, headers 0.131s, total 0.132s, 0.000 MB/s]</pre>

安装时出现的问题及解决方法

在安装完成执行重启服务操作时,出现如下错误提示:
<pre># service swift-proxy restart<br>stop: Unknown instance:<br>start: Job failed to start</pre>
说明/etc/swift/proxy-server.conf文件配置有问题,经查找后发现是在配置时没有注意[filter:authtoken][filter:keystoneauth]默认状态是注释掉的,将其取消注释后重启服务即可成功。在openstack【juno】入门 【swift篇】二十四:创建初始rings此文章中,作者用$ swift-init all start命令查看错误更加明晰,也说明配置文件中所有参数都最好顶格写,不要预留空格。

相关推荐

dongnaosenlu / 0评论 2019-06-24