はじめに Link to heading
前回の記事で、Terraform applyを実行してGCPインフラをデプロイしました。
今回は、DNS設定後に発生した問題を解決し、SSL証明書のプロビジョニングを完了させ、WordPress環境を本番稼働可能な状態にするまでの全工程を記録します。
📋 今回の作業フロー Link to heading
1. DNS設定と確認
↓
2. 起動スクリプトエラー発見(mysql-client不在)
↓
3. 修正 & 再デプロイ(Autoscaler問題)
↓
4. 起動スクリプトエラー再発(Logging Agent問題)
↓
5. 修正 & 再デプロイ
↓
6. SSL証明書プロビジョニング完了
↓
7. HTTPS動作確認 ✅
1. DNS設定と確認 Link to heading
設定内容 Link to heading
10ドメイン全てにAレコードを追加:
| ドメイン | タイプ | 値 |
|---|---|---|
| ai-jisso.tech | A | 34.50.146.93 |
| infra-career.tech | A | 34.50.146.93 |
| cloud-migration.tech | A | 34.50.146.93 |
| remote-dev.tech | A | 34.50.146.93 |
| monitoring-tools.tech | A | 34.50.146.93 |
| learn-code.tech | A | 34.50.146.93 |
| tech-books.tech | A | 34.50.146.93 |
| engineer-money.tech | A | 34.50.146.93 |
| travel-hack.tech | A | 34.50.146.93 |
| self-hosting.tech | A | 34.50.146.93 |
DNS確認コマンド Link to heading
1for domain in ai-jisso.tech infra-career.tech cloud-migration.tech; do
2 dig +short $domain A
3done
結果 Link to heading
34.50.146.93 ✅
34.50.146.93 ✅
34.50.146.93 ✅
... (全10ドメイン正常)
🎉 DNS設定完璧!
❌ 問題1: 起動スクリプトがmysql-clientで失敗 Link to heading
問題発見 Link to heading
VMインスタンスのシリアルポート出力を確認:
1gcloud compute instances get-serial-port-output prod-web-7511 \
2 --zone asia-northeast1-a | tail -50
エラー内容 Link to heading
E: Package 'mysql-client' has no installation candidate
Script "startup-script" failed with error: exit status 100
原因 Link to heading
Debian 12ではmysql-clientパッケージが存在しない
Debian 12から、MySQLクライアントパッケージ名が変更されました:
| Debian 11以前 | Debian 12 |
|---|---|
mysql-client | default-mysql-client |
解決方法 Link to heading
terraform/scripts/startup_script.sh を修正:
1# ❌ 修正前
2apt-get install -y \
3 ...
4 mysql-client \
5 nfs-common \
6
7# ✅ 修正後
8apt-get install -y \
9 ...
10 default-mysql-client \
11 nfs-common \
terraform apply実行 Link to heading
1cd terraform/environments/prod
2terraform apply -auto-approve
新たな問題: Autoscalerエラー Link to heading
Error: Error resizing RegionInstanceGroupManager: googleapi: Error 412:
Resizing of autoscaled regional managed instance groups is not allowed.
原因: Autoscalerが有効な状態でMIGのサイズ変更不可
解決: Autoscalerを一時停止
1gcloud compute instance-groups managed stop-autoscaling prod-web-mig \
2 --region=asia-northeast1
再度terraform apply Link to heading
1terraform apply -auto-approve
2
3# 成功!
4Apply complete! Resources: 1 added, 2 changed, 1 destroyed.
✅ 新しいインスタンステンプレート作成完了
❌ 問題2: 起動スクリプトがLogging Agentで失敗 Link to heading
ローリングアップデート確認 Link to heading
新しいVMインスタンスが起動:
1gcloud compute instances list --filter="labels.service=wordpress"
2
3# 結果
4prod-web-65vr asia-northeast1-a RUNNING (NEW)
5prod-web-jfxp asia-northeast1-b RUNNING (NEW)
6prod-web-7511 asia-northeast1-a RUNNING (OLD)
7prod-web-3t70 asia-northeast1-b RUNNING (OLD)
新VMのログ確認 Link to heading
1gcloud compute instances get-serial-port-output prod-web-65vr \
2 --zone asia-northeast1-a | tail -100
エラー内容 Link to heading
Err:2 https://packages.cloud.google.com/apt google-cloud-logging-bookworm-all Release
404 Not Found
E: The repository does not have a Release file.
Script "startup-script" failed with error: exit status 1
原因 Link to heading
旧Cloud Logging Agentのリポジトリが削除されている
Googleは旧Logging Agentを非推奨とし、Ops Agent(Logging + Monitoring統合)への移行を推奨しています。
解決方法 Link to heading
Ops Agentに置き換え:
1# ❌ 旧Cloud Logging Agent
2curl -sSO https://dl.google.com/cloudagents/add-logging-agent-repo.sh
3bash add-logging-agent-repo.sh --also-install
4
5# ✅ Ops Agent(Logging + Monitoring統合)
6curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh
7bash add-google-cloud-ops-agent-repo.sh --also-install
Ops Agentの利点 Link to heading
| 項目 | 旧Agent | Ops Agent |
|---|---|---|
| Logging | Cloud Logging Agent | ✅ 統合 |
| Monitoring | Cloud Monitoring Agent | ✅ 統合 |
| 設定 | 2つの設定ファイル | 1つの設定ファイル |
| パフォーマンス | 個別プロセス | 統合プロセス |
| サポート | 非推奨 | 推奨 |
terraform apply再実行 Link to heading
1terraform apply -auto-approve
再びAutoscalerエラー Link to heading
同じエラーが発生。Autoscalerを停止して再実行:
1gcloud compute instance-groups managed stop-autoscaling prod-web-mig \
2 --region=asia-northeast1
3
4terraform apply -auto-approve
5
6# 成功!
7Apply complete! Resources: 1 added, 2 changed, 1 destroyed.
✅ 起動スクリプト完了確認 Link to heading
新VMインスタンス確認 Link to heading
1gcloud compute instances list --filter="labels.service=wordpress"
2
3NAME ZONE STATUS CREATION_TIMESTAMP
4prod-web-tng4 asia-northeast1-c RUNNING 2025-11-16T05:34:24
5prod-web-pd9s asia-northeast1-a RUNNING 2025-11-16T05:36:45
起動スクリプトログ確認 Link to heading
1gcloud compute instances get-serial-port-output prod-web-pd9s \
2 --zone asia-northeast1-a | tail -50
結果 Link to heading
google-cloud-ops-agent installation succeeded. ✅
Finished google-startup-scripts.service ✅
🎉 両方のVM起動スクリプト完了!
🔧 Autoscalerの再有効化 Link to heading
停止していたAutoscalerを再度有効化:
1gcloud compute instance-groups managed set-autoscaling prod-web-mig \
2 --region=asia-northeast1 \
3 --mode=on \
4 --min-num-replicas=2 \
5 --max-num-replicas=4 \
6 --target-cpu-utilization=0.7 \
7 --cool-down-period=60
結果 Link to heading
1status: ACTIVE
2mode: ON
3recommendedSize: 2
4minNumReplicas: 2
5maxNumReplicas: 4
6cpuUtilization:
7 utilizationTarget: 0.7
✅ Autoscaler正常稼働
🔐 SSL証明書プロビジョニング完了! Link to heading
初回確認(DNS設定直後) Link to heading
1gcloud compute ssl-certificates describe prod-wordpress-ssl --global
結果(初回) Link to heading
| 状態 | ドメイン数 |
|---|---|
| ✅ ACTIVE | 3 |
| ⚠️ FAILED_NOT_VISIBLE | 7 |
FAILED_NOT_VISIBLE: GoogleがDNS経由でLoad Balancerを確認中
最終確認(約30分後) Link to heading
1gcloud compute ssl-certificates describe prod-wordpress-ssl --global \
2 --format="yaml" | grep -A 15 "domainStatus:"
結果(最終) Link to heading
1domainStatus:
2 ai-jisso.tech: ACTIVE ✅
3 cloud-migration.tech: ACTIVE ✅
4 engineer-money.tech: ACTIVE ✅
5 infra-career.tech: ACTIVE ✅
6 learn-code.tech: ACTIVE ✅
7 monitoring-tools.tech: ACTIVE ✅
8 remote-dev.tech: ACTIVE ✅
9 self-hosting.tech: ACTIVE ✅
10 tech-books.tech: ACTIVE ✅
11 travel-hack.tech: ACTIVE ✅
🎉 全10ドメインのSSL証明書がACTIVE!
プロビジョニング時間 Link to heading
| フェーズ | 時間 |
|---|---|
| DNS設定 | 即時 |
| DNS伝播 | 5-10分 |
| SSL検証 | 15-30分 |
| 合計 | 約30-40分 |
🚀 HTTPS動作確認 Link to heading
テスト1: HTTPSアクセス Link to heading
1for domain in ai-jisso.tech infra-career.tech cloud-migration.tech; do
2 echo "=== Testing HTTPS: $domain ==="
3 curl -I https://$domain/health
4done
結果 Link to heading
=== Testing HTTPS: ai-jisso.tech ===
HTTP/2 404 ✅ HTTP/2で応答!
=== Testing HTTPS: infra-career.tech ===
HTTP/2 404 ✅
=== Testing HTTPS: cloud-migration.tech ===
HTTP/2 404 ✅
404は正常: WordPressがまだインストールされていないため
テスト2: Health Check Link to heading
1curl -I -k https://34.50.146.93/health
結果 Link to heading
HTTP/2 200 ✅
Content-Type: text/plain
Content-Length: 8
🎉 HTTPS完全動作!
📊 最終構成 Link to heading
インフラサマリー Link to heading
| カテゴリ | リソース | 状態 |
|---|---|---|
| Network | VPC, Subnet×2, NAT, Firewall | ✅ 稼働中 |
| Compute | MIG (2-4台), Autoscaler | ✅ 稼働中 |
| Database | Cloud SQL HA, 10DB | ✅ 稼働中 |
| Storage | Filestore NFS (1TB) | ✅ 稼働中 |
| Load Balancer | Global HTTP(S) LB, CDN, WAF | ✅ 稼働中 |
| SSL | Google-managed SSL (10ドメイン) | ✅ ACTIVE |
| DNS | 10ドメイン → 34.50.146.93 | ✅ 設定済み |
| Monitoring | Ops Agent, Alert Policies | ✅ 稼働中 |
VMインスタンス詳細 Link to heading
| インスタンス | ゾーン | ステータス |
|---|---|---|
| prod-web-tng4 | asia-northeast1-c | RUNNING |
| prod-web-pd9s | asia-northeast1-a | RUNNING |
起動スクリプト実行内容 Link to heading
✅ システム更新(Debian 12) ✅ Nginx + PHP 8.2-FPM インストール ✅ WP-CLI インストール ✅ NFS マウント(Filestore) ✅ Nginx設定生成(10サイト分) ✅ PHP OPcache 最適化 ✅ WordPress セットアップスクリプト配置 ✅ Ops Agent インストール(Logging + Monitoring)
🎓 学んだこと Link to heading
1. Debian 12のパッケージ名変更に注意 Link to heading
Debian 12での変更点:
mysql-client→default-mysql-clientpython→python3- その他多数のパッケージ名変更
教訓: OSアップグレード時は公式ドキュメントを必ず確認
2. GCP Ops Agentへの移行 Link to heading
旧Agent vs Ops Agent:
| 項目 | 旧構成 | 新構成(Ops Agent) |
|---|---|---|
| プロセス数 | 2個 | 1個 |
| 設定ファイル | 2個 | 1個 |
| メモリ使用量 | 高め | 最適化 |
| サポート状況 | 非推奨 | 推奨 |
インストールコマンド:
1curl -sSO https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh
2bash add-google-cloud-ops-agent-repo.sh --also-install
3. Autoscaler有効時のMIG更新 Link to heading
問題: Autoscaler ONの状態でMIG更新不可
解決手順:
- Autoscalerを停止
- Terraform apply実行
- Autoscalerを再有効化
自動化の提案:
1# Terraformで自動管理
2lifecycle {
3 create_before_destroy = true
4}
4. SSL証明書プロビジョニングの待機時間 Link to heading
フェーズ別所要時間:
| フェーズ | 時間 | 確認方法 |
|---|---|---|
| DNS設定 | 即時 | dig +short |
| DNS伝播 | 5-10分 | 同上 |
| SSL検証 | 15-30分 | gcloud compute ssl-certificates describe |
| SSL ACTIVE | 30-60分 | 同上 |
Tips: FAILED_NOT_VISIBLEは一時的な状態。DNS伝播待ち。
5. HTTP/2対応の確認 Link to heading
確認コマンド:
1curl -I https://example.com
2# HTTP/2 200 ← HTTP/2で応答していることを確認
HTTP/2の利点:
- 多重化(Multiplexing)
- ヘッダー圧縮
- サーバープッシュ
- パフォーマンス向上
🔍 トラブルシューティングのベストプラクティス Link to heading
1. シリアルポート出力の活用 Link to heading
VMの起動スクリプトログを確認:
1gcloud compute instances get-serial-port-output <INSTANCE_NAME> \
2 --zone <ZONE> | tail -100
検索テクニック:
1# エラー検索
2| grep -i error
3
4# 特定のキーワード前後
5| grep -A 5 -B 5 "startup-script"
6
7# 最新ログのみ
8| tail -100
2. Terraform state管理 Link to heading
1# リソース一覧
2terraform state list
3
4# 特定リソース詳細
5terraform state show <RESOURCE>
6
7# State更新
8terraform refresh
3. GCP CLIでの直接確認 Link to heading
1# SSL証明書
2gcloud compute ssl-certificates list
3
4# MIG状態
5gcloud compute instance-groups managed describe <MIG_NAME> --region <REGION>
6
7# Autoscaler
8gcloud compute instance-groups managed describe <MIG_NAME> \
9 --region <REGION> --format="yaml" | grep -A 10 autoscaler
4. 段階的なロールバック Link to heading
問題発生時:
- Autoscaler停止
- 問題のあるVMを手動削除
- 修正後、terraform apply
- 動作確認
- Autoscaler再有効化
📝 コミット履歴 Link to heading
コミット1: mysql-client修正 Link to heading
1git commit -m "fix: terraform apply成功のための修正
2
3- Cloud SQL innodb_buffer_pool_sizeを4224MBに調整
4- Filestoreネットワーク設定修正
5- 起動スクリプトTerraform変数エスケープ
6- IAM Secret Manager権限調整
7- Instance Template Service Account Scope修正
8- Monitoring Log Sink Phase 2延期"
コミット2: 起動スクリプト修正 Link to heading
1git commit -m "fix: 起動スクリプトのパッケージエラーを修正
2
3## 修正内容
4
51. MySQL Clientパッケージ名修正
6 - mysql-client → default-mysql-client
7
82. Logging Agent を Ops Agent に更新
9 - 旧Cloud Logging Agent → Google Cloud Ops Agent
10 - Ops AgentはLogging + Monitoring統合
11
12## 検証結果
13
14✅ 新VM 2台で起動スクリプト正常完了
15✅ Health Check正常応答
16
17## デプロイ状況
18
19- VM: 2台稼働中
20- Load Balancer IP: 34.50.146.93
21- SSL証明書: 全10ドメインACTIVE
22- DNS: 全10ドメイン設定完了"
🚀 次のステップ Link to heading
1. WordPressインストール Link to heading
各サイトにWordPressをセットアップ:
1# VMにSSH接続
2gcloud compute ssh prod-web-pd9s --zone=asia-northeast1-a
3
4# WordPressセットアップ(サイト1)
5sudo /usr/local/bin/setup-wordpress-site.sh 1 ai-jisso.tech "AI実装ブログ"
6
7# 管理者パスワード取得
8gcloud secrets versions access latest \
9 --secret=prod-wordpress-admin-password-1
2. Ansibleプレイブック作成 Link to heading
自動化のため、Ansible Playbookを作成:
- WordPress一括インストール
- プラグイン導入(Cache、SEO等)
- テーマ設定
- 初期設定自動化
3. CI/CDパイプライン構築 Link to heading
- GitHub Actions
- Cloud Build
- 自動デプロイ
4. AIエージェント統合 Link to heading
- 運用監視
- 異常検知
- 自動復旧
まとめ Link to heading
今回、DNS設定からSSL証明書プロビジョニング完了までを実施し、いくつかの問題に遭遇しながらも解決しました。
解決した問題:
- ✅
mysql-clientパッケージ不在 →default-mysql-clientに変更 - ✅ 旧Logging Agent非推奨 → Ops Agentに移行
- ✅ Autoscaler競合 → 一時停止して更新
- ✅ SSL証明書プロビジョニング → 全10ドメインACTIVE
最終構成:
- ✅ VM 2台稼働(Autoscaler管理)
- ✅ HTTPS完全動作(HTTP/2)
- ✅ 全10ドメインSSL対応
- ✅ Health Check正常
- ✅ Ops Agent導入
重要な学び:
- Debianバージョンごとのパッケージ名変更に注意
- GCP推奨のOps Agentへの移行が必須
- Autoscaler有効時のMIG更新手順
- SSL証明書プロビジョニングには30-60分必要
- シリアルポート出力でのデバッグが有効
次回は、WordPress初期セットアップとAnsibleによる自動化を実施します!
参考リンク Link to heading
- infra-ai-agent リポジトリ
- コミット: e061cac (起動スクリプト修正完了)
- 前回の記事: Terraform Apply実践編
- Google Cloud Ops Agent
- Debian 12 Release Notes
- Google-managed SSL certificates
前回の記事: Terraform Apply実践編!GCPにWordPress環境をデプロイ【エラー解決の全記録】
次回予告: WordPress初期セットアップとAnsible自動化編