ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Mariadb10.7 Master Replication

2022-01-09 09:34:15  阅读:173  来源: 互联网

标签:opt Slave LOG Replication Running Master mysql MASTER Mariadb10.7


Setup master #1

master1.cnf
[mariadb]
log-bin
server_id=1
log-basename=master1
binlog-format=mixed
docker run -d --name=db1 -h db1 -p 13306:3306 -e MYSQL_ROOT_PASSWORD=root1 -e MYSQL_ROOT_HOST='%' -v /opt/conf1:/etc/mysql/conf.d -v /opt/data1:/var/lib/mysql mariadb:10.7.1 

Create user for replicator

mysql -h 127.0.0.1 -P 13306 -uroot -proot1

CREATE USER 'copy2'@'%' IDENTIFIED BY '123456';
GRANT REPLICATION SLAVE ON *.* TO 'copy2'@'%';

Getting the Master’s Binary Log Co-ordinates

MariaDB [(none)]> SHOW MASTER STATUS;
+--------------------+----------+--------------+------------------+
| File               | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| master1-bin.000001 |      639 |              |                  |
+--------------------+----------+--------------+------------------+

Setup Replicator #2

slave2.cnf
[mariadb]
server-id=2
read_only=1
docker run -d --name=db2 -h db2 -p 23306:3306 -e MYSQL_ROOT_PASSWORD=root2 -e MYSQL_ROOT_HOST='%' -v /opt/conf2:/etc/mysql/conf.d -v /opt/data2:/var/lib/mysql mariadb:10.7.1

Start replicator #2

mysql -h 127.0.0.1 -P 23306 -uroot -proot2

CHANGE MASTER TO
  MASTER_HOST='192.168.0.149',
  MASTER_USER='copy2',
  MASTER_PASSWORD='123456',
  MASTER_PORT=13306,
  MASTER_LOG_FILE='master1-bin.000001',
  MASTER_LOG_POS=639,
  MASTER_CONNECT_RETRY=10,
  MASTER_USE_GTID=slave_pos;

If you are starting a slave against a fresh master that was configured for replication from the start, then you don’t have to specify MASTER_LOG_FILE and MASTER_LOG_POS.

START SLAVE;
SHOW SLAVE STATUS \G;
show variables like '%read_only%';

If replication is working correctly, both the values of Slave_IO_Running and Slave_SQL_Running should be Yes:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

Setup Replicator #3

slave3.cnf
[mariadb]
server-id=3
read_only=1
docker run -d --name=db3 -h db3 -p 33306:3306 -e MYSQL_ROOT_PASSWORD=root3 -e MYSQL_ROOT_HOST='%' -v /opt/conf3:/etc/mysql/conf.d -v /opt/data3:/var/lib/mysql mariadb:10.7.1

Start Replicator #3

mysql -h 127.0.0.1 -P 33306 -uroot -proot3

CHANGE MASTER TO
  MASTER_HOST='192.168.0.149',
  MASTER_USER='copy2',
  MASTER_PASSWORD='123456',
  MASTER_PORT=13306,
  MASTER_LOG_FILE='master1-bin.000001',
  MASTER_LOG_POS=1240,
  MASTER_CONNECT_RETRY=10,
  MASTER_USE_GTID=slave_pos;

If you are starting a slave against a fresh master that was configured for replication from the start, then you don’t have to specify MASTER_LOG_FILE and MASTER_LOG_POS.

START SLAVE;
SHOW SLAVE STATUS \G;
show variables like '%read_only%';

If replication is working correctly, both the values of Slave_IO_Running and Slave_SQL_Running should be Yes:

Slave_IO_Running: Yes
Slave_SQL_Running: Yes

标签:opt,Slave,LOG,Replication,Running,Master,mysql,MASTER,Mariadb10.7
来源: https://blog.csdn.net/weixin_38937732/article/details/122389832

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有