概要
クラウドで利用していたAWS(Amazon Web Service)のEC2/Cloud9の環境をVagrantでローカルに構築した記録。利用時の環境に併せて、OS、MySQL、Ruby、Railsのバージョンをできるだけ整合させた。
オリジナルの環境
- OS : Amazon Linux AMI release 2018.03
- MySQL : mysql Ver 14.14 Distrib 5.5.62, for Linux (x86_64) using readline 5.1
- Ruby : ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
- Rails : Rails 5.1.7
構築した環境
- OS(Box) : bento/amazonlinux-2 (virtualbox, 1.2.1)
- MySQL : Ver 14.14 Distrib 5.5.62, for Linux (x86_64) using readline 5.1
- Ruby : ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]
- Rails : Rails 5.1.7
Vagrant/VirtualBoxの導入
Vagrant – 仮想環境構築 – CentOS7を参照。
Boxの導入
ダウンロード
vagruntupのFind Boxesでキーワードamazonを含むBoxを検索し、bento/amazonlinux-2(1.2.1)を選択。
このBoxをvagrant add
コマンドでローカルに追加。
1 2 3 4 5 6 7 8 9 10 11 12 |
C:\>vagrant box add bento/amazonlinux-2 ==> box: Loading metadata for box 'bento/amazonlinux-2' box: URL: https://vagrantcloud.com/bento/amazonlinux-2 ==> box: Adding box 'bento/amazonlinux-2' (v1.2.1) for provider: virtualbox box: Downloading: https://vagrantcloud.com/bento/boxes/amazonlinux-2/versions/1.2.1/providers/virtualbox.box Download redirected to host: vagrantcloud-files-production.s3.amazonaws.com box: ==> box: Successfully added box 'bento/amazonlinux-2' (v1.2.1) for 'virtualbox'! C:\>vagrant box list bento/amazonlinux-2 (virtualbox, 1.2.1) bento/centos-7.7 (virtualbox, 202005.12.0) |
仮想環境の初期化
ディレクトリー\vagrant\amazonlinux2を作成・移動し、vagrant init
でダウンロードしたBoxで環境を構築。
1 2 3 4 5 |
C:\vagrant\amazon2>vagrant init bento/amazonlinux-2 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant. |
仮想環境の利用
仮想環境の起動
vagrant up
コマンドで仮想環境を起動。初回起動時は多数のパッケージインストールや依存関係の解決で時間がかかる。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
C:\vagrant\amazon2>vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Importing base box 'bento/amazonlinux-2'... ..... ==> default: Machine booted and ready![default] GuestAdditions versions on your host (6.1.18) and guest (6.1.16) do not match. Loaded plugins: dkms-build-requires, langpacks, priorities, update-motd ..... --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: elfutils-libelf-devel x86_64 0.176-2.amzn2 amzn2-core 40 k gcc x86_64 7.3.1-12.amzn2 amzn2-core 22 M kernel-devel x86_64 4.14.198-152.320.amzn2 amzn2-core 13 M kernel-devel x86_64 4.14.219-161.340.amzn2 amzn2-core 13 M Updating: perl x86_64 4:5.16.3-299.amzn2.0.1 amzn2-core 8.0 M Installing for dependencies: cpp x86_64 7.3.1-12.amzn2 amzn2-core 9.2 M glibc-devel x86_64 2.26-41.amzn2 amzn2-core 991 k ..... perl-libs x86_64 4:5.16.3-299.amzn2.0.1 amzn2-core 685 k Transaction Summary ================================================================================ Install 4 Packages (+ 4 Dependent packages) Upgrade 1 Package (+15 Dependent packages) Total download size: 84 M Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. -------------------------------------------------------------------------------- Total 829 kB/s | 84 MB 01:43 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : elfutils-libelf-devel-0.176-2.amzn2.x86_64 1/40 Updating : glibc-common-2.26-41.amzn2.x86_64 2/40 Updating : glibc-2.26-41.amzn2.x86_64 3/40 ..... Installed: elfutils-libelf-devel.x86_64 0:0.176-2.amzn2 gcc.x86_64 0:7.3.1-12.amzn2 kernel-devel.x86_64 0:4.14.198-152.320.amzn2 kernel-devel.x86_64 0:4.14.219-161.340.amzn2 Dependency Installed: cpp.x86_64 0:7.3.1-12.amzn2 glibc-devel.x86_64 0:2.26-41.amzn2 glibc-headers.x86_64 0:2.26-41.amzn2 kernel-headers.x86_64 0:4.14.219-161.340.amzn2 Updated: perl.x86_64 4:5.16.3-299.amzn2.0.1 Dependency Updated: glibc.x86_64 0:2.26-41.amzn2 ..... Complete!Copy iso file C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso ..... VirtualBox Guest Additions: Running kernel modules will not be replaced untilthe system is restarted ==> default: Mounting shared folders... default: /vagrant => C:/vagrant/amazon2 |
仮想環境へのログイン
vagrant ssh
コマンドで仮想環境にログイン。EC2のロゴが表示される。
1 2 3 4 5 6 7 8 9 10 11 12 13 |
C:\vagrant\amazon2>vagrant ssh __| __|_ ) _| ( / Amazon Linux 2 AMI ___|\___|___| https://aws.amazon.com/amazon-linux-2/ 46 package(s) needed for security, out of 66 available Run "sudo yum update" to apply all updates. This system is built by the Bento project by Chef Software More information can be found at https://github.com/chef/bento [vagrant@vagrant ~]$ |
システム情報
リリースの表現が違っている。
構築したシステム情報
1 2 3 4 5 6 7 8 9 10 11 12 |
[vagrant@vagrant ~]$ cat /etc/system-release Amazon Linux release 2 (Karoo) [vagrant@vagrant ~]$ cat /etc/os-release NAME="Amazon Linux" VERSION="2" ID="amzn" ID_LIKE="centos rhel fedora" VERSION_ID="2" PRETTY_NAME="Amazon Linux 2" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2" HOME_URL="https://amazonlinux.com/" |
オリジナルのシステム情報
1 2 3 4 5 6 7 8 9 10 11 12 |
$ cat /etc/system-release Amazon Linux AMI release 2018.03 $ cat /etc/os-release NAME="Amazon Linux AMI" VERSION="2018.03" ID="amzn" ID_LIKE="rhel fedora" VERSION_ID="2018.03" PRETTY_NAME="Amazon Linux AMI 2018.03" ANSI_COLOR="0;33" CPE_NAME="cpe:/o:amazon:linux:2018.03:ga" HOME_URL="http://aws.amazon.com/amazon-linux-ami/" |
ロケールとタイムゾーンの設定
確認
タイムゾーンがUTC、ロケールはLANG=enになっている。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
[vagrant@vagrant ~]$ date Sun Mar 7 21:29:29 UTC 2021 [vagrant@vagrant ~]$ locale LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL= [vagrant@vagrant ~]$ localectl System Locale: LANG=en_US.UTF-8 VC Keymap: n/a X11 Layout: n/a |
ロケールの設定
ロケールをJPに設定して再起動。表現は日本語になるが、まだタイムゾーンはUTC。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[vagrant@vagrant ~]$ sudo localectl set-locale LANG=ja_JP.UTF-8 [vagrant@vagrant ~]$ date Sun Mar 7 21:31:03 UTC 2021 [vagrant@vagrant ~]$ exit logout Connection to 127.0.0.1 closed. C:\vagrant\amazonlinux2>vagrant ssh Last login: Sun Mar 7 21:29:03 2021 from 10.0.2.2 Last login: Sun Mar 7 21:29:03 2021 from 10.0.2.2 __| __|_ ) _| ( / Amazon Linux 2 AMI ___|\___|___| https://aws.amazon.com/amazon-linux-2/ 45 package(s) needed for security, out of 65 available Run "sudo yum update" to apply all updates. This system is built by the Bento project by Chef Software More information can be found at https://github.com/chef/bento [vagrant@vagrant ~]$ date 2021年 3月 7日 日曜日 21:32:23 UTC |
timedatectl
で現在のロケールを確認。UTC。
1 2 3 4 5 6 7 8 9 |
[vagrant@vagrant ~]$ timedatectl Local time: 日 2021-03-07 21:34:01 UTC Universal time: 日 2021-03-07 21:34:01 UTC RTC time: 日 2021-03-07 21:33:54 Time zone: n/a (UTC, +0000) NTP enabled: yes NTP synchronized: no RTC in local TZ: no DST active: n/a |
タイムゾーンの設定
timedatectl list-timezones
で設定可能なタイムゾーンを確認。
1 2 3 4 5 6 7 |
[vagrant@vagrant ~]$ timedatectl list-timezones Africa/Abidjan Africa/Accra Africa/Addis_Ababa ..... Asia/Tokyo ..... |
タイムゾーンをAsia/Tokyo
に設定。
1 2 3 4 5 6 7 8 9 10 11 12 |
[vagrant@vagrant ~]$ sudo timedatectl set-timezone Asia/Tokyo [vagrant@vagrant ~]$ date 2021年 3月 8日 月曜日 06:37:47 JST [vagrant@vagrant ~]$ timedatectl Local time: 月 2021-03-08 06:37:51 JST Universal time: 日 2021-03-07 21:37:51 UTC RTC time: 日 2021-03-07 21:37:45 Time zone: Asia/Tokyo (JST, +0900) NTP enabled: yes NTP synchronized: no RTC in local TZ: no DST active: n/a |
その他の設定
共有設定、Atomでの接続はCentOS7と同じ手順で完了。