LoginSignup
0
1

More than 5 years have passed since last update.

WordPress with EFSでアンマウント / 再マウント

Posted at

昨日いろいろ遊んでいて、ふと「これ本当にマウントできてんのか?」という不安に駆られたので実験してみました。

スタックを作る

CloudFormationでElasticFileSystem(EFS)をEC2にマウントさせる - Qiita
AMIMOTO AMI + EFS + ELB + VPC周り諸々が立ち上がってきます。

マウントを外してみる

いきなり外そうとするとエラーになります。

$ sudo umount /var/www/vhosts/
umount.nfs4: /var/www/vhosts: device is busy

monitとnginxを停止させましょう。

[ec2-user@ip-10-0-0-201 ~]$ sudo service monit stop
Shutting down monit:                                       [  OK  ]
[ec2-user@ip-10-0-0-201 ~]$ sudo service nginx stop
Stopping nginx:                                            [  OK  ]

リトライ

[ec2-user@ip-10-0-0-201 ~]$ sudo umount /var/www/vhosts/

成功した場合は特に何もメッセージが出ません。

df -hするとマウントが外れているのがわかります。

[ec2-user@ip-10-0-0-201 ~]$ df -h
ファイルシス   サイズ  使用  残り 使用% マウント位置
/dev/xvda1       9.8G  4.2G  5.6G   43% /
devtmpfs         1.9G   64K  1.9G    1% /dev
tmpfs            1.9G     0  1.9G    0% /dev/shm
/dev/xvdb         15G   39M   15G    1% /media/ephemeral0

マウント先(/var/www/vhosts/)も以下のようにWordPressが綺麗になくなってます。

[ec2-user@ip-10-0-0-201 ~]$ ll /var/www/vhosts/i-4fe8feda/
合計 4
-rw-r--r-- 1 root root 175  6月 29 18:33 index.html

マウントしなおす

「fs-XXXX」はEFSのFile System IDです。

[ec2-user@ip-10-0-0-201 ~]$ sudo mount -t nfs4 -o nfsvers=4.1 $(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone).fs-XXXX.efs.us-east-1.amazonaws.com:/ /var/www/vhosts

マウントされていることを確認します。

[root@ip-10-0-0-201 log]# df -h
Filesystem                                            Size  Used Avail Use% Mounted on
/dev/xvda1                                            9.8G  4.2G  5.6G  43% /
devtmpfs                                              1.9G   68K  1.9G   1% /dev
tmpfs                                                 1.9G     0  1.9G   0% /dev/shm
/dev/xvdb                                              15G   39M   15G   1% /media/ephemeral0
us-west-2b.fs-xxxxxx.efs.us-east-1.amazonaws.com:/  8.0E     0  8.0E   0% /var/www/vhosts
[root@ip-10-0-0-201 log]# 

ファイルも復活しました。

[ec2-user@ip-10-0-0-201 ~]$ ll /var/www/vhosts/i-4fe8feda/
合計 192
-rw-r--r--  1 nginx nginx   418  6月 29 18:38 index.php
-rw-r--r--  1 nginx nginx 19935  6月 29 18:38 license.txt
-rw-r--r--  1 nginx nginx  1176  6月 29 18:37 local-config.php
-rw-r--r--  1 nginx nginx   774  6月 29 18:38 local-salt.php
-rw-r--r--  1 nginx nginx  7360  6月 29 18:39 readme.html
-rw-r--r--  1 nginx nginx  5032  6月 29 18:38 wp-activate.php
drwxr-xr-x  9 nginx nginx  4096  6月 29 18:37 wp-admin
-rw-r--r--  1 nginx nginx   364  6月 29 18:39 wp-blog-header.php
-rw-r--r--  1 nginx nginx  1476  6月 29 18:38 wp-comments-post.php
-rw-r--r--  1 nginx nginx  2853  6月 29 18:39 wp-config-sample.php
-rw-r--r--  1 nginx nginx  2751  6月 29 18:36 wp-config.php
drwxr-xr-x  7 nginx nginx  4096  6月 29 19:23 wp-content
-rw-r--r--  1 nginx nginx  3286  6月 29 18:38 wp-cron.php
drwxr-xr-x 16 nginx nginx  4096  6月 29 18:36 wp-includes
-rw-r--r--  1 nginx nginx  2380  6月 29 18:38 wp-links-opml.php
-rw-r--r--  1 nginx nginx  3316  6月 29 18:38 wp-load.php
-rw-r--r--  1 nginx nginx 33837  6月 29 18:38 wp-login.php
-rw-r--r--  1 nginx nginx  7887  6月 29 18:39 wp-mail.php
-rw-r--r--  1 nginx nginx 13106  6月 29 18:38 wp-settings.php
-rw-r--r--  1 nginx nginx 28624  6月 29 18:38 wp-signup.php
-rw-r--r--  1 nginx nginx  4035  6月 29 18:38 wp-trackback.php
-rw-r--r--  1 nginx nginx  3061  6月 29 18:38 xmlrpc.php

Nginxとmonitが止まってるので現状サイト表示はまだ復活しません。
ちゃんと起動させておきましょう。

[root@ip-10-0-0-201 log]# service nginx start
Starting nginx:                                            [  OK  ]
[root@ip-10-0-0-201 log]# service monit start
Starting monit: Monit start delay set -- pause for 5s
                                                           [  OK  ]

例に使った構成はEC2*1なので、特にEFSを使うメリットはないかもしれません。ですが、実際にEFSでマウント・アンマウントができるということが確認できただけでも進捗だなというところです。

0
1
0

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
0
1