Cross Data Center MySQL Replication Behind NodeBalancer

Linode Staff

I am following this guide. In each data center I have two database servers behind a NodeBalancer. I am trying to replicate the database servers across data centers.

Here's what I'm calling things:

Name Description Public IP Private IP
DC1 Data Center 1
DC2 Data Center 2
DB1-DC1 Database 1 in Data Center 1
DB2-DC1 Database 2 in Data Center 1
NB-DC1 NodeBalancer in Data Center 1
DB1-DC2 Database 1 in Data Center 2
DB2-DC2 Database 2 in Data Center 2
NB-DC2 NodeBalancer in Data Center 2

I am attempting to perform replication to my database servers behind the NodeBalancers ( and

On my databases in data center 1, I have configured grants like this:

GRANT REPLICATION SLAVE ON *.* TO 'replication'@'' IDENTIFIED BY 'password';

Likewise, in data center 2, I have configured things in the opposite direction.

The replication is not working.

I've looked for my log files and can't find them.

1 Reply

Note: The terms primary and replica are the preferred naming convention for replication, replacing the archaic master and slave terminology.

There are a few gotchas exhibited in this configuration.

NodeBalancer's Role

A NodeBalancer can be helpful with distributing the load between interchangeable endpoints, but for replication, you need to specify the exact endpoint you want to replicate with. So instead of replicating with you will want to replicate with the public IP address of one of your database servers (i.e. at if you are replicating between data centers OR via the private IP ( if replicating in the same data center.

At Linode, private IP addresses are unique within a data center, but servers in different data centers could conceivably have the same private IP address. (i.e. nb-dc1 and db1-dc2, both have a private IP address of in the example.)

MySQL Grants and Hostnames

Granting privileges to 'replication'@'' and 'replication'@'' are two completely different animals. If you use a fully qualified domain name in your grant, the address from which you are querying must match both forward and reverse DNS. This means that must point to and must point to
For more information on setting up rDNS for a Linode, you will want to refer to:

Replica Topology

Depending on your needs you may want designate one database as primary in both data centers and configure primary-primary replication between them over their public IPs (i.e. between db1-dc1 and db1-dc2).

Primary-replica replication could take place within a data center (i.e. db1-dc1 to db2-dc2) over the database's private IPs. In this case, the application should direct write queries to the local primary, but reads can be load balanced between any available database in the data center. There are many other topologies to consider. You can refer to the following documentation for a discussion of the trade offs:

Log Files

You will want to look at /etc/mysql/my.cnf and under /etc/mysql/mariadb.conf.d/ or /etc/mysql/mysql.conf.d/ to see where data is being stored for your MariaDB or MySQL instance. The parameter that controls this is 'datadir'. Usually this will be /var/lib/mysql. A quick command to check is:

sudo grep -R 'datadir' /etc/mysql

Usually the log files are stored in the datadir, but could be configured to elsewhere. Refer to the following guide if they aren't in the usual place:


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct