初期設定

Swiftの初期設定から起動までの手順を解説します。システムの構成については、以下の図を参照ください。

プロキシ (Proxy) ノードの設定

プロキシノードの設定には、以下の項目があります。

 

次に、各設定について解説します。

 

1. パケットフィルタの設定

パケットフィルタを有効にする場合、以下のポートを開けておきます。
なお、これらのポート番号は全て各ソフトウェアの設定により変更することが可能です。変更する場合は、それぞれ該当ポート番号に置き換えてください。
また、ストレージサーバのntpデーモンが、プロキシサーバの時刻を参照する場合、ntpのポート番号も開けておく必要があります。

2. ntpの設定

Swiftは、最新のオブジェクトファイルを取得するためにタイムスタンプを使用するため、クラスタ内にある各ノードのシステムタイムができる限り正確に同期していることが重要となります。
そこで、NTPを利用して各サーバのシステムタイムを同期します。NTPの設定ファイルを編集して、プロキシノードは外部のタイムサーバの時刻を参照し、かつ各ストレージノードから時刻を参照される構成とします。
以下に、/etc/ntp.conf の例を記載します。

	:(省略)
server ntp.nict.jp               # 参照するntpサーバ
server ntp.jst.mfeed.ad.jp       # 参照するntpサーバ
server 2.jp.pool.ntp.org         # 参照するntpサーバ
	:(省略)
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap   # データノードからの参照を許可

設定を反映させるためにntpデーモンを再起動します。

[root@stor1 ~]# service ntpd restart
Shutting down ntpd: [ OK ]
Starting ntpd: [ OK ]
[root@proxy ~]#

“ntpq ?p”コマンドで、時刻の同期状態を確認します。
行の先頭に”*”や”+”の印のついたものがあれば、時刻の同期ができていることとなります。また、時刻の同期には10分程度を要します。

