06. DB サーバーを構築する ー WordPress 構築ハンズオン ー
参考書
- Amazon Web Services 基礎からのネットワーク&サーバー構築 改訂版
- https://www.amazon.co.jp/dp/4822237443/ref=cm_sw_r_tw_dp_U_x_k3p3Cb7VX47T4
1. MySQL をインストールする
パブリックサブネットのインスタンス(web サーバー)を踏み台にして、プライベートサブネットのインスタンスに SSH 接続します。そこから、MySQL をインストールします。
ssh -i my-key.pem ec2-user@{パブリックサブネットのインスタンスの固定パブリック IP アドレス}
$ ssh -i my-key-db.pem ec2-user@10.0.2.10
$ sudo yum -y install mysql-server
- 4. インストールした MySQL を起動して、root ユーザーのパスワードを変更しておきます。
$ sudo service mysqld start --------- Initializing MySQL database: Installing MySQL system tables... 190519 22:51:52 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 190519 22:51:52 [Note] /usr/libexec/mysql55/mysqld (mysqld 5.5.62) starting as process 25366 ... OK Filling help tables... 190519 22:51:52 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap. 190519 22:51:52 [Note] /usr/libexec/mysql55/mysqld (mysqld 5.5.62) starting as process 25373 ... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/libexec/mysql55/mysqladmin -u root password 'new-password' /usr/libexec/mysql55/mysqladmin -u root -h ip-10-0-2-10 password 'new-password' Alternatively you can run: /usr/libexec/mysql55/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /usr/libexec/mysql55/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems at http://bugs.mysql.com/ [ OK ] Starting mysqld: [ OK ]
上記の起動時のメッセージ内に「root ユーザのパスワードをセットして下さい」とメッセージが表示されています。
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/libexec/mysql55/mysqladmin -u root password 'new-password' /usr/libexec/mysql55/mysqladmin -u root -h ip-10-0-2-10 password 'new-password'
記載されている内容に従って、root ユーザーのパスワードを変更しておきます。
$ mysqladmin -u root password New password: Confirm new password:
- 5. サーバーを再起動した場合に、自動的に MySQL が起動するようにしておきます。
$ sudo chkconfig mysqld on
→ これで、プライベートサブネット上のインスタンスに MySQL をインストールし、起動と簡単な初期設定が完了しました。(これで正式に DB サーバーとなりました。)
2. WordPress 用の DB を作成する
- 1. MySQL にログインします。パスワードを入力してログインが完了すると、下のウェルカムメッセージが表示されます。
$ mysql -u root -p Enter password: ---------- Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.5.62 MySQL Community Server (GPL) Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
- 2. DB を作成します。DB 名は「wordpress」とします。
mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; ---------- Query OK, 1 row affected (0.00 sec)
- 3. root 以外のユーザーを作成して、作成した DB への全ての権限を与えておきます。ユーザー名は「wordpress」、パスワードは「wordpresspasswd」とします。
mysql> grant all on wordpress.* to wordpress@"%" identified by 'wordpresspasswd'; ---------- Query OK, 0 rows affected (0.00 sec)
- 4. ユーザー作成・権限の設定を反映させます。
mysql> flush privileges; ---------- Query OK, 0 rows affected (0.00 sec)