mysql innodb cluster 搭建

根据文档搭建...https://dev.mysql.com/doc/refman/8.0/en/mysql-innodb-cluster-production-deployment.html

环境准备:
1 下载和安装需要的软件(本人的软件版本--都是mysql Community中的Linux Generic版本)
mysql-server(mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz)
mysql-router(mysql-router-8.0.17-linux-glibc2.12-x86_64.tar.xz)
mysql-shell(mysql-shell-8.0.17-linux-glibc2.12-x86-64bit.tar.gz)

安装(以mysql server为例,其他类似,以下都是Mysql_tar操作系统用户操作):
cd /home/mysql_tar
tar -xvf mysql-8.0.17-linux-glibc2.12-x86_64.tar.xz
ln -s mysql-8.0.17-linux-glibc2.12-x86_64 mysql_install(方便升级)
...mysql-router...
....mysql_shell...

  1. 编辑环境变量:
    vim /home/mysql_tar/.bash_profile
    #FOR MYSQL
    MYSQL_HOME=/home/mysql_tar/mysql_install
    PATH=$PATH:$MYSQL_HOME/bin
    export MYSQL_HOME

#MYSQL SHELL
MYSQL_SHELL_HOME=/home/mysql_tar/mysql_shell
PATH=$PATH:$MYSQL_SHELL_HOME/bin
export MYSQL_SHELL_HOME

#MYSQL_ROUTER
MYSQL_ROUTER=/home/mysql_tar/mysql_router
PATH=$PATH:$MYSQL_ROUTER/bin
export MYSQL_ROUTER

export PATH

  1. 准备mysql 配置文件my.cnf
    vim /etc/my.cnf

default-authentication-plugin=mysql_native_password
lower_case_table_names=1
datadir=/data_test
socket=/data_test/mysql.sock
log-error=/data_test/mysqld.log
pid-file=/data_test/mysqld.pid

  1. 创建数据目录文件/data_test(用户和用户组均为mysql_tar)
  2. 初始化mysql
    cd /home/mysql_tar/mysql_install/bin(环境变量设置正确,该步可有可无)
    ./mysqld --initialize --user=mysql_tar(初始化mysql系统表空间和其他重要文件,initialize 拼错的话不会报错,只会提示数据目录找不到)
  3. 启动Mysql
    mysqld_safe --user=mysql_tar &
  4. 连接Mysql并且修改root账户密码:
    ./mysql -u root -S /data_test/mysql.sock -p(也可以通过TCP/IP登陆,这里通过套接字登陆)
    mysql>alter user [email protected] identified by ‘mjj‘;
  5. 通过mysqlsh登陆mysql、检查环境并创建集群
    /home/mysql_tar/mysql_shell/bin/mysqlsh
    MySQL SQL > \connect [email protected]_host_a(加粗的是我的命令)
    Creating a session to ‘[email protected]_host_a‘
    Please provide the password for ‘[email protected]_host_a‘: *
    Save password for ‘[email protected]_host_a‘? [Y]es/[N]o/Ne[v]er (default No): ~~
    MySQL mysql_host_a:33060+ ssl JS > dba.checkInstanceConfiguration();
    Validating local MySQL instance listening at port 3306 for use in an InnoDB cluster...**

This instance reports its own address as mysql_host_a:3306
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...

NOTE: Some configuration options need to be fixed:
+--------------------------+---------------+----------------+--------------------------------------------------+
| Variable | Current Value | Required Value | Note |
+--------------------------+---------------+----------------+--------------------------------------------------+
| binlog_checksum | CRC32 | NONE | Update the server variable |
| enforce_gtid_consistency | OFF | ON | Update read-only variable and restart the server |
| gtid_mode | OFF | ON | Update read-only variable and restart the server |
| server_id | 1 | <unique ID> | Update read-only variable and restart the server |
+--------------------------+---------------+----------------+--------------------------------------------------+

Some variables need to be changed, but cannot be done dynamically on the server.
NOTE: Please use the dba.configureInstance() command to repair these issues.

{
"config_errors": [
{
"action": "server_update",
"current": "CRC32",
"option": "binlog_checksum",
"required": "NONE"
},
{
"action": "server_update+restart",
"current": "OFF",
"option": "enforce_gtid_consistency",
"required": "ON"
},
{
"action": "server_update+restart",
"current": "OFF",
"option": "gtid_mode",
"required": "ON"
},
{
"action": "server_update+restart",
"current": "1",
"option": "server_id",
"required": "<unique ID>"
}
],
"status": "error"
}
MySQL mysql_host_a:33060+ ssl JS > \exit
Bye!

