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 64bit
mysql社区版: 8.0.11
mysql shell版本:8.0.11
mysql route版本:8.0.11

二、下载软件包

1、mysql
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz

2、mysql-router
https://cdn.mysql.com//Downloads/MySQL-Router/mysql-router-8.0.11-linux-glibc2.12-x86-64bit.tar.gz

3、mysql-shell
https://cdn.mysql.com//Downloads/MySQL-Shell/mysql-shell-8.0.11-linux-glibc2.12-x86-64bit.tar.gz

三、安装软件包

(其他两台主机同步配置)

1、配置hosts文件
# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.115.5 vm1
192.168.115.6 vm2
192.168.115.7 vm3

2、安装mysql-shell
# tar -zxvpf mysql-shell-8.0.11-linux-glibc2.12-x86-64bit.tar.gz -C /usr/local/
# cd /usr/local/
# ln -s mysql-shell-8.0.11-linux-glibc2.12-x86-64bit/ mysql-shell

3、安装mysql-route
# tar -zxvpf mysql-router-8.0.11-linux-glibc2.12-x86-64bit.tar.gz  -C /usr/local/
# cd /usr/local/
# ln -s mysql-router-8.0.11-linux-glibc2.12-x86-64bit/ mysql-router

4、安装和初始化mysql
# tar -zxvpf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
# cd /usr/local/
# ln -s mysql-8.0.11-linux-glibc2.12-x86_64/ mysql

# groupadd -g 27 mysql
# useradd -g mysql -u 27 -d /dev/null -s /sbin/nologin mysql
# mkdir -p /mydata
# chown -R mysql.mysql /mydata/

# cat /usr/local/mysql/my.cnf
[client]
password = 123456

[mysqld]
innodb_buffer_pool_size = 256M
socket          = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 100M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 16M
thread_cache_size = 4
max_connections=1500
character_set_server=utf8
group_concat_max_len=65535
log_bin_trust_function_creators=1
log_queries_not_using_indexes = ON
log_throttle_queries_not_using_indexes = 2
log-bin=mysql-bin
binlog_format=row
default_authentication_plugin = mysql_native_password

long_query_time=2
slow_query_log=1
slow_query_log_file=/mydata/slow-query.log
ft_min_word_len=1
innodb_ft_min_token_size=1

server-id=1155
lower_case_table_names = 1
skip-name-resolve
innodb_file_per_table=1
gtid_mode = ON
enforce_gtid_consistency = ON
slave_parallel_workers=4
master_verify_checksum = 1
slave_sql_verify_checksum = 1
log-slave-updates=true
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

slave-parallel-type=LOGICAL_CLOCK
slave-preserve-commit-order=ON
master_info_repository = TABLE
relay_log_info_repository = TABLE

# /usr/local/mysql/bin/mysqld  --defaults-file=/usr/local/mysql/my.cnf --initialize  --user=mysql --basedir=/usr/local/mysql/ --datadir=/mydata --initialize-insecure
# cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld

# egrep ‘basedir|datadir‘ /etc/init.d/mysqld |head -n 5
#   basedir=<path-to-mysql-installation-directory>
# - Add the path to the mysql-installation-directory to the basedir variable
# If you change base dir, you must also change datadir. These may get
basedir=/usr/local/mysql
datadir=/mydata

# chmod +x /etc/init.d/mysqld
# chkconfig --add mysqld
# mv /etc/my.cnf /etc/my.cnf.bak
# ln -s /usr/local/mysql/my.cnf  /etc/
# service mysqld start

mysql> set sql_log_bin=0;
mysql> update mysql.user set host=‘%‘ where user=‘root‘;
mysql> alter user  ‘root‘@‘localhost‘ identified with mysql_native_password by ‘123456‘;
mysql> create user [email protected]‘%‘ identified by ‘123456‘;
mysql> grant all privileges on *.* to [email protected]‘%‘;
mysql> flush privileges;
mysql> set sql_log_bin=1;

四、检查配置

vm1执行即可

