所以我创建了一个多主复制,其中两个用于主服务器,两个用于从服务器。
主机名:master-1 ip:192.168.120.107
主机名:master-2 ip:192.168.120.111
主机名:slave-1 ip:192.168.120.117
主机名:slave-2 ip:192.168.120.118
两个主服务器(master-1,master-2)被部署为主动 - 主动复制并且运行良好,下面是配置文件/etc/mysql/my.cnf
:
大师-1:
[mysqld]
#
# * Basic Settings
#
server-id = 1
user = root
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
log-bin = master-bin
log-bin-index = master-bin.index
relay-log = slave-relay-bin
relay-log-index = slave-relay-bin.index
skip-external-locking
大师-2:
[mysqld]
#
# * Basic Settings
#
server-id = 2
user = root
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
log-bin = master-bin
log-bin-index = master-bin.index
relay-log = relay-log-bin
relay-log-index = relay-log-bin.index
skip-external-locking
大师们工作得很好。两个从站像这样连接到主站: slave-1 是 master-1 的从站,slave-2 是 master-2 的从站。这些是配置文件:
从属 1:
[mysqld]
#
# * Basic Settings
#
server-id = 3
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
relay-log = slave-relay-bin
relay-log-index = slave-relay-bin.index
skip-external-locking
从属 2:
[mysqld]
#
# * Basic Settings
#
server-id = 4
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
relay-log = slave-relay-bin
relay-log-index = slave-relay-bin.index
skip-external-locking
当主服务器对数据库进行更改时,他的从服务器更改了两个,这意味着工作正常,例如当 master-1 更改数据库时,更改将被复制到 master-2 和 slave-1,并且也会在这些数据库中完成更改。我的问题是我需要在所有从机中发生更改,例如当 master-1 更改数据库时,slave-2 更改他的数据库,如 master-2 和 slave-1。我怎样才能做到这一点?
log-slave-updates
查看您的配置,您的 my.cnf 文件中似乎缺少您。您需要将其添加到两个主
my.cnf
文件中并重新启动它们。这告诉从属数据库从它的主数据库中获取它接收到的任何东西,并从中继日志复制到二进制日志,这样它就可以被复制了。
例如
Master 1 更新一个表。它被写入 Master1 上的二进制日志
这被复制到 Master 1 的 slaves(即 slave 1 和 Master2)
为了让它继续到 slave 2,必须告诉 master 2 将它添加到它的二进制日志中。这是做什么
log-slave-updates
的。