MYSQL Group Replication的搭建过程

29次阅读
没有评论

共计 5486 个字符,预计需要花费 14 分钟才能阅读完成。

这篇文章主要介绍“MYSQL Group Replication 的搭建过程”,在日常操作中,相信很多人在 MYSQL Group Replication 的搭建过程问题上存在疑惑,丸趣 TV 小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”MYSQL Group Replication 的搭建过程”的疑惑有所帮助!接下来,请跟着丸趣 TV 小编一起来学习吧!

1.
环境准备
操作系统 redhat linux 6.8
虚拟机 3 台
一台用于 primary, 另外两台用于做 secondary
注意:
请先设置好各个主机的 hostname 与 /etc/hosts
mysql 版本: mysql-5.7.20
主名 ip 地址 在 mgr 中的角色

mgrhost01  192.168.43.143 primary

mgrhost02 192.168.43.144 seconde

mgrhost03 192.168.43.145 seconde

2.
安装 mysql 数据服务
 cd /tmp/
 wget
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

 tar -xvf
mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
 cd /usr/local/
 ln -s
mysql-5.7.20-linux-glibc2.12-x86_64 mysql

注意:三个环境都需要安装

在三台主机上执行以下命令:
mkdir -p /database/mysql/data/3306
useradd mysql
chown -R mysql:mysql /database/mysql/data/3306
chown -R mysql:mysql /usr/local/mysql*

3. 配置 mysql 服务
三台主机都增加配置文件: /etc/my.cnf

其中 143 的配置文件内容:
basedir=/usr/local/mysql/

datadir=/database/mysql/data/3306

port=3306

socket=/tmp/mysql.sock

server_id=143

gtid_mode=on

enforce_gtid_consistency=on

master_info_repository=table

relay_log_info_repository=table

binlog_checksum=none

log_slave_updates=on

log_bin=mysql-bin

binlog_format=row

relay-log-recovery=1

transaction_write_set_extraction=XXHASH64

loose-group_replication_group_name= aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa

loose-group_replication_start_on_boot=off

loose-group_replication_local_address=
192.168.43.143:33060

loose-group_replication_group_seeds=
192.168.43.143:33060,192.168.43.144:33060,192.168.43.145:33060

loose-group_replication_bootstrap_group=
off

192.168.43.144 的 /etc/my.cnf

[mysqld]

basedir=/usr/local/mysql/

datadir=/database/mysql/data/3306

port=3306

socket=/tmp/mysql.sock

server_id=144

gtid_mode=on

enforce_gtid_consistency=on

master_info_repository=table

relay_log_info_repository=table

binlog_checksum=none

log_slave_updates=on

log_bin=mysql-bin

binlog_format=row

relay-log-recovery=1

transaction_write_set_extraction=XXHASH64

loose-group_replication_group_name= aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa

loose-group_replication_start_on_boot=off

loose-group_replication_local_address=
192.168.43.144:33060

loose-group_replication_group_seeds=
192.168.43.143:33060,192.168.43.144:33060,192.168.43.145:3306

loose-group_replication_bootstrap_group=
off

192.168.43.145 的 /etc/my.cnf
[mysqld]

basedir=/usr/local/mysql/

datadir=/database/mysql/data/3306

port=3306

socket=/tmp/mysql.sock

server_id=145

gtid_mode=on

enforce_gtid_consistency=on

master_info_repository=table

relay_log_info_repository=table

binlog_checksum=none

log_slave_updates=on

log_bin=mysql-bin

binlog_format=row

relay-log-recovery=1

transaction_write_set_extraction=XXHASH64

loose-group_replication_group_name= aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa

loose-group_replication_start_on_boot=off

loose-group_replication_local_address=
192.168.43.145:33060

loose-group_replication_group_seeds=
192.168.43.143:33060,192.168.43.144:33060,192.168.43.145:3306

loose-group_replication_bootstrap_group=
在这里有一些技术细节要说明一下:

上面的三个配置文件省略了所有不必要的配置项、但是看起来还是有点多、这些都是 mgr 环境要求的。

server_id 每个实例都要不要样

loose-group_replication_group_name:为 mgr 高可用组起一个名字,这个名字一定要是 uuid 格式的。

loose-group_replication_local_address:mgr 各实例之前都是要进行通信的、这个配置项设置的就是本实例所监听的 ip:端口

loose-group_replication_group_seeds:各 mgr 实例所监听的 ip: 端口信息
三个环境初始化 mysql(注意,此处 mysql 的 root 用户密码会被设置为空值):

/usr/local/mysql/bin/mysqld –defaults-file=/etc/my.cnf
–datadir=/database/mysql/data/3306/ –user=mysql –initialize-insecure

三个环境将 mysql 加入系统服务
cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld

chkconfig mysqld on

修改环境变量:
echo PATH=/usr/local/mysql/bin/:$PATH /etc/profile

启动 mysql 服务:
service mysqld start

停止 mysql 服务:
service mysqld stop

4. 配置 MGR

  4.1 创建 mgr 所需的用户(第一个节点)
  set
sql_log_bin=0;

  create
user mgruser@ % identified by mtls@352

  grant
replication slave,replication client on *.* to mgruser@ %

  create
user mgruser@ 127.0.0.1 identified by mtls@352

  grant
replication slave,replication client on *.* to mgruser@ 127.0.0.1

  create
user mgruser@ localhost identified by mtls@352

  grant
replication slave,replication client on *.* to mgruser@ localhost

set
sql_log_bin=1;

 4.2 配置复制所使用的用户
  change master to

  master_user= mgruser ,

  master_password= 123456

  for channel group_replication_recovery
 

4.3  安装 MGR 插件  install plugin group_replication soname  group_replication.so

4.4.  初始化一个复制组
   set global
group_replication_bootstrap_group=on;

start
group_replication;

set
global group_replication_bootstrap_group=off;
 

4.5. 配置 MGR 的第二个节点
set sql_log_bin=0;

  create user mgruser@ % identified by
123456

  grant replication slave,replication client
on *.* to mgruser@ %

  create user mgruser@ 127.0.0.1 identified
by 123456

  grant replication slave,replication client
on *.* to mgruser@ 127.0.0.1

  create user mgruser@ localhost identified
by 123456

  grant replication slave,replication client
on *.* to mgruser@ localhost

set
sql_log_bin=1;

 change master
to

  master_user= mgruser ,

  master_password= 123456

  for channel group_replication_recovery

install plugin group_replication soname  group_replication.so  start group_replication;

使用以上脚本依次处理剩余节点。

验证:

至此,配置完成

mgr 中所有的结点都属于一个逻辑上的组、这个组就像是 QQ 群一样、是由群主建起来的、有了这个上组之后、其它的结点就可以加入到这个组中来了。

搭建中的注意项:

1. 
安装虚拟机操作系统时,因 hostname 安装时未能设置好,修改了 hostname, 重启了操作系统之后,group_replication 不能正常启动
mysql start group_replication;

set global group_replication_bootstrap_group=off;

ERROR 3094
(HY000): The START GROUP_REPLICATION command failed as the applier module
failed to start.
 

在参数文件 /etc/my.cnf 中加入了 relay-log-recovery= 1 之后,才正常启动复制

2. 安装 mysql 服务前,最好先设置好 hostname 与 /etc/hosts

本案例中 /etc/hosts 的内容为:

192.168.43.143
mgrhost01

192.168.43.144
mgrhost02

192.168.43.145 mgrhost03

3. select * from performance_schema.replication_group_members ;  这个 SQL 查询的列的 member_state 字段应都为 state 才是正常的

到此,关于“MYSQL Group Replication 的搭建过程”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注丸趣 TV 网站,丸趣 TV 小编会继续努力为大家带来更多实用的文章!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-28发表,共计5486字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)