LoginSignup
6
5

More than 5 years have passed since last update.

EC2インスタンス起動時にインスタンスストアをRAID0にしてswapと任意のディレクトリにマウント

Last updated at Posted at 2015-04-12
  • c3.largeの16GB*2のディスクを
  • RAID0にして
  • パーティション切って
  • 10Gをアプリ置き場(/srv/www/*/releases)、残りをswapにマウントする例

下記をrc.localに追記。

rc.local
# create and mount instance−store disks as raid0(c3.large)
if [ ! -b /dev/md0 -a -b /dev/xvdb -a -b /dev/xvdc ]
then
    umount /dev/xvd[bc]
    yes | mdadm --create /dev/md0 --level=0 -c256 --raid-devices=2 /dev/xvd[bc]
    echo DEVICE /dev/xvdb /dev/xvdc > /etc/mdadm.conf
    mdadm --detail --scan >> /etc/mdadm.conf
    sfdisk /dev/md0 <<EOT
# partition table of /dev/md0
unit: sectors

/dev/md0p1 : start=     1024, size= 20971520, Id=83
/dev/md0p2 : start= 20972544, size= 42980352, Id=83
EOT
    seq 2 | xargs -I{} blockdev --setra 65536 /dev/md0p{}

    # create and mount xfs for application directory
    APPDIR=$(ls -d /srv/www/*/releases)
    APPDIR_OWNER=upuser

    mkfs.xfs /dev/md0p1 -Kf
    [ -e ${APPDIR}/* ] && rm ${APPDIR}/* -rf
    mount -t xfs -o rw,nodev,noatime,nodiratime,nobarrier,discard /dev/md0p1 ${APPDIR}

    chown ${APPDIR_OWNER}: ${APPDIR}
    sed -i -e '/\/mnt/d' -e '/\/dev\/md0p1/d' /etc/fstab
    echo -e "/dev/md0p1\t${APPDIR}\txfs\trw,nodev,noatime,nodiratime,nobarrier,discard,nofail\t0\t0" >> /etc/fstab

    # create and mount swap
    mkswap /dev/md0p2
    swapon /dev/md0p2
    sed -i '/\/dev\/md0p2/d' /etc/fstab
    echo -e "/dev/md0p2\tnone\tswap\tsw\t0\t0" >> /etc/fstab
fi

# deploy itself to master branch
# su ${APPDIR_OWNER} -lc 'cd /opt/capistrano ; cap production deploy'

参考:

6
5
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
6
5