GreatSQL社区

搜索

[待回复] 配置双节点普通复制关系主主同步遇到问题

283 1 2024-9-18 14:20
配置双节点普通复制关系主主同步时,show slave status \G命令两节点连接状态是"yes"。配置的同步库名叫"testzz",从A节点往同步库里插入的数据B节点看不到。操作步骤如下:


#创建itcast用户,并设置密码,该用户可在任意主机连接该MySQL服务
CREATE USER 'masterzz_A'@'%' IDENTIFIED WITH mysql_native_password BY '1234';
CREATE USER 'masterzz_B'@'%' IDENTIFIED WITH mysql_native_password BY '1234';
#为 'itcast'@'%' 用户分配主从复制权限
GRANT REPLICATION SLAVE ON *.* TO 'masterzz_A'@'%';
GRANT REPLICATION SLAVE ON *.* TO 'masterzz_B'@'%';



两台都执行创建数据库
create database testzz  character  set utf8;
需确认两台ip互通,查看uuid不同
SHOW VARIABLES LIKE "server_uuid";

修改my.cnf,server-id改为不同的值
#新加
log-bin = /data/GreatSQL/
sync-binlog = 1
binlog_format = mixed
binlog-do-db = testzz,androidpnserver
binlog-ignore-db = mysql,information_schema,performance_schema
auto-increment-increment = 10
auto-increment-offset = 1
replicate-do-db = testzz,androidpnserver
replicate-ignore-db = mysql,information_schema,performance_schema
log-slave-updates = ON

两台重启服务
systemctl restart greatsql.service

两边先锁表,防止新的数据写入。同时查看master状态。记住 File 和 Position 下面会用到
flush tables with read lock;
show master status;

masterA执行
change master to master_host='master-B的IP',
master_user='master-B创建的账户名',
master_password='对应账户密码',
master_log_file='master-B的File',   
master_log_pos=master-B的Position;
   
change master to master_host='192.168.194.161',
master_user='masterzz_A',
master_password='1234',
master_log_file='binlog.000006',
master_log_pos=714;

change master to master_host='192.168.194.162',
master_user='masterzz_B',
master_password='1234',
master_log_file='binlog.000004',
master_log_pos=754;

masterB执行
change master to master_host='192.168.194.162',
master_user='master-A创建的账户名',
master_password='对应账户密码',
master_log_file='master-A的File',   
master_log_pos=master-A的Position;  

主主.zip

4.98 KB, 下载次数: 0, 下载积分: 金币 -1

my.cnf

全部回复(1)
KAiTO 2024-9-18 14:56:07
log-bin参数,开启 Binlog 与否的总开关。该参数的值只要不是设置为 OFF,就表示启用 Binlog。如果设置为 log_bin = 1 或 log_bin = ON,仅表示打开 Binlog 不设置 Binlog 文件基本名;如果设置为字符串,则表示除了打开 Binlog 外,还同时设定 Binlog 的基本文件名,支持设定为全路径或仅文件名,如 log_bin = binlog 或 log_bin = /data/GreatSQL/binlog[1]

用户设置为/data/GreatSQL/ 导致binlog没生成,复制失败

[1]Binary Log(二进制日志) | GreatSQL用户手册
有点脂肪肝儿

3

主题

0

博客

9

贡献

新手上路

Rank: 1

积分
15

合作电话:010-64087828

社区邮箱:greatsql@greatdb.com

社区公众号
社区小助手
QQ群
GMT+8, 2024-10-18 17:20 , Processed in 0.017709 second(s), 12 queries , Redis On.
快速回复 返回顶部 返回列表