ラベル storagegateway の投稿を表示しています。 すべての投稿を表示
ラベル storagegateway の投稿を表示しています。 すべての投稿を表示

2013年4月26日金曜日

StorageGatewayってなんじゃ?(バッファやキャッシュの容量を追加)

AWSのStorageGatewayを利用していて、パフォーマンスの見積もりが実際と合わず、最初に設定したバッファストレージやキャッシュストレージの容量が少なかったというケースがあるかもしれません。

公式ドキュメントでは、

Adding and Removing Upload Buffer Capacity (Gateway-Cached)

You can add more buffer capacity to your gateway without interrupting existing gateway functions. Note that when you add more upload buffer capacity, you do so with the gateway VM powered on; however, when you reduce the amount of upload buffer capacity, you must first power off the VM.

既存のゲートウェイ機能を中断せずにバッファ容量を追加することができます。
アップロードバッファ容量を追加する時は、ゲートウェイVMが起動中に行えますが
容量を減らす場合はまずVMをシャットダウンしておく必要があります。

As your application needs change and you add more storage volume capacity, you will might need to increase the gateway's upload buffer capacity. You can add more buffer capacity using the AWS Storage Gateway API (see AddUploadBuffer) or the AWS Storage Gateway console. 

アプリケーションのニーズが変化に応じてストレージ容量を追加すると、アップロードバッファ容量も増やす必要が出てきます。APIかAWSコンソールからバッファ容量を増やすことができます。




Adding Cache Storage (Gateway-Cached)


You can add more cache storage to your gateway without interrupting existing gateway functions and with the gateway VM powered on

既存のゲートウェイ機能を中断せずに起動したままキャッシュ容量を追加することができます。

You can add more cache storage using the AWS Storage Gateway API (see AddCache) or the AWS Storage Gateway console.

APIかAWSコンソールからバッファ容量を増やすことができます

Removing a disk allocated as cache storage is currently not supported.

キャッシュストレージの取り外しは現時点ではサポートされていません。


ということで、稼働中にバッファやキャッシュを追加することができます。
また現時点では、WEBシステムなどで利用していて後々アクセスが下がってきた場合キャッシュボリュームは減らせないので、料金的にリスクがありそうです。
長期的に考え、増やすときは必要な分だけ、というのがよさそうです。


では試してみます。




キャッシュ、バッファの追加




今回はゲートウェイインスタンス(EC2)の場合でやってみます。
以下の様な既存のゲートウェイインスタンスがあるとします。







「Gateway」タブの「Configure Local Storage」をみると、アップロードバッファに10GBのボリュームが適用されているのがわかります。また、キャッシュボリュームは20GBです。






ここで、ゲートウェイインスタンスにさらにアップロードバッファ用に10GB、キャッシュ用に20GBのボリュームを用意しアタッチします。





StorageGatewayの画面で、ふたたび「Gateway」タブの「Configure Local Storage」をクリックします。





すると、新しいディスクが認識され、バッファ用かキャッシュ用かを選択できるようになっています。
ここでは既存と同様、バッファ10GB、キャッシュ20GBとします。
「Save」ボタンを押すと、すぐに適用され、以下の画面でもバッファが20GBになってことがわかります。








バッファの削除



それではバッファを削除します。
削除する場合はシャットダウンが必要です。
「Gateway」タブの「Shut Down」をクリックして、コンソールをリロードして以下の画面になるまで待ちます。





上のような画面になったら、先ほど追加したバッファ用の10GBをデタッチします。





ディスクステータスが「Available」になったら、StorageGateway画面に戻り、先ほどの「Restart」ボタンをクリックします。
しばらくして、Gatewayが「Available」になったら「Gateway」タブの「Configure Local Storage」でストレージをみてみると、、、、





このように無事バッファボリュームを減らすことが出来ました。


また、これと同じようにキャッシュボリュームを減らそうとすると、Gatewayが「IRRECOVERABLE」という恐いステータスになってしまい、ボリュームが壊れてしまうようなので、停止中でもキャッシュボリュームはデタッチしてはいけません。サポートされるのをおとなしく待ちましょう。



以上です。





2013年3月2日土曜日

StorageGatewayってなんじゃ?(GlusterFSで復旧編)

前回GlusterFSを使ってStorageGatewayインスタンスを冗長化しました。
今回は、インスタンスが落ちた場合の復旧方法を見てみます。

Gatewayインスタンスが落ちた場合





gatewayインスタンスを落とします。



ブリックである/mnt/sgwをみてみると


