使用mysql shell搭建MGR

news/2024/8/26 14:55:41 标签: mysql

准备环境

资源有限只需要准备一台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’)


http://www.niftyadmin.cn/n/5558202.html

相关文章

【iOS】——ARC源码探究

一、ARC介绍 ARC的全称Auto Reference Counting. 也就是自动引用计数。使用MRC时开发者不得不花大量的时间在内存管理上,并且容易出现内存泄漏或者release一个已被释放的对象,导致crash。后来,Apple引入了ARC。使用ARC,开发者不再…

Brown模型,在概率论中,通常指的是布朗运动(Brownian Motion)的数学模型。

13. Brown模型解释与Python代码示例 一、模型解释 Brown模型,在概率论中,通常指的是布朗运动(Brownian Motion)的数学模型。布朗运动是一种随机过程,它描述了微小粒子在液体或气体中由于与周围分子的随机碰撞而产生的…

钡铼Profinet、EtherCAT、Modbus、MQTT、Ethernet/IP、OPC UA分布式IO系统BL20X系列耦合器

BL20X系列耦合器是钡铼技术开发的一款用于分布式I/O系统的设备,专为工业环境下的高速数据传输和远程设备控制而设计,支持多种工业以太网协议,包括Profinet、EtherCAT、Modbus、MQTT、Ethernet/IP和OPC UA等。如果您正在考虑部署BL20X系列耦合…

VGMP(VRRP组管理协议)和HRP(华为冗余技术)

1、VGMP VGMP(VRRP Group Management Protocol):VRRP组管理协议,是华为开发的一种私有协议,主要用于实现对多个VRRP组进行统一管理的功能 概述:VGMP协议是在VRRP协议的基础上开发的,其最主要的…

redis-缓存三剑客

缓存穿透 定义 缓存穿透是指用户请求的数据既不在缓存中,也不在数据库中。每次这样的请求都会穿透缓存,直接访问数据库,增加数据库的负载。 原因 恶意攻击:攻击者不断请求不存在的数据。无效请求:用户请求的数据在…

数据可视化在石油新能源行业的应用:深度探索与前沿趋势

引言 随着全球对能源需求的不断增长和环保意识的日益增强,石油新能源行业正面临着前所未有的挑战与机遇。在这个背景下,数据可视化技术以其直观、易懂、高效的特点,为石油新能源行业提供了强大的支持。本文将从数据可视化的基本概念出发&…

【源码阅读】osproxy对象存储分布式代理(2)--初始化底层服务和日志器

文章目录 初始化底层服务函数返回类型APPRedis newLangGoConfig()函数initLangGoConfig()函数 初始化日志器 上一章【源码阅读】osproxy对象存储分布式代理(1)下一章 这部分涉及了对于底层服务的初始化和日志器的初始化两部分 // 初始化底层服务&#x…

【Godot4.2】MLTag类:HTML、XML通用标签类

概述 HTML和XML采用类似的标签形式。 之前在Godot中以函数库形式实现了网页标签和内容生成。能用,但是缺点也很明显。函数之间没有从属关系,但是多有依赖,而且没有划分出各种对象和类型。 如果以完全的面向对象形式来设计标签类或者元素类…