|
| 1 | +# Disaster Recovery Manual |
| 2 | + |
| 3 | +In an event/disaster where Master Database Server can't be accessed, down, or deleted we need to promote a Slave Server into a Master Server to minimize down time |
| 4 | + |
| 5 | +## Step 1 |
| 6 | +SSH into one of your Slave Server you want to promote into Master Server |
| 7 | +``` |
| 8 | +ssh ubuntu@slave-server-ip |
| 9 | +``` |
| 10 | + |
| 11 | +## Step 2 |
| 12 | +Login into MySQL |
| 13 | +``` |
| 14 | +sudo mysql -u root |
| 15 | +``` |
| 16 | + |
| 17 | +If you configure root with password, enter this instead |
| 18 | +``` |
| 19 | +sudo mysql -u root -p |
| 20 | +``` |
| 21 | + |
| 22 | +## Step 3 |
| 23 | +Stop and reset slave replication |
| 24 | +``` |
| 25 | +stop slave; |
| 26 | +reset slave; |
| 27 | +``` |
| 28 | + |
| 29 | +## Step 4 |
| 30 | +By default, slave server still can write. But if you configure read only on slave server, enable write on server by adding/editing this line on `/etc/mysql/my.cnf` |
| 31 | +``` |
| 32 | +[mysqld] |
| 33 | +read-only = 0 |
| 34 | +``` |
| 35 | + |
| 36 | +Or run this query on mysql |
| 37 | +``` |
| 38 | +SET read_only false; |
| 39 | +``` |
| 40 | + |
| 41 | +Your new master server is now ready |
| 42 | + |
| 43 | +## Step 5(and so on is optional) |
| 44 | +If you have other slave server, you can point them to your new master server |
| 45 | +In your new Master Server, run this |
| 46 | + |
| 47 | +``` |
| 48 | +SHOW MASTER STATUS; |
| 49 | +``` |
| 50 | + |
| 51 | +You will get something like this |
| 52 | +``` |
| 53 | ++------------------+----------+--------------+------------------+ |
| 54 | +| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | |
| 55 | ++------------------+----------+--------------+------------------+ |
| 56 | +| mysql-bin.000001 | 786 | | | |
| 57 | ++------------------+----------+--------------+------------------+ |
| 58 | +``` |
| 59 | +Note down the `File`, `Position`, and your server IP |
| 60 | + |
| 61 | +## Step 6 |
| 62 | + |
| 63 | +SSH into your other Slave Server |
| 64 | +``` |
| 65 | +ssh ubuntu@other-slave-server-ip |
| 66 | +``` |
| 67 | + |
| 68 | +## Step 7 |
| 69 | +Stop and reset slave replication |
| 70 | +``` |
| 71 | +stop slave; |
| 72 | +reset slave; |
| 73 | +``` |
| 74 | + |
| 75 | +## Step 8 |
| 76 | +Run this query, change the variable into what you note before |
| 77 | +``` |
| 78 | +CHANGE MASTER TO MASTER_HOST = '<your new master server ip>', MASTER_USER = '<replication user>', MASTER_PASSWORD = '<replication password>', MASTER_LOG_FILE = '<your master log file>', MASTER_LOG_POS = <your master log position>; |
| 79 | +``` |
| 80 | + |
| 81 | +Repeat step 6 - 8 for each of your slave server |
0 commit comments