《童虎学习笔记》7分钟搭建单主模式MySQL MGR集群-方案1

  • Post author:
  • Post category:mysql




本文章配套视频


https://www.ixigua.com/7082024332356289032
本专栏全部文章
https://blog.csdn.net/tonghu_note/category_11755726.html
总目录
https://blog.csdn.net/tonghu_note/article/details/124333034


来我的dou音

aa10246666

, 看配套视频


一、实战环境

Primary 节点 node1  mysql 8 10.211.55.9
Secondary1 节点 node2  mysql 8 10.211.55.4
Secondary2 节点 node3  mysql 8 10.211.55.6

/etc/hosts 中的配置

root@node1:/usr/local/mysql# cat /etc/hosts

10.211.55.9 node1

10.211.55.4 node2

10.211.55.6 node3


二、配置mysql

Primary 节点上mysql的配置文件  cat /usr/local/mysql/etc/my.cnf

[mysqld]

server_id=

1


#group_replication_local_address= ”

10.211.55.9

:3307″

#group_replication_group_seeds= “10.211.55.9:3307,10.211.55.4:3307,10.211.55.6:3307”

#group_replication_group_name=”aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa”

datadir=/usr/local/mysql/data/

basedir=/usr/local/mysql

gtid_mode=ON

enforce_gtid_consistency=ON

binlog_checksum=NONE

#transaction_write_set_extraction=XXHASH64

#group_replication_start_on_boot=off

#group_replication_bootstrap_group=off

Secondary1 节点上mysql的配置文件  cat /usr/local/mysql/etc/my.cnf

[mysqld]

server_id=

2


#group_replication_local_address= ”

10.211.55.4

:3307″

#group_replication_group_seeds= “10.211.55.9:3307,10.211.55.4:3307,10.211.55.6:3307”

#group_replication_group_name=”aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa”

datadir=/usr/local/mysql/data/

basedir=/usr/local/mysql

gtid_mode=ON

enforce_gtid_consistency=ON

binlog_checksum=NONE

#transaction_write_set_extraction=XXHASH64

#group_replication_start_on_boot=off

#group_replication_bootstrap_group=off

Secondary2 节点上mysql的配置文件  cat /usr/local/mysql/etc/my.cnf

[mysqld]

server_id=

3


#group_replication_local_address= ”

10.211.55.6

:3307″

#group_replication_group_seeds= “10.211.55.9:3307,10.211.55.4:3307,10.211.55.6:3307”

#group_replication_group_name=”aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa”

datadir=/usr/local/mysql/data/

basedir=/usr/local/mysql

gtid_mode=ON

enforce_gtid_consistency=ON

binlog_checksum=NONE

#transaction_write_set_extraction=XXHASH64

#group_replication_start_on_boot=off

#group_replication_bootstrap_group=off

在3个节点上初始化数据

mysqld –initialize-insecure –user=mysql

mysqld_safe –user=mysql &


三、修改初始密并启用mgr插件

在3个节点上都执行 mysql -uroot -p 不用输入密码

SET SQL_LOG_BIN=0;

alter user root@localhost identified with mysql_native_password by ‘root’;

SET SQL_LOG_BIN=1;

INSTALL PLUGIN group_replication SONAME ‘group_replication.so’;


四、修改my.cnf配置文件并重启mysqld

将注释的部分打开,如果是secondary节点,注意修改server_id和group_replication_local_address,并重启mysqld服务

以 Primary 节点为例

[mysqld]

server_id=

1



group_replication_local_address= “10.211.55.9:3307”

group_replication_group_seeds= “10.211.55.9:3307,10.211.55.4:3307,10.211.55.6:3307”

group_replication_group_name=”aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa”

datadir=/usr/local/mysql/data/

basedir=/usr/local/mysql

gtid_mode=ON

enforce_gtid_consistency=ON

binlog_checksum=NONE


transaction_write_set_extraction=XXHASH64

group_replication_start_on_boot=off

group_replication_bootstrap_group=off

并重启mysql服务

mysqladmin -uroot -proot shutdown

mysqld_safe –user=mysql &


五、创建复制用户

在3个节点上都执行

SET SQL_LOG_BIN=0;

CREATE USER rpl_user@’%’ IDENTIFIED with mysql_native_password BY ‘pwd1’;

GRANT REPLICATION SLAVE ON *.* TO rpl_user@’%’;

FLUSH PRIVILEGES;

SET SQL_LOG_BIN=1;

CHANGE MASTER TO MASTER_USER=’rpl_user’, MASTER_PASSWORD=’pwd1′ FOR CHANNEL ‘group_replication_recovery’;


六、启用Primary节点, 即引导节点

SET GLOBAL group_replication_bootstrap_group=ON;

START GROUP_REPLICATION;

SET GLOBAL group_replication_bootstrap_group=OFF;

查看集群状态

SELECT * FROM performance_schema.replication_group_members;


七、启用

secondary

节点

START GROUP_REPLICATION;

查看集群状态

SELECT * FROM performance_schema.replication_group_members;


八、测试

在 Primary 节点,创建一个新的数据库,看 2台 Secondary 是否会同步此创建数据库的操作



版权声明:本文为tonghu_note原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。