# ls -l /mnt/sgw
ls: reading directory /mnt/sgw: 入力/出力エラーです
合計 16
-rw-r--r-- 2 root root 27  3月  1 13:24 2013 1.txt
-rw-r--r-- 2 root root 27  3月  1 13:24 2013 4.txt


IOエラーがでます。


Glusterボリュームのマウントポイントをみてみると


# ls -lrt /mnt/gv
合計 24
-rw-r--r-- 1 root root 27  3月  1 13:51 2013 1.txt
-rw-r--r-- 1 root root 27  3月  1 13:51 2013 2.txt
-rw-r--r-- 1 root root 27  3月  1 13:51 2013 3.txt
-rw-r--r-- 1 root root 27  3月  1 13:51 2013 4.txt
-rw-r--r-- 1 root root 27  3月  1 13:51 2013 5.txt
-rw-r--r-- 1 root root 27  3月  1 13:52 2013 6.txt
-rw-r--r-- 1 root root 27  3月  1 13:52 2013 7.txt
-rw-r--r-- 1 root root 27  3月  1 13:52 2013 8.txt
-rw-r--r-- 1 root root 27  3月  1 13:52 2013 9.txt
-rw-r--r-- 1 root root 27  3月  1 13:52 2013 10.txt
-rw-r--r-- 1 root root 27  3月  1 13:52 2013 11.txt
-rw-r--r-- 1 root root 27  3月  1 13:53 2013 12.txt
-rw-r--r-- 1 root root 27  3月  1 13:53 2013 13.txt
-rw-r--r-- 1 root root 27  3月  1 13:53 2013 14.txt
-rw-r--r-- 1 root root 27  3月  1 13:53 2013 15.txt

# cat /mnt/gv/*
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ


正しくレプリケーションされています。


gatewayインスタンスを復帰させます。




インスタンスが立ち上がったら、一度10.0.1.8のglusterfsを解除して、iSCSIボリュームを再マウントします。

# ps -ax | grep gluster
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
24350 ?        Ssl    0:00 /usr/sbin/glusterd -p /var/run/glusterd.pid
24371 ?        Ssl    0:00 /usr/sbin/glusterfsd -s localhost --volfile-id gv0.10.0.1.8.mnt-sgw -p /var/lib/glusterd/vols/gv0/run/10.0.1.8-mnt-sgw.pid -S /tmp/6f580d4f3eab1dcb22c5aef9d7fb2275.socket --brick-name /mnt/sgw -l /var/log/glusterfs/bricks/mnt-sgw.log --xlator-option *-posix.glusterd-uuid=4f2e8dff-1b51-423e-8ac0-b0e892bd2e0d --brick-port 24013 --xlator-option gv0-server.listen-port=24013
24377 ?        Ssl    0:00 /usr/sbin/glusterfs -s localhost --volfile-id gluster/nfs -p /var/lib/glusterd/nfs/run/nfs.pid -l /var/log/glusterfs/nfs.log -S /tmp/f34a5ad241dbfecb7dcb5f2c14aab1f4.socket
24383 ?        Ssl    0:00 /usr/sbin/glusterfs -s localhost --volfile-id gluster/glustershd -p /var/lib/glusterd/glustershd/run/glustershd.pid -l /var/log/glusterfs/glustershd.log -S /tmp/c019293c2e261dcab94469694dc5674e.socket --xlator-option *replicate*.node-uuid=4f2e8dff-1b51-423e-8ac0-b0e892bd2e0d
24393 pts/1    S+     0:00 grep gluster
# kill -9 24350 24371 24377 24383

# umount /mnt/sgw
# umount /mnt/gv
# iscsiadm --mode discovery --type sendtargets --portal 10.0.1.5:3260
# iscsiadm --mode node --targetname iqn.1997-05.com.amazon:memorycraft-sgw1 --portal 10.0.1.5:3260,1 --logout
# iscsiadm --mode node --targetname iqn.1997-05.com.amazon:memorycraft-sgw1 --portal 10.0.1.5:3260,1 --login
# mount /dev/sda /mnt/sgw
# /etc/init.d/glusterd start
# mount -t glusterfs 10.0.1.8:/gv0 /mnt/gv



ここでブリック(GlusterFSを構成するディレクトリ)である/mnt/sgwをみてみると、

