广告
返回顶部
首页 > 资讯 > 数据库 >数据库中间件DBLE学习(一) 基础介绍和快速搭建
  • 874
分享到

数据库中间件DBLE学习(一) 基础介绍和快速搭建

数据库中间件DBLE学习(一)基础介绍和快速搭建 2014-12-31 09:12:05 874人浏览 绘本
摘要

dble基本架构简介 dble是上海爱可生信息技术股份有限公司基于Mysql的高可用扩展性的分布式中间件。江湖人送外号MyCat Plus。开源地址 我们首先来看架构图,外部应用通过NIO/Aio进行连接操作。这里首先我们得介绍一下NIO

dble基本架构简介

dble是上海爱可生信息技术股份有限公司基于Mysql高可用扩展性的分布式中间件。江湖人送外号MyCat Plus开源地址

dble架构
我们首先来看架构图,外部应用通过NIO/Aio进行连接操作。这里首先我们得介绍一下NIO/aiO是什么概念。

  • BIO 即传统的Blocking I/O,是jdk1.4之前的唯一选择。同步阻塞I/O模式并发处理能力低。
  • NIO 也叫Non-Blocking I/O,在JDK1.4版本之后发布的新功能,同步非阻塞模式
  • AIO 也叫Asynchronous I/O,在JDK1.7版本之后才支持,是异步非阻塞I/O模型

可以看到应用发起之后,首先经过NIO操作来到sql Parse层进行解析。SQL解析生产执行计划,然后路由下发到各个底层mysql Sharding数据库中执行,这个后台执行的过程也是通过NIO/AIO来实现的。底层各个数据库执行完成之后再返回到中间层进行合并、过滤、分组、排序等操作,最终在返回给客户端。

对基本架构有所了解后,我们来做快速的搭建。首先进行下载:DBLE下载地址,最新版本是2.19.09.0,这里选择下载actiontech-dble-2.19.09.0.tar.gz。我们快速搭建的环境和IP如下:

服务器 IP地址 描述
DBLE服务器 192.168.56.185 DBLE实例,数据库中间件,负责接收SQL进行路由分发
MySQL A服务器 192.168.56.181 物理实例A,将会创建db1,db3,db5三个schema
MySQL B服务器 192.168.56.182 物理实例B,将会创建db2,db4,db6三个schema

dble搭建

dble快速安装

1.首先需要在dble Server服务器配置JAVA1.8的环境变量.

Centos 7中默认是安装了JDK1.8的,如果没有安装需要安装一下。我们系统本身已经安装好的环境做一下配置。

export JAVA_HOME=/etc/alternatives/jre_1.8.0_openjdk
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin

[root@mycat bin]# java -version
openjdk version "1.8.0_161"

OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

2.在dble Server服务器上创建安装目录并解压文件

把安装介质actiontech-dble-2.19.09.0.tar.gz上传到dble server服务器上。

cd /tmp
tar -xvf actiontech-dble-2.19.09.0.tar.gz
mkdir -p /dble
cd /tmp/dele
mv * /dble
cd /dble/conf

接下来需要copy三个模板文件进行修改。这里简单介绍下这三个文件的作用:
| 文件名称 | 作用 |
| --- | --- |
| rule.xml | 对分片的规则进行定义|
| schema.xml | 对具体的分片进行定义,定义table和schema以及datanode之间的关系,指定每个table将要使用哪种类型的分片方法,定义每个dataNode的连接信息等等 |
| server.xml | dble服务器相关参数定义,包含dble性能、定时任务、端口、用户配置 |

cp -rp server_template.xml server.xml
cp -rp schema_template.xml schema.xml
cp -rp rule_template.xml rule.xml

3.在两套MySQL服务器上配置root用户

为了快捷安装,需要在两台MySQL Server给root可以远程登录的相关操作权限.

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.000 sec

4.在dble server上配置schema.xml文件,主要修改下列地方

