MGNでAWS移行の大雑把の流れ
参考できそう情報
https://dev.classmethod.jp/articles/aws-mgn-over-private-network/
https://ent.iij.ad.jp/articles/2344/
https://frontse.hatenablog.jp/entry/2022/01/29/233728
https://syuntech.net/aws/application-migration-service/
■対象サーバー
target-ec2-server
■VMで エージェントのインストールする前に MGN(AWSコンソール)で先に Template を作成する必要がある
1.General launch settings
Instance type right sizing=None
2.EC2 Launch Template
テンプレートバージョンの説明=<サーバー名>
インスタンスタイプ=見積もったタイプを指定
ネットワーク設定=VPC利用を選択
ストレージのサイズ=見積もった値を指定
ボリュームタイプ=GP3
IOPS=3000
リソースタグ=KEY=App、VALUE=サーバー組名(codedeploy用の設定)
ネットワークインターフェイス=New Interface
サブネット=事前に作成
セキュリティグループ(ネットワークインターフェイス)=事前に作成
パブリック IP の自動割り当て=選択しない(Public IP指定しない)
終了保護=有効化
IAM インスタンスプロフィール=事前に作成(codedeployなど利用)
CloudWatchモニタリング=有効化
ユーザーデータ=cloud-initで書く(サーバー初期設定用)
3.作成した起動テンプレートを選択して アクション>デフォルトバージョンを設定 をクリック
デフォルトのバージョンを設定したあと、作成した起動テンプレートが反映されていることを確認しています。
ntp設定がそのまま。変更しましょう。
Amazon Time Sync Service のIPに変更する。169.254.169.123
■作業
①VMにエージェントのインストール(MGN関連)
python3 aws-replication-installer-init.py --region us-east-1 --aws-access-key-id --aws-secret-access-key --no-prompt
②MGNインストール用のコマンド
wget -O ./aws-replication-installer-init.py https://aws-application-migration-service-ap-northeast-1.s3.amazonaws.com/latest/linux/aws-replication-installer-init.py
③cloud-init設定
サーバー初期設定で使う。
こんな感じ
#cloud-config
ssh_pwauth: yes
package_update: false
package_upgrade: false
preserve_hostname: false
hostname: <server-name>
fqdn: <server-hostname>
manage_etc_hosts: true
locale: ja_JP.UTF-8
timezone: Asia/Tokyo
groups:
- ubuntu
users:
- name: ubuntu
shell: /bin/bash
primary_group: ubuntu
homedir: /home/ubuntu
sudo: ['ALL=(ALL) NOPASSWD:ALL']
lock_passwd: true
ssh-authorized-keys:
# EC2にSSHログイン用
- ssh-rsa xxxxxxxxxxxxx
runcmd:
# Amazon Time Sync Service に ntpサーバーを変更
- sed -i'' -e's/^server xxx.yyy.zzz.aaa/server 169.254.169.123/' /etc/ntp.conf
# Codedeployインストール
- cd /tmp/ && apt-get update && wget https://aws-codedeploy-ap-northeast-1.s3.ap-northeast-1.amazonaws.com/latest/install && chmod +x ./install && ./install auto
# Composerインストール
- export HOME=/root && curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer --version=1.8.5
- usermod -p $(openssl passwd -1 <login_password>) <user_name>
- usermod -s /bin/bash -p $(openssl passwd -1 <login_password>) <user_name>
- passwd -e <user_name>
# 新しいディレクトリ用意
- mkdir /home/xxxxxxxx/xxxxxxx
write_files:
# ヘルスチェック用のvhost を追加
- content: |
<VirtualHost *:80>
ServerName <server-hostname>
DocumentRoot /var/excite/<server-name>/htdocs
</VirtualHost>
owner: root:root
path: /etc/apache2/sites-available/001_<server-hostname>.conf
permissions: '0755'
# 元サーバーにはヘルスチェック用ファイルがないので、新規作成します
- content: |
<?php
echo "mb_internal_encoding: " . mb_internal_encoding(). "<br>\n";
echo "mb_get_info: " . mb_get_info("internal_encoding") . "<br>\n";
echo "ini_get: " . ini_get("mbstring.internal_encoding");
phpinfo();
owner: root:root
path: /var/excite/<server-hostname>/htdocs/index.php
permissions: '0755'
power_state:
delay: now
mode: reboot