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?

【RDS】DBサーバーを構築する

Last updated at Posted at 2025-10-26

前回記事
【EC2】Webサーバーを構築する

全体像

AWS.drawio.png
プライベートサブネットの中に、RDSを利用してDBサーバー(MySQL)を構築する。
WebサーバーからのみMySQLでDBサーバーに接続できるようにする。

RDSの作成準備

セキュリティグループの作成

EC2ダッシュボードに移動し、左のタブからセキュリティグループを選択
セキュリティグループを作成をクリック
FireShot Capture 037 - セキュリティグループ - EC2 - ap-northeast-1 - [ap-northeast-1.console.aws.amazon.com].png
セキュリティグループ名:自分で入力
VPC:作成したVPCを選択

インバウンドルールの設定

WebサーバーからのみMySQLでDBサーバーに接続できるようにする。
インバウンドルールでルールを追加をクリック
タイプ:MYSQL/Aurora
ソース:空白をクリックし、Webサーバーを構築したときに作成したセキュリティグループを選択
FireShot Capture 039 - CreateSecurityGroup - EC2 - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

DBサブネットグループの作成

Aurora and RDSダッシュボードに移動し、左のタブからサブネットグループを選択
DBサブネットグループを作成をクリック
FireShot Capture 040 - サブネットグループ - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png
名前:自分で入力
VPC:作成したVPCを選択
サブネット:作成した2つのプライベートサブネットを選択
作成をクリック
FireShot Capture 041 - Aurora and RDS - ap-northeast-1 - [ap-northeast-1.console.aws.amazon.com].png

DBパラメータグループの作成

Aurora and RDSダッシュボードに移動し、左のタブからパラメータグループを選択
パラメータグループの作成をクリック
FireShot Capture 042 - パラメータグループ - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png
パラメータグループ名:自分で入力
エンジンのタイプ:MySQL Community
パラメータグループファミリー:mysql8.0
FireShot Capture 043 - パラメータグループの作成 - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

DBオプショングループの作成

Aurora and RDSダッシュボードに移動し、左のタブからオプショングループを選択
グループを作成をクリック
FireShot Capture 045 - オプショングループ - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png
名前:自分で入力
エンジン:mysql
メジャーエンジンバージョン:8.0
FireShot Capture 046 - オプショングループの作成 - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

RDSの作成

Aurora and RDSダッシュボードに移動し、左のタブからデータベースを選択
データベースの作成をクリック
FireShot Capture 047 - データベース - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

エンジンのオプション

エンジンのタイプ:MySQL
FireShot Capture 048 - データベースの作成 - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

テンプレート

テンプレート:開発/テスト
FireShot Capture 049 - データベースの作成 - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

可用性と耐久性

デプロイオプション:シングル AZ DB インスタンスデプロイ (1 インスタンス)

設定

認証情報管理:セルフマネージド
マスターパスワード:自分で入力
FireShot Capture 050 - データベースの作成 - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

インスタンスの設定

DB インスタンスクラス:バースト可能クラス (t クラスを含む)
db.t3.micro

ストレージ

ストレージタイプ:汎用SSD(gp3)
ストレージ割り当て:20GiB
「ストレージの自動スケーリングを有効にする」のチェックを外す
FireShot Capture 051 - データベースの作成 - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

接続

VPC:作成したVPCを選択
DB サブネットグループ:作成したサブネットグループを選択
パブリックアクセス:なし
VPC セキュリティグループ (ファイアウォール):既存の選択

  • データベースのセキュリティグループを選択

アベイラビリティーゾーン:1a
FireShot Capture 052 - データベースの作成 - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

モニタリング

「拡張モニタリングの有効化」のチェックを外す
FireShot Capture 053 - データベースの作成 - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

追加設定

DBパラメータグループ:作成したDBパラメータグループを選択
オプショングループ:作成したオプショングループを選択
FireShot Capture 054 - データベースの作成 - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png

すべて設定が終わったら、データベースの作成をクリック

WebサーバーからRDSに接続

EC2ダッシュボードに移動し、左のタブからインスタンスを選択
作成したインスタンスを選択
画面の下にあるパブリックIpv4アドレスをコピーする
FireShot Capture 033 - インスタンス - EC2 - ap-northeast-1 - [ap-northeast-1.console.aws.amazon.com].png
ターミナルエミュレータTera TermでWebサーバーにSSH接続する
Tera Term3.png

WebサーバーにMySQLをインストール

sudo dnf -y install https://dev.mysql.com/get/mysql80-community-release-el9-5.noarch.rpm
sudo dnf -y install mysql mysql-community-client

WebサーバーからRDSへmysqlコマンドで接続

Aurora and RDSダッシュボードに移動し、左のタブからデータベースを選択
作成したデータベースをクリック
画面下にあるエンドポイントをコピーする
FireShot Capture 055 - aws-and-infra-web - データベースの詳細 - Aurora and RDS - ap-northeast-1_ - [ap-northeast-1.console.aws.amazon.com].png
ターミナルに移動
mysqlで接続する

mysql -h [DBのエンドポイント] -u [ユーザー名] -p

Tera Term5.png
mysql接続を終了する際はexit;を入力

次の記事
【EC2】WordPressを構築する

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?