Migration of MariaDB to a Different EC2 Instance
Ref: https://learn.cantrill.io/courses/1820301/lectures/41301418
- Following instructions, WP installed in monolith instance + blog post with images created
- 💡 Media in this WP blog post is stored in the local FS. The media will need to be migrated to a shared FS when moving to a fully elastic architecture, since media should not be stored inside EC2 instances.
- Migration of MariaDB in monolith instance to a different EC2 instance (IP=10.16.59.228):
-
Create backup of source DB:
mysqldump -u root -p a4lwordpress > a4lwordpress.sql
-
Restore backup to destination DB:
mysql -h 10.16.59.228 -u a4lwordpress -p a4lwordpress < a4lwordpress.sql
-
Update WP configuration:
sudo nano /var/www/html/wp-config.php
-
Replace:
/** MySQL hostname */
define('DB_HOST', 'localhost');
With:
/** MySQL hostname */
define('DB_HOST', '10.16.59.228');
-
Stop the MariaDB service in the original instance, since it's not needed there any more:
sudo service mariadb stop
Migration of MariaDB to RDS (Free tier)
PART 1: Creation of an RDS instance (free tier)
Ref: https://learn.cantrill.io/courses/1820301/lectures/41301420
- Before deploying an RDS instance, create a DB subnet group
- A DB subnet group can include subnets from different AZs of the VPC
- Select subnets that have been marked/named for the DB tier when creating the VPC
- 💡 CIDRs of each subnet can be checked in VPC service
- RDS instance creation wizard → lots of options/configuration:
- âť—Â Choice of DB engine + version is critical (each version has its limitations)
- e.g. if you intend to import a DB snapshot it into an Aurora cluster, you need a version that is compatible with Aurora!
- Templates for PROD, DEV/TEST and Free tier
- Current free tier limited to burstable class & doesn't allow Multi-AZ mode (only one single RDS instance)
- More configurable options: DB instance identifier, storage, backups…
- ‼️ A Security Group (SG) needs to be assigned to the new RDS instance!
- controls what can go into the DBs and who can read them
- An initial DB can be configured (optional)
- By default, no DBs configured in a new RDS instance
- Once provisioned, every RDS instance gets an endpoint CNAME and endpoint port
- Use them to connect to the instance
PART 2: MariaDB migration from EC2 DB instance to RDS instance
Ref: https://learn.cantrill.io/courses/1820301/lectures/41301421
- For EC2 WordPress App instance to be able to connect to RDS instance, the SG for the RDS instance needs to be updated to include the SG of the EC2 instances:
- Migration of WP DB from EC2 to RDS follows a very similar set of commands as demo before:
- Create a backup/SQL dump → send it to the RDS instance via endpoint CNAME → update WP config file → stop the EC2 DB instance
- Upon deletion of an RDS instance, prompt to keep data (final snapshot & backups):