Introducing Additional Slaves to an Existing Replication Environment
To add another slave to an existing replication configuration, you can do so without stopping the master. Instead, set up the new slave by making a copy of an existing slave, except that you configure the new slave with a different server-id
value.
To duplicate an existing slave:
- Shut down the existing slave:
shell>
mysqladmin shutdown
- Copy the data directory from the existing slave to the new slave. You can do this by creating an archive using tar or
WinZip
, or by performing a direct copy using a tool such as cp or rsync. Ensure that you also copy the log files and relay log files.A common problem that is encountered when adding new replication slaves is that the new slave fails with a series of warning and error messages like these:
071118 16:44:10 [Warning] Neither --relay-log nor --relay-log-index were used; so replication may break when this MariaDB server acts as a slave and has his hostname changed!! Please use '--relay-log=
new_slave_hostname
-relay-bin' to avoid this problem. 16:44:10 [ERROR] Failed to open the relay log './old_slave_hostname
-relay-bin.003525' (relay_log_pos 22940879) 071118 16:44:10 [ERROR] Could not find target log during relay log initialization 071118 16:44:10 [ERROR] Failed to initialize the master info structureThis is due to the fact that, if the
--relay-log
option is not specified, the relay log files contain the host name as part of their file names. (This is also true of the relay log index file if the--relay-log-index
option is not used. See , "Replication and Binary Logging Options and Variables", for more information about these options.)To avoid this problem, use the same value for
--relay-log
on the new slave that was used on the existing slave. (If this option was not set explicitly on the existing slave, use
.) If this is not feasible, copy the existing slave's relay log index file to the new slave and set theexisting_slave_hostname
-relay-bin--relay-log-index
option on the new slave to match what was used on the existing slave. (If this option was not set explicitly on the existing slave, use
.) Alternatively-if you have already tried to start the new slave (after following the remaining steps in this section) and have encountered errors like those described previously-then perform the following steps:existing_slave_hostname
-relay-bin.index- If you have not already done so, issue a
STOP SLAVE
on the new slave.If you have already started the existing slave again, issue a
STOP SLAVE
on the existing slave as well. - Copy the contents of the existing slave's relay log index file into the new slave's relay log index file, making sure to overwrite any content already in the file.
- Proceed with the remaining steps in this section.
- If you have not already done so, issue a
- Copy the
master.info
andrelay-log.info
files from the existing slave to the new slave if they were not located in the data directory. These files hold the current log coordinates for the master's binary log and the slave's relay log. - Start the existing slave.
- On the new slave, edit the configuration and give the new slave a unique
server-id
not used by the master or any of the existing slaves. - Start the new slave. The slave will use the information in its
master.info
file to start the replication process.