根据错误往/etc/my.cnf添加以下参数:
#for innodb cluster
binlog_checksum=none
enforce_gtid_consistency=on
gtid_mode=on
server_id=1234

  1. 创建集群
    MySQL mysql_host_a:33060+ ssl JS > var cluster = dba.createCluster(‘mjjcluster‘);
    A new InnoDB cluster will be created on instance ‘mysql_host_a:3306‘.

Validating instance at mysql_host_a:3306...

This instance reports its own address as mysql_host_a:3306

Instance configuration is suitable.
Creating InnoDB cluster ‘mjjcluster‘ on ‘mysql_host_a:3306‘...

Adding Seed Instance...
Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.
At least 3 instances are needed for the cluster to be able to withstand up to
one server failure.

10 可以通过cluster.status();命令查看集群状态
MySQL mysql_host_a:33060+ ssl JS > cluster.status();
{
"clusterName": "mjjcluster",
"defaultReplicaSet": {
"name": "default",
"primary": "mysql_host_a:3306",
"ssl": "REQUIRED",
"status": "OK_NO_TOLERANCE",
"statusText": "Cluster is NOT tolerant to any failures.",
"topology": {
"mysql_host_a:3306": {
"address": "mysql_host_a:3306",
"mode": "R/W",
"readReplicas": {},
"role": "HA",
"status": "ONLINE",
"version": "8.0.17"
}
},
"topologyMode": "Single-Primary"
},
"groupInformationSourceMember": "mysql_host_a:3306"
}

11, 其他机子也安装软件和准备环境(dba.checkInstanceConfiguration()通过即可,步骤与主节点类似)

  1. 加入节点:
    MySQL mysql_host_a:33060+ ssl JS > cluster.addInstance(‘[email protected]_host_b:3306‘);(本人另一台机子的主机名是mysql_host_b)
    Cluster.addInstance: Connection ‘[email protected]_host_b:3306‘ is not valid: unable to resolve the IPv4 address. (ArgumentError)
    MySQL mysql_host_a:33060+ ssl JS > cluster.addInstance(‘[email protected]_host_b:3306‘);
    Please provide the password for ‘[email protected]_host_b:3306‘: ***
    Save password for ‘[email protected]_host_b:3306‘? [Y]es/[N]o/Ne[v]er (default No):

NOTE: The target instance ‘mysql_host_b:3306‘ has not been pre-provisioned (GTID set
is empty). The Shell is unable to decide whether incremental distributed state
recovery can correctly provision it.
The safest and most convenient way to provision a new instance is through
automatic clone provisioning, which will completely overwrite the state of
‘mysql_host_b:3306‘ with a physical snapshot from an existing cluster member.
To use this method by default, set the ‘recoveryMethod‘ option to ‘clone‘.

The incremental distributed state recovery may be safely used if you are sure
all updates ever executed in the cluster were done with GTIDs enabled, there
are no purged transactions and the new instance contains the same GTID set as
the cluster or a subset of it. To use this method by default, set the
‘recoveryMethod‘ option to ‘incremental‘.

Please select a recovery method [C]lone/[I]ncremental recovery/[A]bort (default Clone):
Validating instance at mysql_host_b:3306...

This instance reports its own address as mysql_host_b:3306

Instance configuration is suitable.
A new instance will be added to the InnoDB cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours.

Adding instance to the cluster...

Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.
Clone based state recovery is now in progress.

NOTE: A server restart is expected to happen as part of the clone process. If the
server does not support the RESTART command or does not come back after a
while, you may need to manually start it back.

  • Waiting for clone to finish...
    NOTE: mysql_host_b:3306 is being cloned from mysql_host_a:3306
    Stage DROP DATA: Completed
    Clone Transfer
    FILE COPY ############################################################ 100% Completed
    PAGE COPY ############################################################ 100% Completed
    REDO COPY ############################################################ 100% Completed

NOTE: mysql_host_b:3306 is shutting down...

  • Waiting for server restart... ready
  • mysql_host_b:3306 has restarted, waiting for clone to finish...
    ** Stage RESTART: Completed
  • Clone process has finished: 58.50 MB transferred in about 1 second (~inf TB/s)

State recovery already finished for ‘mysql_host_b:3306‘

The instance ‘mysql_host_b:3306‘ was successfully added to the cluster.

。。。完成了,基本的步骤就这些吧。

原文地址:https://blog.51cto.com/291268154/2431479

时间: 2024-10-14 05:03:15

mysql innodb cluster 搭建的相关文章

Mysql Innodb Cluster测试