[root@proxy ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp-b3.nict.go. .NICT. 1 u 28 64 377 7.358 -1.543 2.014
+ntp2.jst.mfeed. 210.173.160.56 2 u 36 64 177 4.375 -0.293 1.011
+z2.ktroad.net 131.113.63.2 3 u 32 64 377 16.462 -0.494 1.259
[root@proxy ~]#

行の先頭(1カラム目)の文字は、以下のような意味があります (他の文字も表示されることがあります)。

3. Swift設定ファイル用ディレクトリの生成

設定ファイルやリングファイルを配置するディレクトリを作成し、オーナーとグループにSwift専用ユーザアカウントのswiftを設定します。

mkdir /etc/swift
chown swift:swift /etc/swift

4. swift.confファイルの作成

swift_hash_path_suffixには任意のユニークな文字列を指定します。後で変更することはできないので注意が必要です。

Swiftでは内部的に、リクエストパスから算出したハッシュ値を用いてコンテナのデータベースファイルやオブジェクトのファイルを管理しています。このハッシュにはMD5アルゴリズムを利用しているが、MD5ハッシュ値は誰にでも算出することが可能です。
Swiftではハッシュ値を求める際、元データにswift_hash_path_suffixの値を付加することでハッシュ値の推測を困難にしているため、この値は秘密にしておく必要があります。

ここでは、次のコマンドで取得した乱数を使用しています。

[root@proxy ~]# od -t x8 -N 8 -A n < /dev/random
5c747739000bb7c3
[swift-hash]
# random unique (preferably alphanumeric) string that can never change (DO NOT LOSE)
swift_hash_path_suffix = 5c747739000bb7c3

5. memcachedの設定とサービスの再起動

設定ファイルを編集して、待ち受けIPアドレスを設定します。

/etc/memcached.conf

root@proxy:/etc/swift# service memcached restart
Restarting memcached: memcached.

6. プロキシ(proxy)サーバの設定 (proxy-server.conf)

プロキシサーバ設定ファイルを作成します。
filter:swauthセクションのdefault_swift_clusterは、ユーザに提示するストレージURL(のプリフィクス)として使用されます。また、super_admin_keyは、アカウントの作成や削除などの特権操作を行う際に使用するシステム管理者のパスワードであるため、必ず変更する必要があります。

[DEFAULT]
bind_port = 8080
workers = 8
user = swift

[pipeline:main]
pipeline = healthcheck cache swauth proxy-server

[app:proxy-server]
use = egg:swift#proxy
allow_account_management = true

[filter:swauth]
use = egg:swift#swauth
default_swift_cluster = local#http://172.17.222.21:8080/v1
super_admin_key = swauthkey

[filter:healthcheck]
use = egg:swift#healthcheck

[filter:cache]
use = egg:swift#memcache
memcache_servers = 192.168.0.21:11211

7. リングファイルの作成

Swiftでは、オブジェクトなどのデータとそれに対応するストレージノード上のデバイスをリングと呼ばれるファイルでマッピングします。このマッピングは、リクエストパスから計算により導き出されるパーティション番号と呼ばれるインデックス値を用いて行われます。

あらかじめ決めた固定サイズの配列を作り、そこにストレージノードを割り当てます。配列はデータの複製する数 (レプリカカウント) だけ用意されます。複製を3つ作る場合、配列も3つになります。
各配列の同じインデックス値の箇所には同じゾーンのストレージノードは2つ以上配置されることはありません。これによって複製は必ず別のゾーンに置かれることになります。

この配列を格納したものがリングファイルです。従って、リングファイルを作成するには、配列のサイズ (すなわちパーティション数)、複製の数 (レプリカカウント) をあらかじめ決めておく必要があります。

更にパーティションが連続して移動する (ノード追加時などに、パーティションンを別のノードに再割り当てする) ことを抑制する期間を決めます。パーティションの連続移動抑制期間は24時間が推奨されています。

パーティション数は、使用するディスク数 (各ストレージノードでディスク1つの場合は、ストレージノード数) の100倍が妥当とされていますが、パーティション数は2のべき乗で表せる数に調整する必要があります。
最大5,000台のディスクを使用する場合、パーティション数は500,000となり、2のべき乗に換算すると、2^19となります。

レプリカカウントの推奨値は3で、大きくするとディスク領域を多く消費します。
代わりにデータ喪失の可能性は低くなります。
なお、リングファイルはアカウント用、コンテナ用、オブジェクト用のものをそれぞれ作成する必要があります。

/etc/swiftディレクトリに移動し、swift-ring-builderコマンドでリングファイルの作成を行います。
この例では、パーティション数を262144 (2^18)、レプリカカウントを3、パーティションの連続移動抑制期間を24時間と指定しています。

[root@proxy ~]# cd /etc/swift
[root@proxy swift]# swift-ring-builder account.builder create 18 3 24
[root@proxy swift]# swift-ring-builder container.builder create 18 3 24
[root@proxy swift]# swift-ring-builder object.builder create 18 3 24

8. リングファイルの登録

ゾーンは、5つ以上にすることが推奨されています。
以下の例でもゾーンを5つとしています。

[root@proxy swift]# swift-ring-builder account.builder add z1-172.17.222.31:6002/sdb1 1
Device z1-172.17.222.31:6002/sdb1_”” with 1.0 weight got id 0
[root@proxy swift]# swift-ring-builder account.builder add z1-172.17.222.31:6002/sdc1 1
Device z1-172.17.222.31:6002/sdc1_”” with 1.0 weight got id 1
[root@proxy swift]# swift-ring-builder account.builder add z2-172.17.222.32:6002/sdb1 1
Device z2-172.17.222.32:6002/sdb1_”” with 1.0 weight got id 2
[root@proxy swift]# swift-ring-builder account.builder add z2-172.17.222.32:6002/sdc1 1
Device z2-172.17.222.32:6002/sdc1_”” with 1.0 weight got id 3
[root@proxy swift]# swift-ring-builder account.builder add z3-172.17.222.33:6002/sdb1 1
Device z3-172.17.222.33:6002/sdb1_”” with 1.0 weight got id 4
[root@proxy swift]# swift-ring-builder account.builder add z3-172.17.222.33:6002/sdc1 1
Device z3-172.17.222.33:6002/sdc1_”” with 1.0 weight got id 5
[root@proxy swift]# swift-ring-builder account.builder add z4-172.17.222.34:6002/sdb1 1
Device z4-172.17.222.34:6002/sdb1_”” with 1.0 weight got id 6
[root@proxy swift]# swift-ring-builder account.builder add z4-172.17.222.34:6002/sdc1 1
Device z4-172.17.222.34:6002/sdc1_”” with 1.0 weight got id 7
[root@proxy swift]# swift-ring-builder account.builder add z5-172.17.222.35:6002/sdb1 1
Device z5-172.17.222.35:6002/sdb1_”” with 1.0 weight got id 8
[root@proxy swift]# swift-ring-builder account.builder add z5-172.17.222.35:6002/sdc1 1
Device z5-172.17.222.35:6002/sdc1_”” with 1.0 weight got id 9
[root@proxy swift]#
[root@proxy swift]# swift-ring-builder container.builder add z1-172.17.222.31:6001/sdb1 1
Device z1-172.17.222.31:6001/sdb1_”” with 1.0 weight got id 0
[root@proxy swift]# swift-ring-builder container.builder add z1-172.17.222.31:6001/sdc1 1
Device z1-172.17.222.31:6001/sdc1_”” with 1.0 weight got id 1
[root@proxy swift]# swift-ring-builder container.builder add z2-172.17.222.32:6001/sdb1 1
Device z2-172.17.222.32:6001/sdb1_”” with 1.0 weight got id 2
[root@proxy swift]# swift-ring-builder container.builder add z2-172.17.222.32:6001/sdc1 1
Device z2-172.17.222.32:6001/sdc1_”” with 1.0 weight got id 3
[root@proxy swift]# swift-ring-builder container.builder add z3-172.17.222.33:6001/sdb1 1
Device z3-172.17.222.33:6001/sdb1_”” with 1.0 weight got id 4
[root@proxy swift]# swift-ring-builder container.builder add z3-172.17.222.33:6001/sdc1 1
Device z3-172.17.222.33:6001/sdc1_”” with 1.0 weight got id 5
[root@proxy swift]# swift-ring-builder container.builder add z4-172.17.222.34:6001/sdb1 1
Device z4-172.17.222.34:6001/sdb1_”” with 1.0 weight got id 6
[root@proxy swift]# swift-ring-builder container.builder add z4-172.17.222.34:6001/sdc1 1
Device z4-172.17.222.34:6001/sdc1_”” with 1.0 weight got id 7
[root@proxy swift]# swift-ring-builder container.builder add z5-172.17.222.35:6001/sdb1 1
Device z5-172.17.222.35:6001/sdb1_”” with 1.0 weight got id 8
[root@proxy swift]# swift-ring-builder container.builder add z5-172.17.222.35:6001/sdc1 1
Device z5-172.17.222.35:6001/sdc1_”” with 1.0 weight got id 9
[root@proxy swift]#
[root@proxy swift]# swift-ring-builder object.builder add z1-172.17.222.31:6000/sdb1 1
Device z1-172.17.222.31:6000/sdb1_”” with 1.0 weight got id 0
[root@proxy swift]# swift-ring-builder object.builder add z1-172.17.222.31:6000/sdc1 1
Device z1-172.17.222.31:6000/sdc1_”” with 1.0 weight got id 1
[root@proxy swift]# swift-ring-builder object.builder add z2-172.17.222.32:6000/sdb1 1
Device z2-172.17.222.32:6000/sdb1_”” with 1.0 weight got id 2
[root@proxy swift]# swift-ring-builder object.builder add z2-172.17.222.32:6000/sdc1 1
Device z2-172.17.222.32:6000/sdc1_”” with 1.0 weight got id 3
[root@proxy swift]# swift-ring-builder object.builder add z3-172.17.222.33:6000/sdb1 1
Device z3-172.17.222.33:6000/sdb1_”” with 1.0 weight got id 4
[root@proxy swift]# swift-ring-builder object.builder add z3-172.17.222.33:6000/sdc1 1
Device z3-172.17.222.33:6000/sdc1_”” with 1.0 weight got id 5
[root@proxy swift]# swift-ring-builder object.builder add z4-172.17.222.34:6000/sdb1 1
Device z4-172.17.222.34:6000/sdb1_”” with 1.0 weight got id 6
[root@proxy swift]# swift-ring-builder object.builder add z4-172.17.222.34:6000/sdc1 1
Device z4-172.17.222.34:6000/sdc1_”” with 1.0 weight got id 7
[root@proxy swift]# swift-ring-builder object.builder add z5-172.17.222.35:6000/sdb1 1
Device z5-172.17.222.35:6000/sdb1_”” with 1.0 weight got id 8
[root@proxy swift]# swift-ring-builder object.builder add z5-172.17.222.35:6000/sdc1 1
Device z5-172.17.222.35:6000/sdc1_”” with 1.0 weight got id 9

リングが登録されたか、内容を確認します。

[root@proxy swift]# swift-ring-builder account.builder
account.builder, build version 10
262144 partitions, 3 replicas, 5 zones, 10 devices, 100.00 balance
The minimum number of hours before a partition can be reassigned is 24
Devices:    id  zone      ip address  port      name weight partitions balance meta
      0     1   172.17.222.31  6002      sdb1   1.00          0 -100.00
      1     1   172.17.222.31  6002      sdc1   1.00          0 -100.00
      2     2   172.17.222.32  6002      sdb1   1.00          0 -100.00
      3     2   172.17.222.32  6002      sdc1   1.00          0 -100.00
      4     3   172.17.222.33  6002      sdb1   1.00          0 -100.00
      5     3   172.17.222.33  6002      sdc1   1.00          0 -100.00
      6     4   172.17.222.34  6002      sdb1   1.00          0 -100.00
      7     4   172.17.222.34  6002      sdc1   1.00          0 -100.00
      8     5   172.17.222.35  6002      sdb1   1.00          0 -100.00
      9     5   172.17.222.35  6002      sdc1   1.00          0 -100.00
[root@proxy swift]# swift-ring-builder container.builder
container.builder, build version 10
262144 partitions, 3 replicas, 5 zones, 10 devices, 100.00 balance
The minimum number of hours before a partition can be reassigned is 24
Devices:    id  zone      ip address  port      name weight partitions balance meta
      0     1   172.17.222.31  6001      sdb1   1.00          0 -100.00
      1     1   172.17.222.31  6001      sdc1   1.00          0 -100.00
      2     2   172.17.222.32  6001      sdb1   1.00          0 -100.00
      3     2   172.17.222.32  6001      sdc1   1.00          0 -100.00
      4     3   172.17.222.33  6001      sdb1   1.00          0 -100.00
      5     3   172.17.222.33  6001      sdc1   1.00          0 -100.00
      6     4   172.17.222.34  6001      sdb1   1.00          0 -100.00
      7     4   172.17.222.34  6001      sdc1   1.00          0 -100.00
      8     5   172.17.222.35  6001      sdb1   1.00          0 -100.00
      9     5   172.17.222.35  6001      sdc1   1.00          0 -100.00
[root@proxy swift]# swift-ring-builder object.builder
object.builder, build version 10
262144 partitions, 3 replicas, 5 zones, 10 devices, 100.00 balance
The minimum number of hours before a partition can be reassigned is 24
Devices:    id  zone      ip address  port      name weight partitions balance meta
      0     1   172.17.222.31  6000      sdb1   1.00          0 -100.00
      1     1   172.17.222.31  6000      sdc1   1.00          0 -100.00
      2     2   172.17.222.32  6000      sdb1   1.00          0 -100.00
      3     2   172.17.222.32  6000      sdc1   1.00          0 -100.00
      4     3   172.17.222.33  6000      sdb1   1.00          0 -100.00
      5     3   172.17.222.33  6000      sdc1   1.00          0 -100.00
      6     4   172.17.222.34  6000      sdb1   1.00          0 -100.00
      7     4   172.17.222.34  6000      sdc1   1.00          0 -100.00
      8     5   172.17.222.35  6000      sdb1   1.00          0 -100.00
      9     5   172.17.222.35  6000      sdc1   1.00          0 -100.00

9. リングのrebalance

全てのストレージノードを追加したら、rebalanceを実行します。
この操作によって実際のリングファイル(account.ring.gz、container.ring.gz、object.ring.gz)が生成されます。

[root@proxy swift]# swift-ring-builder account.builder rebalance
Reassigned 262144 (100.00%) partitions. Balance is now 0.00.
[root@proxy swift]# swift-ring-builder container.builder rebalance
Reassigned 262144 (100.00%) partitions. Balance is now 0.00.
[root@proxy swift]# swift-ring-builder object.builder rebalance
Reassigned 262144 (100.00%) partitions. Balance is now 0.00.

10. 各ファイルのオーナー設定

/etc/swiftおよびその配下のディレクトリとファイル全てのユーザとグループがswiftになるよう変更します。

[root@proxy swift]# chown -R swift:swift /etc/swift/ [root@proxy swift]# ls -al /etc/swift/ total 6644 drwxr-xr-x 3 swift swift 4096 Feb 9 13:57 . drwxr-xr-x. 63 root root 4096 Feb 9 12:19 .. -rw-r–r– 1 swift swift 1836683 Feb 9 13:56 account.builder -rw-r–r– 1 swift swift 413564 Feb 9 13:56 account.ring.gz drwxr-xr-x 2 swift swift 4096 Feb 9 13:57 backups -rw-r–r– 1 swift swift 1836683 Feb 9 13:57 container.builder -rw-r–r– 1 swift swift 413415 Feb 9 13:57 container.ring.gz -rw-r–r– 1 swift swift 1836683 Feb 9 13:57 object.builder -rw-r–r– 1 swift swift 413486 Feb 9 13:57 object.ring.gz -rw-r–r– 1 swift swift 449 Feb 9 12:49 proxy-server.conf -rw-r–r– 1 swift swift 141 Feb 7 20:02 swift.conf

以上で、プロキシノードの設定は終了です。