AWS
vagrant
AmazonLinux

Vagrant Cloud に Amazon Linux 2 のイメージを公開した

さくっと Amazon Linux 2 を使いたかったので、Vagrant Cloud に登録してみた。

https://app.vagrantup.com/stakahashi/boxes/amazonlinux2

自分のためにも更新があれば更新していきたい所存。

TL;DR

$ vagrant init stakahashi/amazonlinux2
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'stakahashi/amazonlinux2' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'stakahashi/amazonlinux2'
    default: URL: https://vagrantcloud.com/stakahashi/amazonlinux2
==> default: Adding box 'stakahashi/amazonlinux2' (v2017.12) for provider: virtualbox
    default: Downloading: https://vagrantcloud.com/stakahashi/boxes/amazonlinux2/versions/2017.12/providers/virtualbox.box
==> default: Successfully added box 'stakahashi/amazonlinux2' (v2017.12) for 'virtualbox'!
==> default: Importing base box 'stakahashi/amazonlinux2'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'stakahashi/amazonlinux2' is up to date...
==> default: Setting the name of the VM: amazonlinux2_default_1513588712330_45863
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/mac-user/Documents/Vagrant/amazonlinux2
$ vagrant ssh
Last login: Mon Dec 18 08:58:01 2017 from gateway

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[vagrant@localhost ~]$ uname -a
Linux localhost.localdomain 4.9.62-10.57.amzn2.x86_64 #1 SMP Wed Dec 6 00:07:49 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Amazon Linux Extras repository の追加

Amazon Linux 2 では「Amazon Linux Extras repository」というリポジトリが提供されており、サポートされている言語・ソフトウェア等はこのリポジトリで提供されているようです。

https://aws.amazon.com/jp/amazon-linux-2/#Features

[root@localhost ~]# rpm -qa amazon-linux-extras
[root@localhost ~]# amazon-linux-extras list
  0  ansible2   disabled  [ =2.4.2 ]
  1  emacs   disabled  [ =25.3 ]
  2  memcached1.5   disabled  [ =1.5.1 ]
  3  nginx1.12   disabled  [ =1.12.2 ]
  4  postgresql9.6   disabled  [ =9.6.6 ]
  5  python3   disabled  [ =3.6.2 ]
  6  redis4.0   disabled  [ =4.0.5 ]
  7  R3.4   disabled  [ =3.4.3 ]
  8  rust1   disabled  [ =1.22.1 ]
  9  vim   disabled  [ =8.0 ]
 10  golang1.9   disabled  [ =1.9.2 ]
 11  ruby2.4   disabled  [ =2.4.2 ]
 12  nano   disabled  [ =2.9.1 ]
 13  php7.2   disabled  [ =7.2.0 ]

例: PHP7.2 をインストール

[root@localhost ~]# amazon-linux-extras install php7.2
  0  ansible2   disabled  [ =2.4.2 ]
  1  emacs   disabled  [ =25.3 ]
  2  memcached1.5   disabled  [ =1.5.1 ]
  3  nginx1.12   disabled  [ =1.12.2 ]
  4  postgresql9.6   disabled  [ =9.6.6 ]
  5  python3   disabled  [ =3.6.2 ]
  6  redis4.0   disabled  [ =4.0.5 ]
  7  R3.4   disabled  [ =3.4.3 ]
  8  rust1   disabled  [ =1.22.1 ]
  9  vim   disabled  [ =8.0 ]
 10  golang1.9   disabled  [ =1.9.2 ]
 11  ruby2.4   disabled  [ =2.4.2 ]
 12  nano   disabled  [ =2.9.1 ]
 13  php7.2=latest  enabled  [ =7.2.0 ]
[root@localhost ~]# php -v
PHP 7.2.0 (cli) (built: Dec 13 2017 00:38:30) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies