使用mysql shell搭建MGR

准备环境

资源有限只需要准备一台Linux主机
腾讯云主机159.75.158.18

(1)规划部署

主机端口配置文件数据目录
159.75.158.183381/etc/my3381.cnf/data/3381/data
159.75.158.183382/etc/my3382.cnf/data/3382/data
159.75.158.183383/etc/my3383.cnf/data/3383/data

(2)准备实例配置文件
编辑3个配置文件,分别是
my3381.cnf
my3382.cnf
my3383.cnf

配置文件内容以my3383.cnf为例
将其中对应的数字3383 改为对应端口到不同配置文件

[mysqld]
log_timestamps=SYSTEM
user=mysql
basedir=/usr/local/mysql8
datadir=/data/3383/data
log_bin=/data/3383/binlog/mysql-bin
port=3383
server_id=20243383
socket=/tmp/mysql3383.sock
gtid-mode=on
enforce-gtid-consistency=true
log_slave_updates=1
relay_log_info_repository=TABLE
master_info_repository=TABLE
relay_log_recovery=on

(3)创建目录

mkdir -p /data/3381/data
mkdir -p /data/3381/binlog
mkdir -p /data/3382/data
mkdir -p /data/3382/binlog
mkdir -p /data/3383/data
mkdir -p /data/3383/binlog
chown mysql.mysql -R /data

(4)初始化和启动库

/usr/local/mysql8/bin/mysqld --defaults-file=/etc/my3381.cnf --basedir=/usr/local/mysql8 --initialize-insecure --datadir=/data/3381/data --user=mysql &

/usr/local/mysql8/bin/mysqld --defaults-file=/etc/my3382.cnf --basedir=/usr/local/mysql8 --initialize-insecure --datadir=/data/3382/data --user=mysql &

/usr/local/mysql8/bin/mysqld --defaults-file=/etc/my3383.cnf --basedir=/usr/local/mysql8 --initialize-insecure --datadir=/data/3383/data --user=mysql &



/usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my3381.cnf --user=mysql &

/usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my3382.cnf --user=mysql &

/usr/local/mysql8/bin/mysqld_safe --defaults-file=/etc/my3383.cnf --user=mysql &

(5)创建账号

为了简化步骤,直接执行

三个库都执行

mysql> create user admin@'%' identified by 'admin';
Query OK, 0 rows affected (0.02 sec)

mysql> grant all on *.* to admin@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)

此步骤不规范,正常操作应当是
Create a new admin account for InnoDB cluster with minimal required grants

#在本地通过socket方式登入
$ mysqlsh -S /data/****/mysql.sock root@localhost

执行
dba.configureInstance()

选择
2) Create a new admin account for InnoDB cluster with minimal required grants

数据用户和密码

在使用
mysqlsh --uri 用户@IP:端口 进入mysql shell界面

搭建MySQL shell环境

(1)下载:
https://dev.mysql.com/downloads/shell/

下载的shell版本和数据库版本保持一致

(2)解压
tar -zxvf mysql-shell-8.0.25-linux-glibc2.12-x86-64bit.tar.gz -C /opt/idc/mysql-shell8.0.25

(3)配置环境变量
vi /etc/profile
export PATH=/opt/idc/mysql-shell8.0.25/bin:$PATH
source /etc/profile

使用shell搭建MGR

(1)检查是否适配MGR节点
dba.checkInstanceConfiguration(‘admin@159.75.158.18:3381’)

MySQL  JS > dba.checkInstanceConfiguration('admin@159.75.158.18:3381')
Validating MySQL instance at VM-20-8-centos:3381 for use in an InnoDB cluster...

This instance reports its own address as VM-20-8-centos:3381
Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.

Checking whether existing tables comply with Group Replication requirements...
No incompatible tables detected

Checking instance configuration...
Instance configuration is compatible with InnoDB cluster

The instance 'VM-20-8-centos:3381' is valid to be used in an InnoDB cluster.

{
    "status": "ok"
}

另外两台节点需要做此操作
dba.checkInstanceConfiguration(‘admin@159.75.158.18:3382’)
dba.checkInstanceConfiguration(‘admin@159.75.158.18:3383’)

如果此步报错说不符合MGR节点要求,执行第二步

(2)
执行 dba.configureInstance() 命令开始检查当前实例是否满足安装MGR集群的条件,如果不满足可以直接配置成为MGR集群的一个节点:

dba.configureInstance(‘admin@159.75.158.18:3381’)

dba.configureInstance('admin@159.75.158.18:3381')
Configuring MySQL instance at VM-20-8-centos:3381 for use in an InnoDB cluster...

This instance reports its own address as VM-20-8-centos:3381
Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.

applierWorkerThreads will be set to the default value of 4.

The instance 'VM-20-8-centos:3381' is valid to be used in an InnoDB cluster.
The instance 'VM-20-8-centos:3381' is already ready to be used in an InnoDB cluster.

Successfully enabled parallel appliers.

根据需要选择YES,后再返回执行第一个,看结果是否是OK

另外两个节点同样执行相同步骤
dba.configureInstance(‘admin@159.75.158.18:3382’)
dba.configureInstance(‘admin@159.75.158.18:3383’)

(3)连接主节点
MySQL JS > \connect admin@159.75.158.18:3381

(4)创建集群
dba.createCluster(‘mgrCluster’)
var cluster = dba.getCluster()

(5)添加节点
这里要指定MGR专用账号,我们用的是测试账户不符合规范
cluster.addInstance(‘admin@159.75.158.18:3382’)
cluster.addInstance(‘admin@159.75.158.18:3383’)

(6)查看集群状态

cluster.status()

查看集群状态
  MySQL  159.75.158.18:3381 ssl  JS > cluster.status()
  {
    "clusterName": "mgrCluster", 
    "defaultReplicaSet": {
        "name": "default", 
        "primary": "VM-20-8-centos:3381", 
        "ssl": "REQUIRED", 
        "status": "OK", 
        "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.", 
        "topology": {
            "VM-20-8-centos:3381": {
                "address": "VM-20-8-centos:3381", 
                "memberRole": "PRIMARY", 
                "mode": "R/W", 
                "readReplicas": {}, 
                "replicationLag": null, 
                "role": "HA", 
                "status": "ONLINE", 
                "version": "8.0.25"
            }, 
            "VM-20-8-centos:3382": {
                "address": "VM-20-8-centos:3382", 
                "memberRole": "SECONDARY", 
                "mode": "R/O", 
                "readReplicas": {}, 
                "replicationLag": null, 
                "role": "HA", 
                "status": "ONLINE", 
                "version": "8.0.25"
            }, 
            "VM-20-8-centos:3383": {
                "address": "VM-20-8-centos:3383", 
                "memberRole": "SECONDARY", 
                "mode": "R/O", 
                "readReplicas": {}, 
                "replicationLag": null, 
                "role": "HA", 
                "status": "ONLINE", 
                "version": "8.0.25"
            }
        }, 
        "topologyMode": "Single-Primary"
    }, 
    "groupInformationSourceMember": "VM-20-8-centos:3381"
}

R/O是只读,R/W是读写,PRIMARY是主节点。

补充

切换到多主模式
cluster.switchToMultiPrimaryMode()

切换到单主模式
cluster.switchToSinglePrimaryMode(‘159.75.158.18:3381’)

  • 7
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 在MySQL 8中,可以使用MySQL Shell来管理MySQL Group Replication (mgr)。要重启mgr,请按照以下步骤进行操作: 1.首先,使用MySQL Shell连接到mgr: ```shell mysqlsh node1:3306,node2:3306,node3:3306 ``` 其中,node1、node2和node3是mgr的三个节点的主机名或IP地址,3306是MySQL服务器端口号。 2.检查mgr状态: ```shell mysql-js> var gr = shell.getGroup() mysql-js> gr.status() ``` 3.如果需要重启mgr,请执行以下操作: ```shell mysql-js> gr.stop() mysql-js> gr.start() ``` 这将停止mgr并重新启动它。请注意,在重新启动mgr之前,必须确保所有节点都已启动并处于运行状态。 4.检查mgr状态以确保它已成功重启: ```shell mysql-js> gr.status() ``` 如果mgr状态显示为“ ONLINE”,则表示mgr已成功重启。 ### 回答2: 要重启 MySQL 8 ShellMGR (MySQL Group Replication),您可以按照以下步骤进行操作: 1. 打开 MySQL 8 Shell。可以通过运行命令 `mysqlsh` 来启动 MySQL 8 Shell。 2. 连接到 MGR 的主节点。运行以下命令连接到 MGR 主节点: ```shell \connect username@hostname:port ``` 其中,`username` 是您的 MySQL 用户名,`hostname` 是主节点的主机名或 IP 地址,`port` 是主节点的端口号。 3. 检查 MGR 状态。运行以下命令检查 MGR 的状态: ```shell \sql SELECT * FROM performance_schema.replication_group_members; ``` 这将显示 MGR 中所有成员的状态。确保主节点正常运行,并记录下所有成员的 UUID。 4. 关闭其他成员。为了安全地重启 MGR,您需要先关闭除主节点外的所有成员。使用以下命令关闭其他成员: ```shell \sql STOP GROUP_REPLICATION; ``` 5. 重启主节点。运行以下命令重启主节点: ```shell \sql START GROUP_REPLICATION; ``` 6. 检查 MGR 状态。再次运行第 3 步中的命令,确保所有成员都已重新启动并正常运行。 以上就是使用 MySQL 8 Shell 重启 MGR 的步骤。请确保在执行这些操作之前备份数据库以防止数据丢失。 ### 回答3: 要重启MySQL 8的shell MGR,可以按照以下步骤进行操作: 1. 连接到MySQL Shell:在终端或命令提示符窗口中输入`mysqlsh`命令并按回车键,以启动MySQL Shell。 2. 连接到MGR集群:在MySQL Shell中输入以下命令连接到MGR集群: ``` \connect user@localhost:port ``` 其中,`user`是MGR集群连接的用户名,`localhost`是MGR集群所在的主机地址,`port`是MGR集群连接的端口号。 3. 查看MGR状态:在MySQL Shell中输入以下命令查看当前MGR集群的状态: ``` \status ``` 这将显示出当前各个成员的状态以及其他相关信息。 4. 切换到主节点:在MySQL Shell中输入以下命令切换到MGR集群的主节点: ``` \connect primary ``` 这将切换到当前MGR集群的主节点。 5. 执行重启操作:在主节点MySQL Shell中输入以下命令执行重启操作: ``` STOP GROUP_REPLICATION; SET GLOBAL group_replication_bootstrap_group=ON; START GROUP_REPLICATION; ``` 这将停止MGR集群的复制,启用启动引导,然后重新启动MGR集群。 6. 确认重启完成:在MySQL Shell中输入以下命令确认MGR集群已成功重启: ``` \status ``` 确保所有节点都处于运行状态,并且集群复制已恢复正常。 请注意,执行上述操作需要具有适当的权限。同时,重启MGR集群可能会中断正在进行的数据库操作,因此请在合适的时间进行操作,并确保已进行适当的备份工作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值