Apache サーバーの移行計画をカスタマイズする

移行の準備で作成した移行計画ファイルを確認し、移行を実行する前にファイルをカスタマイズします。移行計画の詳細は、ソースからワークロード コンテナ アーティファクトを抽出する際に使用されます。

このドキュメントでは、移行の内容と、移行を実行してデプロイ アーティファクトを生成する前に考慮すべきカスタマイズについて説明します。

始める前に

  • このトピックでは、すでに移行を準備し、移行計画ファイルが作成されていることを前提としています。

移行計画を編集する

移行計画を編集するには、migctl ツールまたは Google Cloud コンソールを使用します。

migctl

移行計画をダウンロードしてから編集する必要があります。

  1. 移行計画をダウンロードします。

    migctl migration get my-migration
    
  2. ダウンロードした移行計画 my-migration.yaml をテキスト エディタで編集します。

  3. 編集が完了したら、修正した移行計画を保存してアップロードします。

    migctl migration update my-migration --main-config my-migration.yaml
    
  4. さらに編集が必要な場合は、上記の手順を繰り返します。

コンソール

YAML エディタを使用して Google Cloud コンソールで移行プランを編集します。

  1. Google Cloud コンソールで [Migrate to Containers] ページを開きます。

    [Migrate to Containers] ページに移動

  2. [移行] タブをクリックして、使用可能な移行を含むテーブルを表示します。

  3. 目的の移行の行で移行の名前を選択し、[詳細] タブを開きます。

  4. [YAML] タブを選択します。

  5. 必要に応じて、移行計画を編集します。

  6. 編集が完了したら、次のいずれかの操作を行います。

    1. 移行計画を保存する。その後、移行アーティファクトを手動で生成して移行する必要があります。移行の実行の手順を行います。

    2. アーティファクトを保存して生成する。編集内容を使用して、移行アーティファクトを生成し、移行を実施します。このプロセスは、移行の実行で説明する方法と同じです。その後、移行のモニタリングの説明に従って移行をモニタリングします。

CRD

移行計画をダウンロードして編集し、適用する必要があります。移行計画は、AppXGenerateArtifactsFlowSpec CRD の appXGenerateArtifactsConfig フィールドに保存されます。

  1. AppXGenerateArtifactsFlow の名前を取得します。

    kubectl get migrations.anthos-migrate.cloud.google.com -n v2k-system -o jsonpath={.status.migrationPlanRef.name} my-migration

    命名パターンは appx-generateartifactsflow-id の形式で返されます。

  2. 移行計画を名前で取得し、my-plan.yaml という名前のファイルに書き込みます。

    kubectl -n v2k-system get appxgenerateartifactsflows.anthos-migrate.cloud.google.com -o jsonpath={.spec.appXGenerateArtifactsConfig} appx-generateartifactsflow-id > my-plan.yaml
  3. 必要に応じて、移行計画を編集します。

  4. ファイルを適用します。

    kubectl patch appxgenerateartifactsflows.anthos-migrate.cloud.google.com --type merge -n v2k-system --patch '{"spec": {"appXGenerateArtifactsConfig": '"$(jq -n --rawfile plan my-plan.yaml '$plan')"'}}' appx-generateartifactsflow-id

移行計画の構造

Apache2 ワークロードの移行プランの構造は次のとおりです。この構造は、次のセクションで説明するようにカスタマイズできます。

