LoginSignup
24

More than 5 years have passed since last update.

EFS(Elastic File System)の作成メモ

Posted at

概要

EFS(Elastic File System)の作り方を確認した時のメモです。
確認用としてap-northeast-1aとap-northeast-1cにそれぞれEC2インスタンスを作成し、EFSで作成したファイルシステムをマウントします。

参考

VPC

VPCを作成したら「DNSホスト名の編集」で”はい”を選択します。
dns.png

この設定が”いいえ”の場合、EFSのファイルシステムのマウントが失敗します。

Failed to resolve "fs-ef6997ce.efs.ap-northeast-1.amazonaws.com" - check that your file system ID is correct.
See https://docs.aws.amazon.com/console/efs/mount-dns-name for more detail.

サブネットの作成

EC2インスタンスとEFSのマウントターゲットを作成するPublicサブネットをap-northeast-1aとap-northeast-1cに作成します。(説明は割愛しますがインターネットゲートウェイの作成とルートテーブルへの追加も行いました)
サブネット   VPC Management Console.png

インターネット側からアクセスできるように「IPv4の自動割り当て」を有効にします。
ipv4.png

セキュリティグループの作成

EC2に割り当てるセキュリティグループ

ローカルPCからsshで接続できるように、下記のインバウンドのルールを追加します。

タイプ プロトコル ポート範囲 ソース
SSH TCP 22 MyIP

EC2 Management Console.png

EFSのマウントターゲットに割り当てるセキュリティグループ

EC2インスタンスからEFSのマウントターゲットに接続できるように、下記のインバウンドのルールを追加します。
ポート範囲は2049を設定する必要があります。

タイプ プロトコル ポート範囲 ソース
NFS TCP 2049 EC2に割り当てたセキュリティグループのID

EC2 Management Console (1).png

EC2

EC2インスタンスの作成

publicサブネットのap-northeast-1aとap-northeast-1cにそれぞれ1つずつEC2インスタンスを作成します。
セキュリティグループには先に作成したEC2インスタンス用のセキュリティグループを指定します。

Amazon EFS マウントヘルパーのインストール

EC2インスタンスが立ち上がったらsshで接続し、updateとEFSマウントヘルパーのインストールを行います。

$ sudo yum update -y

Amazon EFS マウントヘルパーのインストール

$ sudo yum install -y amazon-efs-utils

マウントポイントの作成

EFSのマウントポイントは、/mnt/efsにしました。

$ sudo mkdir /mnt/efs

EFS

マウントターゲットの作成

アベイラビリティーゾーンとサブネットは、先に作成したサブネットを指定します。
セキュリティグループは、事前に作成したマウントターゲット用のセキュリティグループを指定します。
Elastic File System Management Console.png

オプション設定

パフォーマンスモードの選択

  • General Purpose
  • Max I/O

General Purposeパフォーマンスモードを選択しました。(デフォルト)

スループットモードの選択

  • Bursting
  • Provisioned

Burstingスループットモードを選択しました。(デフォルト)

暗号化の有効化

”保管時のデータの暗号化の有効化”はチェックしませんでした。(デフォルト)

Elastic File System Management Console (1).png

EFSを以下の設定で作成しました。
Elastic File System Management Console (2).png

EFSをマウントする

EFSをマウントするにはファイルシステムIDが必要です。
Elastic File System Management Console (3).png

DNS名

EFSはDNS名が設定されています。
それぞれのインスタンスからnslookupで調べると、アベイラビリティーゾーン毎のIPアドレスがわかります。

ap-northeast-1aから

$ nslookup fs-ef6997ce.efs.ap-northeast-1.amazonaws.com
Server:         10.0.0.2
Address:        10.0.0.2#53

Non-authoritative answer:
Name:   fs-ef6997ce.efs.ap-northeast-1.amazonaws.com
Address: 10.0.1.213

ap-northeast-1cから

$ nslookup fs-ef6997ce.efs.ap-northeast-1.amazonaws.com
Server:         10.0.0.2
Address:        10.0.0.2#53

Non-authoritative answer:
Name:   fs-ef6997ce.efs.ap-northeast-1.amazonaws.com
Address: 10.0.2.161

mountコマンド

$ sudo mount -t efs fs-ef6997ce:/ /mnt/efs
                    ^^^^^^^^^^^   ^^^^^^^^
                     |             |
                     |             +--- マウントポイント
                     +--- ファイルシステムID

確認

