原文链接:MySQL:8.0搭建mgr集群(clone方式)
一. 前言
本次搭建三节点mgr集群,具体信息如下:
OS版本 Red Hat 7.5
DB版本 8.0.31
DB软件目录 /mysql/app/mysql/
DB数据目录 /mysql/data/
节点一 mgr1 192.168.40.51
节点二 mgr2 192.168.40.52
节点三 mgr3 192.168.40.53
数据库软件为二进制安装方式,安装过程略。
二. 安装节点一
2.1 初始化数据库
1.初始化数据库
[root@mgr1 ~]# /mysql/app/mysql/bin/mysqld --initialize --user=mysql --basedir=/mysql/app/mysql --datadir=/mysql/data
2023-03-13T02:13:34.238199Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2023-03-13T02:13:34.238280Z 0 [System] [MY-013169] [Server] /mysql/app/mysql/bin/mysqld (mysqld 8.0.31) initializing of server in progress as process 1749
2023-03-13T02:13:34.244001Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-03-13T02:13:35.252915Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-03-13T02:13:36.452071Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: WkooMt<z<8*t
--------------这是一条分割线--------------------------------------------------
2.mysql cnf配置文件内容如下:
[root@mgr1 ~]# cat /mysql/mgr1.cnf
[mysqld]
user=mysql
server_id=6
port=3306
basedir=/mysql/app/mysql
datadir=/mysql/data
socket=/tmp/mgr1.sock
log-error=/mysql/data/error.log
log_bin=binlog-bin
log_slave_updates=ON
binlog_format=ROW
binlog_checksum=NONE
master_info_repository=TABLE
relay_log_info_repository=TABLE
gtid_mode=ON
enforce_gtid_consistency=true
disabled_storage_engines="MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"
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.40.51:33061"
loose-group_replication_group_seeds="192.168.40.51:33061,192.168.40.52:33061,192.168.40.53:33061"
loose-group_replication_bootstrap_group=OFF
report_host=192.168.40.51
report_port=3306
loose-group_replication_recovery_get_public_key=ON
[mysql]
socket=/tmp/mgr1.sock
--------------这是一条分割线--------------------------------------------------
3.配置mysql systemd启动方式
说明:由于后面clone数据库后会自动重启,这里使用mysqld_safe,而不是mysqld
[root@mgr1 ~]# cat >/etc/systemd/system/mysqld_mgr1.service <<EOF
> [Unit]
> Description=MySQL Server
> Documentation=man:mysqld(8)
> Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
> After=network.target
> After=syslog.target
> [Install]
> WantedBy=multi-user.target
> [Service]
> User=mysql
> Group=mysql
> ExecStart=/mysql/app/mysql/bin/mysqld_safe --defaults-file=/mysql/mgr1.cnf
> LimitNOFILE = 5000
> EOF
--------------这是一条分割线--------------------------------------------------
4.启动数据库,修改root密码
[root@mgr1 ~]# systemctl start mysqld_mgr1.service
[root@mgr1 ~]# ps -ef|grep mysql |grep -v grep
mysql 1809 1 0 10:23 ? 00:00:00 /bin/sh /mysql/app/mysql/bin/mysqld_safe --defaults-file=/mysql/mgr1.cnf
mysql 2181 1809 8 10:23 ? 00:00:01 /mysql/app/mysql/bin/mysqld --defaults-file=/mysql/mgr1.cnf --basedir=/mysql/app/mysql --datadir=/mysql/data --plugin-dir=/mysql/app/mysql/lib/plugin --log-error=/mysql/data/error.log --pid-file=mgr1.pid --socket=/tmp/mgr1.sock --port=3306
[root@mgr1 ~]# mysql -uroot -p -S/tmp/mgr1.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.31
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user root@'localhost' identified by '12345678';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
2.2 安装组复制插件
1.安装组复制插件
mysql> INSTALL PLUGIN group_replication SONAME 'group_replication.so';
Query OK, 0 rows affected (0.00 sec)
2.查看插件是否安装成功
mysql> show plugins;
+----------------------------------+----------+--------------------+----------------------+---------+
| Name | Status | Type | Library | License |
+----------------------------------+----------+--------------------+----------------------+---------+
| group_replication | ACTIVE | GROUP REPLICATION | group_replication.so | GPL |
+----------------------------------+----------+--------------------+----------------------+---------+
2.3 创建复制用户
1.创建用户
mysql> create user repl@'192.168.40.%' identified by '12345678';
Query OK, 0 rows affected (0.00 sec)
2.授权
mysql> grant replication slave on *.* to repl@'192.168.40.%';
Query OK, 0 rows affected (0.01 sec)
3.刷新权限表
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
2.4 配置复制通道
1.说明
由于8.0使用的是caching_sha2_password密码认证插件,
所以需要在配置文件中添加loose-group_replication_recovery_get_public_key