Amazon S3 互換の KVS である Riak-CS を Mac にインストールしてみた。
今回のポイント
- homebrew には Riak の brew はあるものの、RiakCS の brew がないのと、バージョンが新しすぎるため、Riak / RiakCS / stanchion をそれぞれ、公式サイトのバイナリパッケージを落としてきてインストールした。
- バイナリを展開したディレクトリで実行しているので、データを別のディレクトリに置く場合 (/var下など) は、設定をいじる必要がある。
- brew でインストールする s3cmd はバージョンが古くて一部コマンドが対応してないなどの問題がある。
- 最新の s3cmd を使うとデフォルト状態では RiakCS が認証で問題が生じるので、オプション設定の必要がある。
Riak / RiakCS / Stanchion のインストール
Riak
$ wget http://s3.amazonaws.com/downloads.basho.com/riak/1.4/1.4.12/osx/10.8/riak-1.4.12-OSX-x86_64.tar.gz
$ tar riak-1.4.12-OSX-x86_64.tar.gz
Configuring Riak for CS を参考に riak-1.4.12/etc/app.config をいじる
$ vi riak-1.4.12/etc/app.config
- riak_kv の
{storage_backend, riak_kv_bitcask_backend},
の行を消す - riak_kv に、以下を追加する
{add_paths, ["../riak-cs-1.5.3/lib/riak_cs-1.5.3/ebin"]},
{storage_backend, riak_cs_kv_multi_backend},
{multi_backend_prefix_list, [{<<"0b:">>, be_blocks}]},
{multi_backend_default, be_default},
{multi_backend, [
{be_default, riak_kv_eleveldb_backend, [
{max_open_files, 50},
{data_root, "./data/leveldb"}
]},
{be_blocks, riak_kv_bitcask_backend, [
{data_root, "./data/bitcask"}
]}
]},
- riak_core に、
{default_bucket_props, [{allow_mult, true}]},
を追加する
Stanchion
$ wget http://s3.amazonaws.com/downloads.basho.com/stanchion/1.5/1.5.0/osx/10.8/stanchion-1.5.0-OSX-x86_64.tar.gz
$ tar stanchion-1.5.0-OSX-x86_64.tar.gz
RiakCS
$ wget http://s3.amazonaws.com/downloads.basho.com/riak-cs/1.5/1.5.3/osx/10.8/riak-cs-1.5.3-OSX-x86_64.tar.gz
$ tar zxvf riak-cs-1.5.3-OSX-x86_64.tar.gz
$ vi riak-cs-1.5.3/etc/app.config
- riak_cs の、
{anonymous_user_creation, false},
の行の false を true に書き換える
起動
$ riak-1.4.12/bin/riak start
$ riak-1.4.12/bin/riak ping
pong
$ stanchion-1.5.0/bin/stanchion start
$ stanchion-1.5.0/bin/stanchion ping
pong
$ riak-cs-1.5.3/bin/riak-cs start
$ riak-cs-1.5.3/bin/riak-cs ping
pong
auth key の発行
$ curl -H 'Content-Type: application/json' -X POST http://localhost:8080/riak-cs/user --data '{"email":"test@example.org", "name":"admin"}'
{"email":"test@example.org","display_name":"admin","name":"admin","key_id":"HOGEHOGEHOGE","key_secret":"hogehoge==","id":"0b32a21c1f4","status":"enabled"}
- key_id と key_secret を控えておこう。
設定の更新
$ vi stanchion-1.5.0/etc/app.config
$ vi riak-cs-1.5.3/etc/app.config
stanchionとriak-csの設定ファイルそれぞれの
{admin_key, "admin-key"},
{admin_secret, "admin-secret"},
admin-key に key_id, admin-secret に key_secret を書き換える。
また、riak-cs の {anonymous_user_creation, false},
の行を、true にしていたのを false に戻すのを忘れないように。
$ stanchion-1.5.0/bin/stanchion stop
ok
$ stanchion-1.5.0/bin/stanchion start
$ stanchion-1.5.0/bin/stanchion ping
pong
$ riak-cs-1.5.3/bin/riak-cs stop
ok
$ riak-cs-1.5.3/bin/riak-cs start
$ riak-cs-1.5.3/bin/riak-cs ping
pong
s3cmd のインストール
$ git clone https://github.com/s3tools/s3cmd.git
$ cd s3cmd
$ python setup.py install
s3cmd の設定
$ s3cmd --configure
- proxy に、127.0.0.1 と 8080 を指定する
$ vi ~/.s3cfg
-
signature_v2 = False
の False を True に書き換える
テスト
$ s3cmd mb s3://test
Bucket 's3://test/' created
$ vi hoge.txt
ほげー
$ s3cmd put hoge.txt s3://test/
WARNING: Module python-magic is not available. Guessing MIME types based on file extensions.
asking for bucket location
hoge.txt -> s3://test/hoge.txt [1 of 1]
11 of 11 100% in 0s 137.23 B/s done
$ vi policy.json
{
"Version":"2008-10-17",
"Statement":[{
"Sid":"AllowPublicRead",
"Effect":"Allow",
"Principal": {
"AWS": "*"
},
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::test/*"
]
}
]
}
$ s3cmd setpolicy policy.json s3://test
$ curl http://localhost:8080/test/hoge.txt
ほげー
エラーかなと思ったら
- s3cmd ならば -d オプションをつけると詳細なデバッグ情報が見られる
- riak-1.4.12/log/ stanchion-1.5.0/log riak-cs-1.5.3/log/ 下など、それぞれのログディレクトリを見ると、原因がわかるかもしれない。
- 設定ファイルの書き間違えはわりと発生する割にわかりにくい雰囲気がある。