$ df -Th
Filesystem                                     Type      Size  Used Avail Use% Mounted on
devtmpfs                                       devtmpfs  476M     0  476M   0% /dev
tmpfs                                          tmpfs     493M     0  493M   0% /dev/shm
tmpfs                                          tmpfs     493M  328K  493M   1% /run
tmpfs                                          tmpfs     493M     0  493M   0% /sys/fs/cgroup
/dev/xvda1                                     xfs       8.0G  1.3G  6.8G  16% /
tmpfs                                          tmpfs      99M     0   99M   0% /run/user/1000
fs-ef6997ce.efs.ap-northeast-1.amazonaws.com:/ nfs4      8.0E     0  8.0E   0% /mnt/efs

umountコマンド

$ sudo umount /mnt/efs

自動的にマウントする

/etc/fstabファイルに下記の行を追加します。

fs-883ac4a9:/ /mnt/efs efs defaults,_netdev 0 0

補足

fioで性能計測

こちらの「fioを使ってストレージの性能を計測してみた」を参考にシーケンシャルリードの性能を計測してみました。

  • EBS : iops=6251
  • EFS : iops=2438

EBS

$ fio -filename=/tmp/test2g -direct=1 -rw=read -bs=4k -size=2G -numjobs=64 -runtime=10 -group_reporting -name=file1
file1: (g=0): rw=read, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
...
fio-2.14
Starting 64 processes
file1: Laying out IO file(s) (1 file(s) / 2048MB)
Jobs: 64 (f=64): [R(64)] [100.0% done] [23035KB/0KB/0KB /s] [5758/0/0 iops] [eta 00m:00s]
file1: (groupid=0, jobs=64): err= 0: pid=8508: Sun Sep 30 07:44:35 2018
  read : io=250320KB, bw=25004KB/s, iops=6251, runt= 10011msec
    clat (usec): min=407, max=15003, avg=10229.58, stdev=2856.49
     lat (usec): min=407, max=15004, avg=10230.13, stdev=2856.48
    clat percentiles (usec):
     |  1.00th=[  932],  5.00th=[ 1064], 10.00th=[10944], 20.00th=[11072],
     | 30.00th=[11072], 40.00th=[11072], 50.00th=[11072], 60.00th=[11072],
     | 70.00th=[11072], 80.00th=[11072], 90.00th=[11200], 95.00th=[11200],
     | 99.00th=[11712], 99.50th=[12096], 99.90th=[12608], 99.95th=[12736],
     | 99.99th=[13504]
    lat (usec) : 500=0.01%, 750=0.07%, 1000=2.80%
    lat (msec) : 2=5.86%, 4=0.05%, 10=0.13%, 20=91.09%
  cpu          : usr=0.11%, sys=0.03%, ctx=62600, majf=0, minf=724
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=62580/w=0/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=250320KB, aggrb=25004KB/s, minb=25004KB/s, maxb=25004KB/s, mint=10011msec, maxt=10011msec

Disk stats (read/write):
  xvda: ios=33406/2, merge=28456/0, ticks=337012/24, in_queue=337304, util=99.04%

EFS

$ sudo fio -filename=/mnt/efs/test2g -direct=1 -rw=read -bs=4k -size=2G -numjobs=64 -runtime=10 -group_reporting -name=file1
file1: (g=0): rw=read, bs=4K-4K/4K-4K/4K-4K, ioengine=psync, iodepth=1
...
fio-2.14
Starting 64 processes
file1: Laying out IO file(s) (1 file(s) / 2048MB)
Jobs: 64 (f=64): [R(64)] [100.0% done] [9456KB/0KB/0KB /s] [2364/0/0 iops] [eta 00m:00s]
file1: (groupid=0, jobs=64): err= 0: pid=8616: Sun Sep 30 07:48:51 2018
  read : io=97796KB, bw=9752.3KB/s, iops=2438, runt= 10028msec
    clat (msec): min=3, max=75, avg=26.15, stdev= 3.45
     lat (msec): min=3, max=75, avg=26.15, stdev= 3.45
    clat percentiles (usec):
     |  1.00th=[16064],  5.00th=[20352], 10.00th=[24960], 20.00th=[25472],
     | 30.00th=[25728], 40.00th=[25984], 50.00th=[26240], 60.00th=[26496],
     | 70.00th=[27264], 80.00th=[27776], 90.00th=[28032], 95.00th=[28544],
     | 99.00th=[31616], 99.50th=[33536], 99.90th=[71168], 99.95th=[72192],
     | 99.99th=[73216]
    lat (msec) : 4=0.01%, 10=0.08%, 20=4.63%, 50=95.03%, 100=0.26%
  cpu          : usr=0.06%, sys=0.01%, ctx=26570, majf=0, minf=669
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued    : total=r=24449/w=0/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: io=97796KB, aggrb=9752KB/s, minb=9752KB/s, maxb=9752KB/s, mint=10028msec, maxt=10028msec

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24