# ls -l /mnt/sgw
合計 112
-rw-r--r-- 2 root root  0  3月  1 13:51 2013 1.txt
-rw-r--r-- 2 root root  0  3月  1 13:52 2013 10.txt
-rw-r--r-- 2 root root  0  3月  1 13:52 2013 11.txt
-rw-r--r-- 2 root root 27  3月  1 14:07 2013 12.txt
-rw-r--r-- 2 root root  0  3月  1 13:53 2013 13.txt
-rw-r--r-- 2 root root 27  3月  1 14:07 2013 14.txt
....略....
-rw-r--r-- 2 root root  0  3月  1 14:00 2013 58.txt
-rw-r--r-- 2 root root  0  3月  1 13:52 2013 6.txt
-rw-r--r-- 2 root root 27  3月  1 14:07 2013 7.txt
-rw-r--r-- 2 root root  0  3月  1 13:52 2013 8.txt
-rw-r--r-- 2 root root  0  3月  1 13:52 2013 9.txt



ファイルの内容は同期されましたが、ファイルサイズが0のままです。
これをマウントポイントから読み出しを行うと即座に完全同期できます。

# find /mnt/gv -type f -exec dd if='{}' of=/dev/null bs=1M \; > /dev/null 2>&1

# ls -l /mnt/sgw
-rw-r--r-- 2 root root 27  3月  1 14:12 2013 1.txt
-rw-r--r-- 2 root root 27  3月  1 14:12 2013 10.txt
-rw-r--r-- 2 root root 27  3月  1 14:12 2013 11.txt
-rw-r--r-- 2 root root 27  3月  1 14:07 2013 12.txt
-rw-r--r-- 2 root root 27  3月  1 14:12 2013 13.txt
-rw-r--r-- 2 root root 27  3月  1 14:07 2013 14.txt
-rw-r--r-- 2 root root 27  3月  1 14:12 2013 15.txt
-rw-r--r-- 2 root root 27  3月  1 14:12 2013 16.txt
...略.....
-rw-r--r-- 2 root root 27  3月  1 14:12 2013 56.txt
-rw-r--r-- 2 root root 27  3月  1 14:12 2013 57.txt
-rw-r--r-- 2 root root 27  3月  1 14:12 2013 58.txt
-rw-r--r-- 2 root root 27  3月  1 14:14 2013 59.txt
-rw-r--r-- 2 root root 27  3月  1 14:12 2013 6.txt
-rw-r--r-- 2 root root 27  3月  1 14:14 2013 60.txt

これで同期が復旧しました。
その後も投入されつづけたファイルが同期されているのがわかります。




イニシエータインスタンスが落ちた場合




10.0.1.8をstopしてみます。




10.0.1.9では投入が反映され続けられています。
# ls -lrt /mnt/gv
.....略......
-rw-r--r-- 1 root root 27  3月  1 17:37 2013 562.txt
-rw-r--r-- 1 root root 27  3月  1 17:37 2013 563.txt
-rw-r--r-- 1 root root 27  3月  1 17:37 2013 564.txt
-rw-r--r-- 1 root root 27  3月  1 17:37 2013 565.txt
-rw-r--r-- 1 root root 27  3月  1 17:38 2013 566.txt
-rw-r--r-- 1 root root 27  3月  1 17:38 2013 567.txt
-rw-r--r-- 1 root root 27  3月  1 17:39 2013 568.txt
-rw-r--r-- 1 root root 27  3月  1 17:39 2013 569.txt
-rw-r--r-- 1 root root 27  3月  1 17:39 2013 570.txt
-rw-r--r-- 1 root root 27  3月  1 17:39 2013 571.txt
-rw-r--r-- 1 root root 27  3月  1 17:39 2013 572.txt
-rw-r--r-- 1 root root 27  3月  1 17:39 2013 573.txt
-rw-r--r-- 1 root root 27  3月  1 17:40 2013 574.txt
-rw-r--r-- 1 root root 27  3月  1 17:40 2013 575.txt
-rw-r--r-- 1 root root 27  3月  1 17:40 2013 576.txt
-rw-r--r-- 1 root root 27  3月  1 17:40 2013 577.txt
-rw-r--r-- 1 root root 27  3月  1 17:40 2013 578.txt
-rw-r--r-- 1 root root 27  3月  1 17:40 2013 579.txt
-rw-r--r-- 1 root root 27  3月  1 17:41 2013 580.txt
-rw-r--r-- 1 root root 27  3月  1 17:41 2013 581.txt


10.0.1.8をstartします。



SSHで入り、ブリックと、Glusterボリュームをマウントしなおします。

# df -h
Filesystem            Size  Used Avail Use% マウント位置
/dev/xvde1            6.0G  2.6G  3.1G  46% /
none                  3.7G     0  3.7G   0% /dev/shm

