网站制作学习网Database→正文:MySQL Group Replication 配置mysql 主从同步, mysql 一主多从
字体:

MySQL Group Replication 配置mysql 主从同步, mysql 一主多从

Database 2024/10/16 20:57:31  点击:不统计

原载于:原文章%77w%77%2Ef%6F%72%61%73%70%2E%63n

 现在做mysql 主从备份 使用 MySQL Group Replication  2台从库,配置如下
 
第一步:配置主服务器mysql A,下面所有配置先搜索一下本地是否配置了,在修改。
1. 编辑配置
   [mysqld]
log_bin=ON
binlog_format=ROW
server-id=200
innodb-flush-log-at-trx-commit=1
sync-binlog=1
skip-networking=OFF
plugin-load-add=mysql_clone.so
max_allowed_packet=128M # 调整
   
2.重启主服务器mysql检查配置
   show variables like 'log_bin';
show variables like 'binlog_format';
show variables like 'server_id';
show variables like 'innodb_flush_log_at_trx_commit';
show variables like 'sync_binlog';
show variables like 'skip_networking';
   
3. 检查插件是否完整
   select plugin_name,plugin_status from INFORMATION_SCHEMA.PLUGINS where PLUGIN_NAME='clone';   
第二部:配置子服务器mysql B
1. 编辑配置 
   [mysqld]
skip-log-bin=ON
server-id=201
plugin-load-add=mysql_clone.so
max_allowed_packet=128M #调整
   
2. 重启mysql 再次检查mysql 配置
   show variables like 'log_bin';
show variables like 'server_id';
show variables like '%relay%';
   
3. 检查插件是否完整
   select plugin_name,plugin_status from INFORMATION_SCHEMA.PLUGINS where PLUGIN_NAME='clone';   
配置子服务器mysql C 参考B 唯一不同的是server-id=202 
 
第三步 创建同步mysql账号信息
1.主服务器A mysql 创建 用于复制的账号, 下面的密码和IP 自行修改
   create user repl@'192.168.0.0/255.255.0.0' identified by 'mAster$c' REQUIRE SSL; # 创建用户
grant replication slave on *.* to 'repl'@'192.168.0.0/255.255.0.0';
grant BACKUP_ADMIN on *.* to 'repl'@'192.168.0.0/255.255.0.0';
flush privileges;
show create user 'repl'@'192.168.0.0/255.255.0.0';
show grants for 'repl'@'192.168.0.0/255.255.0.0';
   
2.检查repl 用户登录情况, 在从服务器 B C 上使用测试是否可以登录
这里的master-01 是在服务器(主从) /etc/hosts 中配置了dns 解析到主服务器IP,可以用IP ,建议用 名称(下面同步则一样的)
   mysql -h master-01 --ssl-mode=required -u repl -p 输入上面的密码 如果不同端口则 -P[端口]
select current_user(); # 查看当前用户。 结果为:
repl@192.168.0.0/255.255.0.0
检查 支持ssl
show session status like 'Ssl_cipher';
   
第四步 开始配置从服务器A,B同步数据,每台逐步操作
1. 给当前mysql 添加clone_admin 权限 每个都建立, 
   # 可以SHOW GRANTS FOR 'root'@'localhost'; 看下是否已经存在了,我测试是存在的。下面就不用执行了
grant CLONE_ADMIN on *.* to 'root'@'locahost';
flush privileges;
   
2.从服务器上执行clone 操作
   set global clone_valid_donor_list='master-01:3306'; # 这里可以更改端口
clone instance from 'repl'@'master-01':3306 identified by 'mAster$c' REQUIRE SSL; # 这里使用对应的主服务器mysql 的账号密码
   
3.从每台从服务器myql检查克隆情况
   select state from performance_schema.clone_status;
# 如果完毕会出现 (中间mysql 克隆完毕会重启),重启后,因为同步了mysql库,需要 主mysql 账号登录查看
Completed
# 查看可克隆后的mysql 有哪些库
show databases;
   
4. 上面是从 主服务器克隆现有的数据到从服务器,下面开始准备同步,从服务器mysql 查询已经克隆到本地的二进制信息
   select binlog_file,Binlog_position from performance_schema.clone_status;
   
5.设置每台从服务器 设置Replication。参数上面获取到的
   change master to master_host='master-01',MASTER_PORT=3306, master_ssl=1,master_user='repl', master_password='',master_log_file='上面结果',master_log_pos=上面结果;   
6. 克隆后 开始复制
   start replica; # 开始复制--正常执行同步
show replica status \G; # 查看同步状态
   
7. 启动或者停止同步
start replica; 
stop replica; 
 
第五步 登录 主mysql 服务器,通过下面命令查看 状态

show REPLICAS; # 可以看到,目前已经注册的2个克隆的服务器。
mysql> show REPLICAS;
+-----------+------+------+-----------+--------------------------------------+
| Server_Id | Host | Port | Source_Id | Replica_UUID |
+-----------+------+------+-----------+--------------------------------------+
| 201 | | 3306 | 200| 7ffaeb1c-8bab-11ef-b37b-22405c040fbc |
| 202 | | 3306 | 200| 7ffaeb1c-8bab-11ef-b37b-23xbc24dcf2c |
+-----------+------+------+-----------+--------------------------------------+
   
以上就是MySQL Group Replication 配置mysql 主从同步, mysql 一主多从
 

学习www.网for站asp制.cn作

·上一篇:Got a packet bigger than 'max_allowed_packet' bytes >>    ·下一篇:mysql同步更改从库relay_log位置 >>
推荐文章
最新文章