本文介绍mysql 8版本下的Innodb Cluster配置与测试过程,其核心还是mysql的组复制功能,通过使用mysql shell简化了组复制的配置过程,同时使用mysql route中间件实现了故障的自动转移以及读写分离等功能.之前测试mysql组复制的时候有提出过中间件的问题,mysql-route是个不错的解决方案,前文传送门:http://blog.51cto.com/ylw6006/1976829 一.环境介绍 操作系统:centos linux 7.2 64bitmysql社

MySQL 8.0.11 innodb cluster 运维管理手册之二--集群搭建

MySQL 8.0.11 innodb cluster 高可用集群部署运维管理手册之二 集群建设 作者 方连超 基础环境 系统:centos 7.5Mysql:8.0.11 二进制包Mysqlshell: 8.0.11 rpm 包Mysql router: 8.0.11 二进制包 架构: 192.168.181.101 myrouter1 Keepalived.MySQL-shell.MySQL-Router.MySQL-client 192.168.181.102 myrouter2 Keep

MySQL 8.0.11 innodb cluster 运维管理手册之四-msyqlbackup备份

MySQL 8.0.11 innodb cluster 运维管理手册之四-msyqlbackup备份 作者 方连超 Mysqlbackup 介绍 mysqlbackup是一个热备份工具.也就是说它不像mysqldump那样给表上一个全局锁,由于mysqldump上了这个锁,所以就造成客户端只能对数据库进行读操作不能写,这也就是称mysqldump为温备份的原因.但是mysqlbackup真的有这么吊吗?答案是并没有.对于innodb引擎的表mysqlbackup 热备的:但是对于非innodb表

MySQL 8.0 InnoDB Cluster 恢复故障成员

InnoDB Cluster 一节点丢失初始化故障节点 systemctl stop mysqld rm -rf /var/lib/mysql/* systemctl start mysqld 导出正常节点的数据库,并传到故障节点 mysqldump --all-databases --triggers --routines --events --quick --single-transaction --flush-logs --master-data=2 > dbs.dump scp dbs.

MySQL InnoDB Cluser | Mysql 5.7 集群

目前 本集群 应用在自己的 django demo 环境上,暂时稳定运行. 欢迎加群 620176501 讨论 Mysql 集群的应用. 核心架构 * MySQL 5.7 引入了 Group Replication 功能,可以在一组 MySQL 服务器之间实现自动主机选举,形成一主多从结构.经过高级配置后,可以实现多主多从结构. * MySQL Router 是一个轻量级透明中间件,可以自动获取上述集群的状态,规划 SQL 语句,分配到合理的 MySQL 后端进行执行. * MySQL Shel

MySQL inodb cluster部署

innodb cluster是基于组复制来实现的. 搭建一套MySQL的高可用集群innodb. 实验环境: IP 主机名 系统 软件 192.168.91.46 master RHEL7.4 mysqlshell8.0.17,mysqlrouter8.0.17,mysql8.0.17 192.168.91.35 node1 RHEL7.4 mysql8.0.17 192.168.91.36 node2 RHEL7.4 mysql8.0.17 组复制的部署: master: server_id

2-20 MySQL集群搭建实现高可用

MySQL集群概述和安装环境 MySQL Cluster是MySQL适合于分布式计算环境的高实用.高冗余版本.Cluster的汉语是"集群"的意思.它采用了NDB Cluster 存储引擎,允许在1个 Cluster 中运行多个MySQL服务器. MySQL Cluster 是一种技术,该技术允许在无共享的系统中部署"内存中"数据库的 Cluster .通过无共享体系结构,系统能够使用廉价的硬件,而且对软硬件无特殊要求.此外,由于每个组件有自己的内存和磁盘,不存在单

巧用MySQL InnoDB引擎锁机制解决死锁问题(转)

该文会通过一个实际例子中的死锁问题的解决过程,进一步解释innodb的行锁机制 最近,在项目开发过程中,碰到了数据库死锁问题,在解决问题的过程中,笔者对MySQL InnoDB引擎锁机制的理解逐步加深. 案例如下: 在使用Show innodb status检查引擎状态时,发现了死锁问题: *** (1) TRANSACTION: TRANSACTION 0 677833455, ACTIVE 0 sec, process no 11393, OS thread id 278546 starti

mysql真实环境搭建主从

 mysql真实环境搭建主从 防伪码:人之所以能,是相信能. 前言:当今数据库有oracle mysql  SQL Server ACCESS 等等很多种,今天我们来真实环境搭建mysql主从.先说一下四种数据库的区别: 1.四种数据库的区别: ACCESS:功能相对不是那么强大,主要是开发单机版软件中经常用到. SQL Server:是目前应用比较广泛和普遍的一款数据库,是数据库发展的一个里程碑. MySQL:是一个开源的关系数据库管理系统,有快速.可靠和易于使用的特点:MySQL服务器工作在