# mount /dev/sda /mnt/sgw
# mount -t glusterfs 10.0.1.8:/gv0 /mnt/gv
# ls -lrt /mnt/gv
.....略......
-rw-r--r-- 1 root root 27  3月  1 20:34 2013 1602.txt
-rw-r--r-- 1 root root 27  3月  1 20:34 2013 1603.txt
-rw-r--r-- 1 root root 27  3月  1 20:34 2013 1604.txt
-rw-r--r-- 1 root root 27  3月  1 20:34 2013 1605.txt
-rw-r--r-- 1 root root 27  3月  1 20:35 2013 1606.txt
-rw-r--r-- 1 root root 27  3月  1 20:35 2013 1607.txt
-rw-r--r-- 1 root root 27  3月  1 20:35 2013 1608.txt
-rw-r--r-- 1 root root 27  3月  1 20:35 2013 1609.txt
-rw-r--r-- 1 root root 27  3月  1 20:35 2013 1610.txt
-rw-r--r-- 1 root root 27  3月  1 20:35 2013 1611.txt
-rw-r--r-- 1 root root 27  3月  1 20:36 2013 1612.txt


# ls -lrt /mnt/sgw
.....略.....
rw-r--r-- 2 root root 27  3月  1 20:34 2013 1602.txt
-rw-r--r-- 2 root root 27  3月  1 20:34 2013 1603.txt
-rw-r--r-- 2 root root 27  3月  1 20:34 2013 1604.txt
-rw-r--r-- 2 root root 27  3月  1 20:34 2013 1605.txt
-rw-r--r-- 2 root root 27  3月  1 20:35 2013 1606.txt
-rw-r--r-- 2 root root 27  3月  1 20:35 2013 1607.txt
-rw-r--r-- 2 root root 27  3月  1 20:35 2013 1608.txt
-rw-r--r-- 2 root root 27  3月  1 20:35 2013 1609.txt
-rw-r--r-- 2 root root 27  3月  1 20:35 2013 1610.txt
-rw-r--r-- 2 root root 27  3月  1 20:35 2013 1611.txt
-rw-r--r-- 2 root root 27  3月  1 20:36 2013 1612.txt

マウントポイントに復帰され、投入が反映されています。
起動時に自動でマウントするにはfstabに以下のように設定します。

# cat /etc/fstab
/dev/sda         /mnt/sgw  ext4    _netdev         0 0
10.0.1.8:/gv0 /mnt/gv glusterfs defaults,_netdev 0 0


以上です。

2013年2月25日月曜日

StorageGatewayってなんじゃ?(Gatewayインスタンスの冗長化:GlusterFS編)

StorageGatewayのiSCSIボリュームをEC2にマウントし、アプリケーションシステムの中で使おうとする場合、冗長化という課題が持ち上がってきます。


ここで、いくつか冗長化の可能性を考えてみました。


