文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

mysql innodb cluster 搭建

2024-04-02 19:55

关注

根据文档搭建...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 root@localhost identified by 'mjj';
  5. 通过mysqlsh登陆mysql、检查环境并创建集群
    /home/mysql_tar/mysql_shell/bin/mysqlsh
    MySQL SQL > \connect root@mysql_host_a(加粗的是我的命令)
    Creating a session to 'root@mysql_host_a'
    Please provide the password for 'root@mysql_host_a': *
    Save password for 'root@mysql_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('root@mysql_host_b:3306');(本人另一台机子的主机名是mysql_host_b)
    Cluster.addInstance: Connection 'root@mysql_host_b:3306' is not valid: unable to resolve the IPv4 address. (ArgumentError)
    MySQL mysql_host_a:33060+ ssl JS > cluster.addInstance('root@mysql_host_b:3306');
    Please provide the password for 'root@mysql_host_b:3306': ***
    Save password for 'root@mysql_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.

NOTE: mysql_host_b:3306 is shutting down...

State recovery already finished for 'mysql_host_b:3306'

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

。。。完成了,基本的步骤就这些吧。
主要方法:
dba.configureInstance()

dba.createCluster()

Cluster.addInstance()----cluster=dba.getCluster()获取cluster变量

Cluster.removeInstance()

Cluster.rejoinInstance()

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