使用JS命令,检查每台服务器的配置。三台服务的mysql都要执行检查
# /usr/local/mysql-shell/bin/mysqlsh
 MySQL  JS > dba.checkInstanceConfiguration(‘[email protected]:3306‘)
Please provide the password for ‘[email protected]:3306‘: ******
Validating local MySQL instance listening at port 3306 for use in an InnoDB cluster...

This instance reports its own address as vm1
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 ‘vm1:3306‘ is valid for InnoDB cluster usage.

{
    "status": "ok"
}

执行 dba.checkInstanceConfiguration,当输出 "status": "ok"的时候,表示该服务器检查通过

五、创建组复制

vm1执行即可

 # /usr/local/mysql-shell/bin/mysqlsh --uri [email protected]:3306 

 MySQL  vm1:3306 ssl  JS > var cluster = dba.createCluster(‘main‘)
A new InnoDB cluster will be created on instance ‘[email protected]:3306‘.

Validating instance at vm1:3306...

This instance reports its own address as vm1

Instance configuration is suitable.
Creating InnoDB cluster ‘main‘ on ‘[email protected]: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.

JS > cluster.addInstance(‘[email protected]:3306‘)
JS > cluster.addInstance(‘[email protected]:3306‘) 

 MySQL  vm1:3306 ssl  JS > cluster.status()
{
    "clusterName": "main",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "vm1:3306",
        "ssl": "REQUIRED",
        "status": "OK",
        "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
        "topology": {
            "vm1:3306": {
                "address": "vm1:3306",
                "mode": "R/W",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "vm2:3306": {
                "address": "vm2:3306",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "vm3:3306": {
                "address": "vm3:3306",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            }
        }
    },
    "groupInformationSourceMember": "mysql://[email protected]:3306"
}

六、配置mysql-route

vm1执行即可

# useradd  mysql-router
# /usr/local/mysql-router/bin/mysqlrouter --bootstrap [email protected]:3306 --user mysql-router   --directory /data/mysqlrouter --user=root --conf-use-sockets --force
Please enter MySQL password for root: 

Reconfiguring MySQL Router instance at ‘/data/mysqlrouter‘...
MySQL Router  has now been configured for the InnoDB cluster ‘main‘.

The following connection information can be used to connect to the cluster.

Classic MySQL protocol connections to cluster ‘main‘:
- Read/Write Connections: localhost:6446
- Read/Write Connections: /data/mysqlrouter/mysql.sock
- Read/Only Connections: localhost:6447
- Read/Only Connections: /data/mysqlrouter/mysqlro.sock

X protocol connections to cluster ‘main‘:
- Read/Write Connections: localhost:64460
- Read/Write Connections: /data/mysqlrouter/mysqlx.sock
- Read/Only Connections: localhost:64470
- Read/Only Connections: /data/mysqlrouter/mysqlxro.sock

# /data/mysqlrouter/start.sh
# netstat -anpt |grep router
tcp        0      0 0.0.0.0:64460           0.0.0.0:*               LISTEN      4865/mysqlrouter
tcp        0      0 0.0.0.0:6446            0.0.0.0:*               LISTEN      4865/mysqlrouter
tcp        0      0 0.0.0.0:6447            0.0.0.0:*               LISTEN      4865/mysqlrouter
tcp        0      0 0.0.0.0:64470           0.0.0.0:*               LISTEN      4865/mysqlrouter
tcp        0      0 192.168.115.5:6446      192.168.115.1:63131     ESTABLISHED 4865/mysqlrouter
tcp        0      0 192.168.115.5:36458     192.168.115.5:3306      ESTABLISHED 4865/mysqlrouter
tcp        0      0 192.168.115.5:46488     192.168.115.7:3306      ESTABLISHED 4865/mysqlrouter 

七、连接测试

[[email protected] ~]# /usr/local/mysql/bin/mysql -u root -h 192.168.115.5 -P 6446 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 87
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> SELECT @@port;
+--------+
| @@port |
+--------+
|   3306 |
+--------+
1 row in set (0.00 sec)

mysql> select user,host from mysql.user;
+----------------------------------+-----------+
| user                             | host      |
+----------------------------------+-----------+
| mysql_innodb_cluster_r0467305354 | %         |
| mysql_innodb_cluster_r0467308990 | %         |
| mysql_innodb_cluster_r0467310325 | %         |
| mysql_router1_2x0gxmyjbatp       | %         |
| mysql_router1_x017h4ui76aq       | %         |
| root                             | %         |
| test                             | %         |
| mysql.infoschema                 | localhost |
| mysql.session                    | localhost |
| mysql.sys                        | localhost |
| mysql_innodb_cluster_r0467286081 | localhost |
| mysql_innodb_cluster_r0467305354 | localhost |
| mysql_innodb_cluster_r0467308990 | localhost |
| mysql_innodb_cluster_r0467310325 | localhost |
+----------------------------------+-----------+
14 rows in set (0.00 sec)

[[email protected] ~]#  /usr/local/mysql/bin/mysql -u root -h 192.168.115.5 -P 6447 -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 233
Server version: 8.0.11 MySQL Community Server - GPL

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

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> create database yang;
ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement

mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
| group_replication_applier | 7c8712b3-8b2c-11e8-b41f-000c2994965c | vm1         |        3306 | ONLINE       | SECONDARY   | 8.0.11         |
| group_replication_applier | 862443de-8b2c-11e8-bf4c-000c29c9b5f9 | vm3         |        3306 | ONLINE       | PRIMARY     | 8.0.11         |
| group_replication_applier | 8852b2af-8b2c-11e8-8487-000c2971a45f | vm2         |        3306 | ONLINE       | SECONDARY   | 8.0.11         |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
3 rows in set (0.37 sec)

原文地址:http://blog.51cto.com/ylw6006/2147342

时间: 2024-10-11 07:04:38

Mysql Innodb Cluster测试的相关文章

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-li

mysql InnoDB加锁测试

以下测试基于mysql5.7,隔离级别为:REPEATABLE READ 建表语句如下: create table mytest ( a int primary key AUTO_INCREMENT, b int , c int, d int, KEY idx_b (b), KEY idx_c (c), UNIQUE idx_d (d) ) ENGINE=InnoDB; insert into mytest (b, c,d) VALUES (1,1,1),(3,1,3),(5,3,6),(7,6

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.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 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 Galera Cluster

部署MySQL Galera Cluster 0.功能简介 特性 基于行复制的完全并行同步复制 实时多主架构,任意节点可读写 无延迟复制,事务零丢失,可靠健壮的读写体验. 自动化节点关系控制:节点故障自动摘除,节点加入自动协调 接近原生的MySQL数据库连接的体验 原理简析当一个事务在当前写入的节点提交后,通过wsrep API(write set replication API)将这个事务变成写集(write set)广播到同集群的其他节点中,其他节点收到写集事务后,对这个事务进行可行性检查,

MySQL InnoDB 群集–在Windows上设置InnoDB群集

InnoDB集群最需要的功能之一是Windows支持,我们现在已将其作为InnoDB Cluster 5.7.17预览版 2的一部分提供.此博客文章将向您展示如何在MS Windows 10上运行InnoDB集群.64位系统. 我们将执行以下步骤. 下载包 安装 创建一个InnoDB群集沙箱配置 引导MySQL路由器 测试配置 下一步是什么? 让我们开始吧! 下载包 首先,我们必须下载安装所需的四个组件. 来自dev.mysql.com的具有组复制功能的MySQL Server 5.7.17.

使用mysql innodb 使用5.7的json类型遇到的坑和解决办法

---------------------------------------------- #查询JSON的某个字段 select data -> '$.Host' from temp #创建虚拟列 ALTER TABLE temp ADD host varchar(128) GENERATED ALWAYS AS (json_extract(data,'$.Host')) VIRTUAL; #给虚拟列创建索引 ALTER TABLE temp ADD INDEX index_temp_hos