apacheServer:
  # Apache configuration for directories on the system
  # Content is the configuration as understood by apache
  directories:
  - Content: |-
      Options FollowSymLinks
      AllowOverride None
      Require all denied
    Path: /
  - Content: |-
      AllowOverride None
      Require all granted
    Path: /usr/share
  - Content: |-
      Options Indexes FollowSymLinks
      AllowOverride None
      Require all granted
    Path: /var/www/
  - Content: "#\tOptions Indexes FollowSymLinks\n#\tAllowOverride None\n#\tRequire
      all granted"
    Path: /srv/
  - Content: |-
      #   AllowOverride None
      #   Require all denied
    Path: /
  # Environment variables used by apache
  envVars:
  - Value: www-data
    Var: APACHE_RUN_USER
  - Value: www-data
    Var: APACHE_RUN_GROUP
  - Value: /var/run/apache2$SUFFIX/apache2.pid
    Var: APACHE_PID_FILE
  - Value: /var/run/apache2$SUFFIX
    Var: APACHE_RUN_DIR
  - Value: /var/lock/apache2$SUFFIX
    Var: APACHE_LOCK_DIR
  - Value: /var/log/apache2$SUFFIX
    Var: APACHE_LOG_DIR
  - Value: C
    Var: LANG
  # The port the service will listen on
  listen:
  - "80"
  - "443"
  # Apache modules to be loaded and installed
  loadModules:
  - Module: access_compat_module
  - Module: alias_module
  - Module: auth_basic_module
  - Module: authn_core_module
  - Module: authn_file_module
  - Module: authz_core_module
  - Module: authz_host_module
  - Module: authz_user_module
  - Module: autoindex_module
  - Module: deflate_module
  - Module: dir_module
  - Module: env_module
  - Module: filter_module
  - Module: mime_module
  - Module: mpm_prefork_module
  - Module: negotiation_module
  - Module: php7_module
  - Module: proxy_module
  - Module: proxy_fcgi_module
  - Module: reqtimeout_module
  - Module: rewrite_module
  - Module: setenvif_module
  - Module: socache_shmcb_module
  - Module: ssl_module
  - Module: status_module
  # The sites to be extracted
  virtualHosts:
  - address: '*:80'
    documentRoot: /var/www/html
    # should the site be enabled in extracted VM
    includeInContainerImage: true
    originalConfig: |-
      # The ServerName directive sets the request scheme, hostname and port that
      # the server uses to identify itself. This is used when creating
      # redirection URLs. In the context of virtual hosts, the ServerName
      # specifies what hostname must appear in the request's Host: header to
      # match this virtual host. For the default virtual host (this file) this
      # value is not decisive as it is used as a last resort host regardless.
      # However, you must set it for any further virtual host explicitly.
      #ServerName www.example.com

      ServerAdmin webmaster@localhost
      DocumentRoot /var/www/html

      # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
      # error, crit, alert, emerg.
      # It is also possible to configure the loglevel for particular
      # modules, e.g.
      #LogLevel info ssl:warn

      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined

      # For most configuration files from conf-available/, which are
      # enabled or disabled at a global level, it is possible to
      # include a line for only one particular virtual host. For example the
      # following line enables the CGI configuration for this host only
      # after it has been globally disabled with "a2disconf".
      #Include conf-available/serve-cgi-bin.conf
    serverName: server-0
  - address: '*:443'
    # The location of the site content (will be copied to the same location the extracted container)
    documentRoot: /var/www/html
    includeInContainerImage: false
    originalConfig: |-
      ServerAdmin admin@example.com
      DocumentRoot /var/www/html
      SSLEngine on
      SSLCertificateFile /etc/ssl/certs/c2d-temporary-self-signed-cert.pem
      SSLCertificateKeyFile /etc/ssl/private/c2d-temporary-self-signed-cert.key

      <Directory /var/www/html>
      Options -Indexes
      AllowOverride FileInfo
      </Directory>
    serverName: server-1
php:
  # list of php modules to be installed in the extracted container (add/remove entries to change what will be installed)
  modules:
  - calendar
  - ctype
  - curl
  - exif
  - ffi
  - fileinfo
  - filter
  - gd
  - gettext
  - iconv
  - json
  - mysqli
  - pcntl
  - pdo
  - pdo_mysql
  - posix
  - shmop
  - sockets
  - sysvmsg
  - sysvsem
  - sysvshm
  - tokenizer
  - xsl

ディレクトリに対してセキュリティ ポリシーを構成する

directories セクションでは、特定の構成を適用して、特定のディレクトリにセキュリティ ポリシーを適用できます。プランのこのセクションに入力して編集するには、Directory ディレクティブの構文を使用します。

モジュールの読み込みとインストール

loadModules セクションでは、読み込んでインストールするモジュールを指定できます。Migrate to Containers は、LoadModule ディレクティブの元の構成をスキャンして、必要なモジュールを自動的に検出します。

サポートされているモジュール

access_compat_module
alias_module
auth_basic_module
authn_core_module
authn_file_module
authz_core_module
authz_host_module
authz_user_module
autoindex_module
deflate_module
dir_module
env_module
expires_module
filter_module
mime_module
mpm_prefork_module
negotiation_module
php7_module
proxy_fcgi_module
proxy_module
remoteip_module
reqtimeout_module
rewrite_module
setenvif_module
socache_shmcb_module
ssl_module
status_module

仮想ホストの指定と構成

virtualHosts セクションで、Migrate to Containers は <VirtualHost> ブロックと </VirtualHost> ブロックで囲まれているすべてのディレクティブをコピーします。

address フィールドで、サイトの IP アドレスが * に置き換えられます。

originalConfigDocumentRoot フィールドには、リクエストされたファイルを Apache が提供するパスを指定します。DocumentRoot で指定されたパスごとに、Migrate to Containers は次の処理を行います。

  • 各パスを個別の tar ファイルに圧縮します。
  • この tar ファイルをアーティファクトにコピーします。
  • Dockerfile の ADD --chown オプションを使用して、Docker イメージのユーザーの権限を変更します。

PHP 拡張機能を確認する

Migrate to Containers は、VM にインストールされている PHP モジュールを自動的に検出し、移行プランの php セクションに追加します。このセクションを確認して、必要に応じてモジュールを追加または削除してください。

次のステップ