这里的dataHost是节点名称。我们有两套服务器,需要配置相关writeHost的IP地址,然后Mysql的用户名和密码(为了简单方便这里暂时使用root)。


    show slave status
    
    
    


    show slave status
    
    
    

5.启动dble

这里通过dble命令就可以启动程序了,启动后,可以查看wrapper.log,显示Server startup successfully则成功启动。

[root@mycat logs]# dble start
Starting dble-server...

---->wrapper.log日志
STATUS | wrapper  | 2019/12/17 23:25:25 | --> Wrapper Started as Daemon
STATUS | wrapper  | 2019/12/17 23:25:25 | Launching a JVM...
INFO   | jvm 1    | 2019/12/17 23:25:26 | Wrapper (Version 3.2.3) Http://wrapper.tanukisoftware.org
INFO   | jvm 1    | 2019/12/17 23:25:26 |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.
INFO   | jvm 1    | 2019/12/17 23:25:26 | 
INFO   | jvm 1    | 2019/12/17 23:25:28 | Server startup successfully. dble version is [5.6.29-dble-2.19.09.0-fd62e7a27a561169acabc11df32b2f0d13a0b922-20191121135714]. Please see logs in logs/dble.log

6.登录进行验证

接下来我们就可以使用root用户来登录192.168.56.185数据库中间件主机来进行管理了。这里通过181主机远程进行登录,因为185上没安装Mysql客户端。

[root@mysql5 ~]# mysql -uroot -p -P8066 -h192.168.56.185 -p123456
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.6.29-dble-2.19.09.0-fd62e7a27a561169acabc11df32b2f0d13a0b922-20191121135714 dble Server (ActionTech)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MySQL [(none)]> show databases;
+----------+
| DATABASE |
+----------+
| testdb   |
| testdb2  |
+----------+
2 rows in set (0.002 sec)
MySQL [(none)]> use testdb;
Database changed
MySQL [testdb]> show tables;
Empty set (0.002 sec)

7.创建数据分片

之前我们配置的schema.xml文件中,我们有以下默认的配置。该文件配置了6个数据分片,分别对应不同主机不同实例中的6套schema。







此时我们需要通过管理账号来进行操作。打开server.xml文件。找到用户这里。第一个定义的用户为管理用户。还有开头的端口配置,默认管理端口是9066。


        654321
        true
        



通过管理账号man1和9066端口登录,就可以执行管理命令,这里我们按照schema.xml中dataNode的规划创建分片。这里创建很方便,可以支持dn$1-n的写法。

[root@mysql5 ~]# mysql -uman1 -p -P9066 -h192.168.56.185 -p654321
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.6.29-dble-2.19.09.0-fd62e7a27a561169acabc11df32b2f0d13a0b922-20191121135714 dble Server (ActionTech)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MySQL [(none)]> create database @@dataNode='dn$1-6';
Query OK, 1 row affected (0.049 sec)

接下来我们可以登录MySQL A上进行验证。在A实例中,我们可以看到创建了schema db_1,db_3,db_5。和我们的schema.xml文件中配置结果一致。

[root@mysql5 ~]# mysql -uroot -S /tmp/mysql.sock1 -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 190
Server version: 10.3.17-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| db_1               |
| db_3               |
| db_5               |
| infORMation_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
7 rows in set (0.001 sec)

8.创建测试

在dble的conf目录下面有个配置文件叫template_table.sql,这个文件是提供给我们测试一些测试用例。因为在192.168.56.185上没有安装MySQL服务,管理端口9066和服务端口8066实际都是Java在监听,我们需要先把这个文件scp到192.168.56.181上。利用181上的MySQL程序远程连接185来操作。

