Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[HOWTO] MySQL Multimaster Replication
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
wizard69
Apprentice
Apprentice


Joined: 22 Sep 2003
Posts: 178
Location: Berlin

PostPosted: Tue Apr 25, 2006 10:17 am    Post subject: [HOWTO] MySQL Multimaster Replication Reply with quote

In a regular replication setup one host is the replication master with one or more slaves. Which creates a single point of failure the master. One of the advantages of MySQL Cluster is that each node is a peer to the others, whereas in a normal replicating system you have a master and many slaves, and applications must be careful to write only to the master.


This guide only works with MyISAM table types (the default for MySQL).

This guide is aimed at users who have setup a master slave replication. If this is not the case please read the following howto.

How to Set Up Replication

or from the gentoo forum

[HOWTO] MySQL Replication

Using features introduced in MySQL 5.0 and 5.1, it is possible to build a replication system where all nodes act as master and slave at the same time, with a built-in fail-over mechanism. Please make sure you emerge mysql 5.x before you continue.

One hard-to-solve problem in a multimaster replication is the conflict that can happen with self-generated keys. The AUTO_INCREMENT feature is quite convenient, but in a replication environment it will be disruptive. If node A and node B both insert an auto-incrementing key on the same table, conflicts arise immediately. MySQL 5 introduces a couple of server variables for replicated auto-increment that address this specific problem and allow for the creation of an array of peer-to-peer nodes with MySQL replication.

Quoting from the manual:

* auto_increment_increment controls the increment between successive AUTO_INCREMENT values.
* auto_increment_offset determines the starting point for AUTO_INCREMENT column values.

By choosing non-conflicting values for these variables on different masters, servers in a multiple-master configuration will not use conflicting AUTO_INCREMENT values when inserting new rows into the same table. To set up N master servers, set the variables like this:

* Set auto_increment_increment to N on each master.
* Set each of the N masters to have a different auto_increment_offset, using the values 1, 2, ... , N.

Using those two variables as described in the manual, you can ensure that all nodes in your replication array will use different sequences of auto-incrementing numbers. For example, using auto_increment_increment = 10 and auto_increment_offset=3, the numbers generated when inserting three records will be 3, 13, 23. Using 10, 7, you'll get 7, 17, 27, and so on.
For my two-node array, I set auto_increment_increment to 10 for each node, and auto_increment_offset to 1 in the first node and 2 in the second.

Stop both mysql servers if you have a running master slave replication and edit the file

Code:
vi /etc/mysql/my.cnf


mine looks like this (only the [mysqld] section) host one.

Code:

# mysql.one.it
[mysqld]
server-id                       = 10
log-bin                         = mysql-bin
log-slave-updates
replicate-same-server-id        = 0
auto_increment_increment        = 10
auto_increment_offset           = 1
master-host                     = mysql.two.it
master-user                     = repl
master-password                 = password
report-host                     = mysql.one.it


host two

Code:

# mysql.two.it
[mysqld]
server-id                       = 20
log-bin                         = mysql-bin
log-slave-updates
replicate-same-server-id        = 0
auto_increment_increment        = 10
auto_increment_offset           = 2
master-host                     = mysql.one.it
master-user                     = repl
master-password                 = password
report-host                     = mysql.two.it


The server ID, must be different for each node the auto_increment_increment, the same for all the nodes. The auto_increment_offset, must also be different on each host to guarantee the uniqueness of self-generated keys.
A few variables are worth noting in these configuration files. The first is log-slave-updates. This option tells each server to write the changes that it receives from its master through the relay binary log to its own binary log. Without it, cascade replication doesn't work. The option replicate-same-server-id has the purpose of avoiding infinite replication loops, effectively telling each node to ignore from its master's binary log any statement that originated with its own server ID.
auto_increment_increment and auto_increment_offset have the appropriate values, as explained earlier. The rest is normal replication administration.


Reference:

MySQL Using Replication

Advanced MySQL Replication Techniques

Auto-Increment in Multiple-Master Replication

:lol: Enjoy
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum