0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MGNでAWS移行の大雑把の流れ

Last updated at Posted at 2025-11-25

MGNでAWS移行の大雑把の流れ

公式ドキュメント
https://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/connect-to-application-migration-service-data-and-control-planes-over-a-private-network.html

参考できそう情報
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
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?