EC2にswapを増やす

訳あってEC2のt2.nano(メモリ 0.5GB)でCPAMを使いたいけど、CPAMだけで300MB近くメモリを食うので、isntall処理がAbortしてしまう。

#  perl -MCPAN -e shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v2.16)
Enter 'h' for help.

cpan[1]> install Mail::IMAPClient
Reading '/root/.cpan/sources/authors/01mailrc.txt.gz'
............................................................................DONE
Reading '/root/.cpan/sources/modules/02packages.details.txt.gz'
  Database was generated on Tue, 10 Apr 2018 14:54:48 GMT
....................................................Killed

遅くてもinstallが出来ればいいので、SWAP付けて逃げる。

# free -m
              total        used        free      shared  buff/cache   available
Mem:            483         174         222          32          86         245
Swap:             0           0           0  ← SWAPがない

/var/swapfileを作成して、SWAPに当てる

# dd if=/dev/zero of=/var/swapfile bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 15.0153 s, 71.5 MB/s

# mkswap /var/swapfile
mkswap: /var/swapfile: insecure permissions 0644, 0600 suggested.
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=2311e423-13a4-4451-b081-05ac4074c8bf

# swapon /var/swapfile
swapon: /var/swapfile: insecure permissions 0644, 0600 suggested.

# free -m
              total        used        free      shared  buff/cache   available
Mem:            483         175           5          32         302         244
Swap:          1023           0        1023  ← SWAP増えた!