[root@mycat conf]# ps -ef | grep mysql
root      3670  1287  0 00:28 pts/0    00:00:00 grep --color=auto mysql
[root@mycat conf]# netstat -anp | grep 8066
tcp6       0      0 :::8066                 :::*                    LISTEN      3432/java           
[root@mycat conf]# netstat -anp | grep 9066
tcp6       0      0 :::9066                 :::*                    LISTEN      3432/java   
[root@mycat conf]# scp template_table.sql root@192.168.56.181:/root

---登录到181上连接管理端口8066执行脚本。
[root@mysql5 ~]# mysql -uroot -p -P8066 -h192.168.56.185 -p123456
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.6.29-dble-2.19.09.0-fd62e7a27a561169acabc11df32b2f0d13a0b922-20191121135714 dble Server (ActionTech)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MySQL [(none)]> source /root/template_table.sql

---创建完之后就可以登录到testdb查询创建的表,可以看到表的类型,有全局表和分片表。
MySQL [testdb]> use testdb;
Database changed
MySQL [testdb]> show all tables;
+----------------------+----------------+
| Tables_in_testdb     | Table_type     |
+----------------------+----------------+
| tb_child1            | SHARDING TABLE |
| tb_child2            | SHARDING TABLE |
| tb_child3            | SHARDING TABLE |
| tb_date              | SHARDING TABLE |
| tb_enum_sharding     | SHARDING TABLE |
| tb_global1           | GLOBAL TABLE   |
| tb_global2           | GLOBAL TABLE   |
| tb_grandson1         | SHARDING TABLE |
| tb_grandson2         | SHARDING TABLE |
| tb_hash_sharding     | SHARDING TABLE |
| tb_hash_sharding_er1 | SHARDING TABLE |
| tb_hash_sharding_er2 | SHARDING TABLE |
| tb_hash_sharding_er3 | SHARDING TABLE |
| tb_hash_string       | SHARDING TABLE |
| tb_jump_hash         | SHARDING TABLE |
| tb_mod               | SHARDING TABLE |
| tb_parent            | SHARDING TABLE |
| tb_pattern           | SHARDING TABLE |
| tb_range_sharding    | SHARDING TABLE |
| tb_single            | SHARDING TABLE |
| tb_uneven_hash       | SHARDING TABLE |
+----------------------+----------------+
21 rows in set (0.002 sec)

---接下来可以使用explain来查看分片表的执行情况。这里我不带条件查询tb_mod,可以发现使用了广播sql,会对4个分片进行扫描。为什么会是4个分片,这里我们需要看schema.xml中对表的定义。
[DBLE下载地址](https://github.com/actiontech/dble/releases),
MySQL [testdb]> explain select * from tb_mod;
+-----------+----------+----------------------+
| DATA_NODE | TYPE     | SQL/REF              |
+-----------+----------+----------------------+
| dn1       | BASE SQL | select * from tb_mod |
| dn2       | BASE SQL | select * from tb_mod |
| dn3       | BASE SQL | select * from tb_mod |
| dn4       | BASE SQL | select * from tb_mod |
+-----------+----------+----------------------+
4 rows in set (0.006 sec)
如果我查询id=2,就会通过分片键进行查询,这里是取模算法,2是放在dn3分片上的。
MySQL [testdb]> explain select * from tb_mod where id=2;
+-----------+----------+---------------------------------+
| DATA_NODE | TYPE     | SQL/REF                         |
+-----------+----------+---------------------------------+
| dn3       | BASE SQL | select * from tb_mod where id=2 |
+-----------+----------+---------------------------------+
1 row in set (0.054 sec)

结尾语:

dble还是比较好安装的,但是它的概念和配置xml是有点繁琐的。需要细心一些。

参考文档

dble微课堂 https://opensource.actionsky.com/20191125-dble/ 2.开源分布式中间件 DBLE 快速入门指南 https://www.jianshu.com/p/cd5911058c

您可能感兴趣的文档:

--结束END--

本文标题: 数据库中间件DBLE学习(一) 基础介绍和快速搭建

本文链接: https://www.lsjlt.com/news/3392.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作