マルチパス(


その場合、iSCSIとしての冗長化に合わせると、マルチパスという方法があるようです。
イメージとしては、以下のような感じでiSCSIターゲットであるgatewayインスタンスに複数のIPを付与し、それぞれの接続先の複数のデバイスを1つのデバイスとして認識させ、1つの接続が切れても他のNICで接続ができる方法です。



これはそもそもGatewayインスタンスの冗長化ではなく、ネットワーク・インターフェースの冗長化になりますが、ちょっと試してみます。
2番目のENIIを10.0.1.6として追加し、gatewayインスタンスにアタッチします。





そして、マウント用のEC2から10.0.1.6のiSCSIを調べてみますが、接続できないようです。
(既存のENIのセカンダリIPに付与しても同じでした。)
# iscsiadm --mode discovery --type sendtargets --portal 10.0.1.6:3260
iscsiadm: cannot make connection to 10.0.1.6: Connection refused
iscsiadm: cannot make connection to 10.0.1.6: Connection refused
iscsiadm: cannot make connection to 10.0.1.6: Connection refused


その後、ググってみると、いろいろなことがわかりました。

また、EC2インスタンスのゲートウェイには通常のログインができないようです。
替わりにAWSのサポートにトラブルシュートをしてもらうために以下のsshコマンドだけ受け付けているそうです。
ssh -i IDENTITY_FILE sguser@INSTANCE_IP_ADDRESS grant-aws-support-access
ssh -i IDENTITY_FILE sguser@INSTANCE_IP_ADDRESS revoke-aws-support-access
(試したところ、理由はわかりませんが、上記のコマンドもPermission denied (publickey).がでてアクセス出来ませんでした。。)



ソフトウェアRAID(


2つのGatewayインスタンスを複数のイニシエータにマウントしそれぞれでソフトウェアRAID1を試してみましたが、
一方の変更が他方のイニシエータ上に反映されませんでした。クラスタファイルシステムなどを利用する必要があるようです。





DRBD


DRBD + iSCSIはiSCSIターゲット側でDRBDを行うことが通常のようですが、Gateway on EC2ではGatewayインスタンスにはログインできないようなので、マウント側のEC2でDRBDを行うことになります。
このケースも試してみたいのですが、今回は見送ります。


GlusterFS


今回はGlusterFSという分散ファイルシステムを使用してみます。



前回の記事までは、Gatewayインスタンスが1つでしたがこれを2つにして、冗長化を図ります。
また、これらのGatewayインスタンスにさらに複数のイニシエータが接続し、それぞれが担当するGatewayのiSCSIをマウントし、もう一方をGlusterFSで互いをレプリカとしてミラーリングしあいます。

まず、前回と同じ手順でStorageGatewayをもう一つ登録し、Gatewayインスタンスを2つの状態にしておきます。
2つのGatewayインスタンスの内部IPは 10.0.1.5, 10.0.1.6とします。
また、マウント用のインスタンスを2つ用意し、10.0.1.8, 10.0.1.9とします。

そして、10.0.1.8は10.0.1.5の、10.0.1.9は10.0.1.6のGatewayインスタンスのiSCSIボリュームをそれぞれマウントします。


10.0.1.8
# mkdir /mnt/sgw
# iscsiadm  --mode node --targetname iqn.1997-05.com.amazon:memorycraft-sgw --portal 10.0.1.5:3260,1 --login

# ls -l /dev/disk/by-path/
合計 0
lrwxrwxrwx 1 root root  9  2月 25 00:08 2013 ip-10.0.1.5:3260-iscsi-iqn.1997-05.com.amazon:memorycraft-sgw-lun-0 -> ../../sda
lrwxrwxrwx 1 root root  9  2月 25 00:48 2013 ip-10.0.1.6:3260-iscsi-iqn.1997-05.com.amazon:memorycraft-sgw2-lun-0 -> ../../sdb
lrwxrwxrwx 1 root root 11  2月 23 17:54 2013 xen-vbd-2049 -> ../../xvde1

# mkfs.ext4 /dev/sda
# mount /dev/sda /mnt/sgw


10.0.1.9
# mkdir /mnt/sgw2
# iscsiadm  --mode node --targetname iqn.1997-05.com.amazon:memorycraft-sgw2 --portal 10.0.1.6:3260,1 --login


# ls -l /dev/disk/by-path/
合計 0
lrwxrwxrwx 1 root root  9  2月 25 00:08 2013 ip-10.0.1.5:3260-iscsi-iqn.1997-05.com.amazon:memorycraft-sgw-lun-0 -> ../../sda
lrwxrwxrwx 1 root root  9  2月 25 00:48 2013 ip-10.0.1.6:3260-iscsi-iqn.1997-05.com.amazon:memorycraft-sgw2-lun-0 -> ../../sdb
lrwxrwxrwx 1 root root 11  2月 23 17:54 2013 xen-vbd-2049 -> ../../xvde1


# mkfs.ext4 /dev/sdb
# mount /dev/sdb /mnt/sgw2


次に、10.0.1.8で10.0.1.9をGlusterのピアとして登録し、互いをレプリカとしてGlusterボリュームを作成します。

10.0.1.8
# gluster peer probe 10.0.1.9
# gluster volume create gv0 replica 2 10.0.1.8:/mnt/sgw 10.0.1.9:/mnt/sgw2

すると、双方にgv0というデバイスが接続されるので、これをglusterfsとしてマウントします。


10.0.1.8, 10.0.1.9
# mount -t glusterfs 10.0.1.8:/gv0 /mnt/gv
# ls -l /mnt/gv
drwx------  2 root root     16384  2月 25 00:47 2013 lost+found


一方でファイルを作成すると、

10.0.1.8
# echo "hoge" > /mnt/gv/hoge.txt


10.0.1.9
# ls -l /mnt/gv
-rw-r--r--  1 root root         5  2月 25 01:26 2013 hoge.txt
drwx------  2 root root     16384  2月 25 00:47 2013 lost+found


もう一方にも更新が反映されています。
また、一方のゲートウェイインスタンス(10.0.1.6)を落としても、、、


それぞれのイニシエータでは問題なくファイル操作できるようです。


10.0.1.8
# echo "111" > /mnt/gv/111.txt

# ls -l /mnt/gv/
-rw-r--r--  1 root root         5  2月 25 03:42 2013 111.txt
-rw-r--r--  1 root root         5  2月 25 01:26 2013 hoge.txt
drwx------  2 root root     16384  2月 25 00:47 2013 lost+found


10.0.1.9
# echo "222" > /mnt/gv/222.txt
# ls -l /mnt/gv/
-rw-r--r--  1 root root         5  2月 25 03:42 2013 111.txt
-rw-r--r--  1 root root         4  2月 25 03:42 2013 222.txt
-rw-r--r--  1 root root         5  2月 25 01:26 2013 hoge.txt
drwx------  2 root root     16384  2月 25 00:47 2013 lost+found


とりあえず、これで冗長化はできました。
GlusterFSはFUSEを使うこともあり少しパフォーマンスが落ちますが、
GlusterFSに関わらず、以下のような対策でパフォーマンスは上がるかもしれません。

  • fuseのバージョンを変えてみる
  • ファイルシステムをxfsにしてみる、
  • EBS-Optimizedインスタンスにしてみる
  • PIOPS-EBSにしてみる
  • GlusterFSを4台構成でstriped + replicaにしてみる
などなどです。

また、他のクラスタソリューションを試してみても良いかもしれません。

  • GFS
  • OCFS
  • Lustre
  • ....

また、lsyncd+rsyncdなど二重化をするほうほうなど方法はまだまだありますので、要件にあわせていろいろ探ってみるのも良いと思います。

以上です。

StorageGatewayってなんじゃ?(スナップショットからの復元)

前回、Storage GatewayをEC2にマウントしてみました。
運用中、ボリュームのデータがおかしくなったり、オペレーションミスで以前の状態に復旧したい場合があります。

その場合の定期的なスナップショットから復元する方法です。




ざっくりですが、少し試してみました。
まず、StorageGateway画面で、スナップショットをとりました。



スナップショットはEBSボリュームとして作成されるようで、StorageGatewayの「Snapshots」からも参照できます。




そして、「CreateVolume」を選択します。
すると、ボリューム作成画面が表示されますが、名前を「memorycraft-sgw2」、ホストIPを「10.0.1.5」にして「Create Volume」をクリックします。ちなみにホストIPをNICの別のIPを選ぶと、iSCSIのエンドポイントが変わるため、既存の接続が切れてしまうので注意が必要です。



すると、ボリュームが1つ追加されました。
そして、EC2のマウント用インスタンスで10.0.1.5のインターフェースを探してみると、、、
# iscsiadm --mode discovery --type sendtargets --portal 10.0.1.6:3260
10.0.1.5:3260,1 iqn.1997-05.com.amazon:memorycraft-sgw
10.0.1.5:3260,1 iqn.1997-05.com.amazon:memorycraft-sgw2


認識されました。とりあえず、このsgw2の方をログインしてみると、
# iscsiadm  --mode node --targetname iqn.1997-05.com.amazon:memorycraft-sgw2 --portal 10.0.1.5:3260,1 --login
Logging in to [iface: default, target: iqn.1997-05.com.amazon:memorycraft-sgw2, portal: 10.0.1.5,3260] (multiple)
Login to [iface: default, target: iqn.1997-05.com.amazon:memorycraft-sgw2, portal: 10.0.1.5,3260] successful.
# ls -l /dev/disk/by-path/
合計 0
lrwxrwxrwx 1 root root  9  2月 23 19:27 2013 ip-10.0.1.5:3260-iscsi-iqn.1997-05.com.amazon:memorycraft-sgw-lun-0 -> ../../sdb
lrwxrwxrwx 1 root root  9  2月 24 03:08 2013 ip-10.0.1.5:3260-iscsi-iqn.1997-05.com.amazon:memorycraft-sgw2-lun-0 -> ../../sda
lrwxrwxrwx 1 root root 11  2月 23 17:54 2013 xen-vbd-2049 -> ../../xvde1

sdaにアタッチできたようです。
また、sgwの方をログアウトします。
# iscsiadm  --mode node --targetname iqn.1997-05.com.amazon:memorycraft-sgw --portal 10.0.1.5:3260,1 --logout
Logging out of session [sid: 2, target: iqn.1997-05.com.amazon:memorycraft-sgw, portal: 10.0.1.5,3260]
Logout of [sid: 2, target: iqn.1997-05.com.amazon:memorycraft-sgw, portal: 10.0.1.5,3260] successful.


次にsdaの方を/mnt/sgwにマウントしなおします。
# umount /mnt/sgw
# mount /dev/sda /mnt/sgw

# ls -l /mnt/sgw
合計 44
drwxr-xr-x 14 root root  4096  2月 23 19:19 2013 cassandra
drwxr-xr-x 25 root root  4096  2月 23 19:12 2013 linux
drwxr-xr-x  3 root root  4096  2月 23 19:40 2013 linux2
drwx------  2 root root 16384  2月 23 18:37 2013 lost+found
drwxr-xr-x 28 root root  4096  2月 23 18:43 2013 perl
drwxr-xr-x  7 root root  4096  2月 23 19:18 2013 redis
drwxr-xr-x  4 root root  4096  2月 23 18:48 2013 symfony
drwxr-xr-x 11 root root  4096  2月 23 18:47 2013 v8


データが正しくコピーされたようです。
また、StorageGatewayではスナップショットを定期的にとるように設定することができます。
これらの操作はAPIでも提供されていますし、ある時点までの自動バックアップ-リストアはできそうです。


以上です。

2013年2月23日土曜日

Storage Gatewayってなんじゃ?(EC2のCentOSにS3をマウント)

AWSにStorageGatewayというサービスがあります。StorageGatewayはオンプレミスのデータをS3へ直接保存するための接続サービスですが、EC2の世界でも利用することができます。

今回は、StorageGatewayでS3の領域をVPC内のEC2にマウントしてみたいと思います。


ゲートウェイの作成


StorageGatewayの画面の左ペインに「Deploy a new Gateway on Amazon EC2」というリンクをクリックします。




するとダイアログが立ち上がり、アクティベーションダイアログが起ち上がります。
赤枠の「Launch Gateway AMI」のリンクをクリックします。



StorageGateway用のAMIの説明画面が開きます。
「Continue」ボタンをクリックします。




AMIの選択画面になり、「1-Click Launch」と「Launch with EC2 Console」のタブがあるので選択肢、TokyoリージョンのAMIをクリックします。料金表をみるとGatewayインスタンスはxlargeから使用可能のようです。




すると確認画面が表示されるので、「Continue」をクリックします。



先ほど「Launch with EC2 Console」を選んだので、EC2のダイアログが起ち上がります。
一番グレードの低いxlargeを選択し、今回はVPCのprivateサブネットを選択します。



あとは通常どおりに進んでいきます。ここではプライベートIPを10.0.1.5に割り当てます。




そのまま次へ進んでいきます。EBSボリュームの設定画面が表示されます。
StorageGatewayではストレージボリューム以外にもキャッシュやバッファ用のボリュームが必要です。ここで追加することも可能ですが、今回はこのまま進み、後から追加することにします。



セキュリティグループのところでは、あとでiscsiを使用するため、このインスタンスをマウントするEC2からiscsiインターフェスでマウントするためデフォルトポート3260をセキュリティグループに含めます。また、設定作業用のSSHポートもあけておきます。
  • 22  10.0.0.0/16
  • 3260 10.0.0.0/16




後はそのまま進み、インスタンスが起ち上がったらEIPを付与します。
VPCの場合でもアクティベーションに使用するので、一時的にEIPをつけておきます。




ここで、先ほどのStrageGatewayの画面にもどり、IPアドレス欄にEIPを入力して、「Proceed to Activation」をクリックします。



するとStrageGatewayのコンソールにゲートウェイのVMの設定が表示されます。
タイムゾーンを選択し、Gatewayの名前を入力して「Activate My Storage Gateway」をクリックします。


すると、以下のような画面になり、ゲートウェイが表示されます。



次に、キャッシュとバッファ用のEBSを作成し、ゲートウェイインスタンスにアタッチします。(インスタンス作成の時に同時に行なっても構いません)


StorageGatewayの画面に戻り、「Create Volume」をクリックするとダイアログが現れるので、キャッシュボリュームとアップロードバッファのデバイスをそれぞれ選択します。今回はキャッシュボリュームに20GB、バッファボリュームに10GBのボリュームを割り当てます。




「Next」をクリックすると、このキャッシュとバッファのボリュームのそれぞれ使用容量のアラームの設定画面が表示されるので、適宜設定していきます。
今回はデフォルトのままメールアドレスを入力し次へすすみます。




すると、ゲートウェイ用ボリュームの設定になります。ここでは実際に使用するファイルストレージとしての容量とiSCSIのターゲットのエンドポイントを決めるIDを入力します。
ここでは、容量は1TB、iSCSIターゲットのIDをmemorycraft-sgwとして最後に「Create Volume」ボタンをクリックします。




するとゲートウェイボリューム作成完了と表示されます。



ここまで出来たらゲートウェイ自体は完了です。




ゲートウェイボリュームをEC2(CentOS)にマウント


次に、作成したゲートウェイボリュームをEC2上のCentOSインスタンスにマウントします。

このボリュームをマウントするためのインスタンスを新たに立ち上げます。



ここから先は、このインスタンスにSSH接続しての設定になります。
StorageGatewayはiSCSIインターフェースなので、このインスタンスをiSCSIイニシエータにするための設定を行います。

まずiSCSIイニシエータツールをインストールして、設定ファイルをStorageGateway用に変更し、起動します。
AWSの資料では、設定は例としてカスタマイズしたほうがよいそうで、それにならって変更します。
実際には用途に応じて適切な値を設定することをお勧めします。
# yum install -y iscsi-initiator-utils
# vim /etc/iscsi/iscsid.conf
~

node.session.timeo.replacement_timeout = 600
node.conn[0].timeo.noop_out_interval = 60
node.conn[0].timeo.noop_out_timeout = 600

~
# /etc/init.d/iscsi start


iscsiadmコマンドでネットワーク内のiscsiターゲットを探してみます。
ゲートウェイインスタンスはVPC内で10.0.1.5を設定したため、10.0.1.5を探します。
# iscsiadm --mode discovery --type sendtargets --portal 10.0.1.5:3260
iscsid を起動中:                                           [  OK  ]
10.0.1.5:3260,1 iqn.1997-05.com.amazon:memorycraft-sgw


StorageGatewayで作成したボリュームが見つかりました。
これに接続します。
# iscsiadm  --mode node --targetname iqn.1997-05.com.amazon:memorycraft-sgw --portal 10.0.1.5:3260,1 --login
Logging in to [iface: default, target: iqn.1997-05.com.amazon:memorycraft-sgw, portal: 10.0.1.5,3260] (multiple)
Login to [iface: default, target: iqn.1997-05.com.amazon:memorycraft-sgw, portal: 10.0.1.5,3260] successful.


次に、デバイスとしてアタッチされているか見てみます。
# ls -l /dev/disk/by-path/
合計 0
lrwxrwxrwx 1 root root  9  2月 23 18:09 2013 ip-10.0.1.5:3260-iscsi-iqn.1997-05.com.amazon:memorycraft-sgw-lun-0 -> ../../sda
lrwxrwxrwx 1 root root 11  2月 23 17:54 2013 xen-vbd-2049 -> ../../xvde1


/dev/sdaにアタッチされているようです。
これをマウントしてみます。
# mkfs.ext4 /dev/sda

ke2fs 1.41.12 (17-May-2010)
/dev/sda is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
67108864 inodes, 268435456 blocks
13421772 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
8192 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
 102400000, 214990848

Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

# mkdir /mnt/sgw
# mount /dev/sda /mnt/sgw
# df -h

Filesystem            Size  Used Avail Use% マウント位置
/dev/xvde1            6.0G  2.6G  3.1G  47% /
none                  3.7G     0  3.7G   0% /dev/shm
/dev/sda             1008G  200M  957G   1% /mnt/sgw


おー、ちゃんと1TBがマウントされたようです。
ここに、以前s3syncのときにつかった大量のファイルを置いてみます。
# cd /mnt/sgw/

# git clone https://github.com/mirrors/perl.git
# git clone https://github.com/apache/cassandra.git
# git clone https://github.com/v8/v8.git
# git clone https://github.com/symfony/symfony.git
# git clone https://github.com/torvalds/linux.git

# tree -L 2 .
.
|-- cassandra
|   |-- CHANGES.txt
(略)
|   `-- tools
|-- linux
|   |-- COPYING
(略)
|   `-- virt
|-- perl
|   |-- AUTHORS
(略)
|   `-- x2p
(略)
|   `-- utils
|-- symfony
|   |-- CHANGELOG-2.0.md
(略)
|   `-- src
`-- v8
    |-- AUTHORS
(略)
    `-- tools

# du -sh

1.9G .


ファイル配置も問題ないようです。
また、s3cmdやs3fsのようにファイルリストの取得だけで重くなってしまうことはないようですが、キャッシュボリュームがあるためかも知れません。ファイル総量がキャッシュを超えた時の挙動などはまたの機会に試してみたいと思います。
また、EBSをPIOPSにしたり、EBSOptimizedインスタンスにした場合など、ボトルネックや、冗長化などなど考えると奥が深そうです。

現在のところでは、接続先のS3領域はS3コンソールやAPIからは秘匿されているようです。これらにアクセスできるとまた別の使い方ができるかもしれません。

以上です。