mysql8.0.31 mgr搭建

1.  mysql下载地址:MySQL :: Download MySQL Community Server

2.  mgr文档:MySQL :: MySQL 8.0 Reference Manual :: 18 Group Replication

3. 安装实例:

  a)  解压 tar -xvf mysql-8.0.31-linux-glibc2.17-x86_64-minimal.tar.xz

  b)   添加用户

groupadd mysql
useradd -r -g mysql mysql
chown mysql:mysql -R /usr/local/mysql

 

  c)  初始化: ./bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --user=mysql --initialize

    需要记住初始密码,第一次登录需要

  d)  配置软连接: 

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/bin/mysql /usr/bin

 

  e) 更改root密码(授权远程登录)

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456'
flush privileges;

  f) mysql打开失败时可能是目录没有权限 chown mysql:mysql -R /usr/local/mysql/data

    或者log文件没有创建,需要手动创建

    初始化密码登录失败,需要注意转义字符,登录命令添加 -h127.0.0.1

4.  mgr配置:

  a)  my.cnf,注意 server-id 是组内唯一的,group_replication_local_address 为本机地址,group_replication_group_name 是组内相同的

[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/data/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
#user=root

#开启GTID,必须开启
gtid_mode=ON
#强制GTID的一致性
enforce_gtid_consistency=ON
 
log_bin=binlog
#log_slave_updates=ON
#binlog格式,MGR要求必须是ROW,不过就算不是MGR,也最好用row
binlog_format=row
#server-id必须是唯一的
server-id = 2
#MGR使用乐观锁,所以官网建议隔离级别是RC,减少锁粒度
transaction_isolation = READ-COMMITTED
#因为集群会在故障恢复时互相检查binlog的数据,
#所以需要记录下集群内其他服务器发过来已经执行过的binlog,按GTID来区分是否执行过.
log-slave-updates=1
#binlog校验规则,5.6之后的高版本是CRC32,低版本都是NONE,但是MGR要求使用NONE
binlog_checksum=NONE
#基于安全的考虑,MGR集群要求复制模式要改成slave记录记录到表中,不然就报错
master_info_repository=TABLE
#同上配套
relay_log_info_repository=TABLE

report_host = '192.168.229.188'
 
#组复制设置
#记录事务的算法,官网建议设置该参数使用 XXHASH64 算法
transaction_write_set_extraction = XXHASH64
#plugin_load_add='group_replication.so'
#相当于此GROUP的名字,是UUID值,不能和集群内其他GTID值的UUID混用,可用uuidgen来生成一个新的,
#主要是用来区分整个内网里边的各个不同的GROUP,而且也是这个group内的GTID值的UUID
group_replication_group_name = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
#IP地址白名单,默认只添加127.0.0.1,不会允许来自外部主机的连接,按需安全设置
group_replication_ip_whitelist = '127.0.0.1/8,192.168.0.0/16,192.168.229.189,192.168.229.190'
#是否随服务器启动而自动启动组复制,不建议直接启动,怕故障恢复时有扰乱数据准确性的特殊情况
group_replication_start_on_boot = OFF
#本地MGR的IP地址和端口,host:port,是MGR的端口,不是数据库的端口
group_replication_local_address = '192.168.229.188:33081'
#需要接受本MGR实例控制的服务器IP地址和端口,是MGR的端口,不是数据库的端口
group_replication_group_seeds = '192.168.229.188:33081,192.168.229.189:33081,192.168.229.190:33081'
#开启引导模式,添加组成员,用于第一次搭建MGR或重建MGR的时候使用,只需要在集群内的其中一台开启,
group_replication_bootstrap_group = OFF
#是否启动单主模式,如果启动,则本实例是主库,提供读写,其他实例仅提供读,如果为off就是多主模式了
#group_replication_single_primary_mode = ON
#多主模式下,强制检查每一个实例是否允许该操作,如果不是多主,可以关闭
#loose-group_replication_enforce_update_everywhere_checks = OFF



[mysqld_safe]
log-error=/usr/local/mysql/log/mariadb.log
pid-file=/usr/local/mysql/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

  b)  进入mysql配置组复制链接登录凭证(所有实例都需要配置)

SET SQL_LOG_BIN=0;
CREATE USER rpl_user@'%' IDENTIFIED BY 'password';
GRANT REPLICATION SLAVE ON *.* TO rpl_user@'%';
GRANT CONNECTION_ADMIN ON *.* TO rpl_user@'%';
GRANT BACKUP_ADMIN ON *.* TO rpl_user@'%';
GRANT GROUP_REPLICATION_STREAM ON *.* TO rpl_user@'%';
FLUSH PRIVILEGES;
SET SQL_LOG_BIN=1;
CHANGE MASTER TO MASTER_USER='rpl_user', MASTER_PASSWORD='password' FOR CHANNEL 'group_replication_recovery';

  c)  安装插件

INSTALL PLUGIN group_replication SONAME 'group_replication.so';

  d)  引导启动 主节点

SET GLOBAL group_replication_bootstrap_group=ON;
START GROUP_REPLICATION;
SET GLOBAL group_replication_bootstrap_group=OFF;
SELECT * FROM performance_schema.replication_group_members; ## 查询组成员

 e)  添加 从节点

START GROUP_REPLICATION;

  f)  添加节点出现异常: This member has more executed transactions than those present in the group 可以尝试 reset master; reset slave;

      或者:在欲加入的节点执行 reset master; 然后在组内任一节点查询 show master status\G ,取值Executed_Gtid_Set,

          然后再加入节点执行 SET GLOBAL GTID_PURGED = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa:1-197687:1000003-1000379'; ###Executed_Gtid_Set值

   节点无法连接时,可能是防火墙限制

     添加节点时异常:  Authentication requires secure connection. Error_code: MY-002061,另实例重启后再次加入组时也需要重新执行    

CHANGE MASTER TO MASTER_USER='rpl', MASTER_PASSWORD='rpl123' FOR CHANNEL 'group_replication_recovery';

 

posted @ 2022-11-17 10:26  不知为何就叫呵呵  阅读(268)  评论(0编辑  收藏  举报