Database middleware DBLE learning (a) Based on the introduction and quickly erected

dble Basic Architecture Overview

dble is 上海爱可生信息技术股份有限公司based on mysqldistributed middleware scalability of high availability. Individuals who sent the nickname MyCat Plus. Open source address

dble architecture
We first look at the architecture diagram, connect an external application operated by NIO / AIO. Here first of all we have to introduce the NIO / AIO is what the concept.

  • BIO i.e. conventional Blocking I / O, is the only option before JDK1.4. 同步阻塞I/O模式Low concurrent processing capability.
  • NIO also known as Non-Blocking I / O, the new features released after JDK1.4 version 同步非阻塞模式.
  • AIO also known as Asynchronous I / O, support only after JDK1.7 version is 异步非阻塞I/O模型.

After you can see the application launch, the first operation to SQL Parse through the NIO layer for resolution. SQL parsing production execution plan, and executes a database routing onward transport underlying MySQL Sharding, the background of this process is achieved by NIO / AIO. After completion of the execution of each underlying database is returned to the intermediate layers were combined, filtered, grouping, sorting and other operations, eventually returned to the client.

After an understanding of the basic structure, we do a quick set up. First download: DBLE Download the latest version 2.19.09.0here choose to download actiontech-dble-2.19.09.0.tar.gz. We quickly set up the environment and IP are as follows:

server IP addresses description
DBLE server 192.168.56.185 DBLE instance, middleware, database, SQL is responsible for receiving routing distribution
MySQL A server 192.168.56.181 Physical instances of A, will create db1, db3, db5 three schema
MySQL B server 192.168.56.182 Physical instance B, will create db2, db4, db6 three schema

dble build

dble quick installation

1. First you need to configure the environment variables JAVA1.8 in dble Server server.

在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)。

<dataHost name="dataHost1" maxCon="1000" minCon="10" balance="0" switchType="-1" slaveThreshold="100">
    <heartbeat>show slave status</heartbeat>
    <!-- can have multi write hosts -->
    <writeHost host="hostM1" url="192.168.56.181:3306" user="root" password="123456">
    </writeHost>
</dataHost>
<dataHost name="dataHost2" maxCon="1000" minCon="10" balance="0" switchType="-1" slaveThreshold="100">
    <heartbeat>show slave status</heartbeat>
    <!-- can have multi write hosts -->
    <writeHost host="hostM2" url="192.168.56.182:3306" user="root" password="123456">
    </writeHost>
</dataHost>

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.登录进行验证

Then we will be able to log 192.168.56.185 host database middleware to manage the root user. Log in here by 181 host remote, because no installation on 185 Mysqlclients.

[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. Create a data slice

schema.xml configuration files before us, we have the following default configuration. The data file is configured with six fragments corresponding to different examples of different sets of hosts 6 schema.

<!-- <dataNode name="dn1$0-743" dataHost="dataHost1" database="db$0-743" /> -->
<dataNode name="dn1" dataHost="dataHost1" database="db_1"/>
<dataNode name="dn2" dataHost="dataHost2" database="db_2"/>
<dataNode name="dn3" dataHost="dataHost1" database="db_3"/>
<dataNode name="dn4" dataHost="dataHost2" database="db_4"/>
<dataNode name="dn5" dataHost="dataHost1" database="db_5"/>
<dataNode name="dn6" dataHost="dataHost2" database="db_6"/>

At this point we need to operate through the management account. Open the server.xml file. Users find here. The first user-defined administrative user. Beginning port configuration as well as the default management port is 9066.

<user name="man1">
        <property name="password">654321</property>
        <property name="manager">true</property>
        <!-- manager user can't set schema-->
</user>

<!--<property name="serverPort">8066</property> -->
<!--<property name="managerPort">9066</property> -->

By managing the account man1 and 9066 port login, you can perform administrative command, here we create slices in accordance with the schema.xml dataNode planning. Create here is very convenient, you can support the wording of 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)

Then we can log on MySQL A verified. In example A, we can see to create a schema db_1, db_3, db_5. And our results are consistent schema.xml configuration file.

[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. Create a test table

Conf directory dble below have a configuration file called template_table.sql, this file is available to us to test some test cases. Because not installed on 192.168.56.185 MySQLservice, service management port 9066 and port 8066 are actual Java listening, we need to put this file to scp on 192.168.56.181. 181 using the MySQLprocedure to operate the remote connection 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 [email protected]:/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中对表的定义。
<table name="tb_mod" dataNode="dn1,dn2,dn3,dn4" rule="rule_mod"/>[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)

The end of the phrase:

dble or better installed, but its concept and configuration xml is a bit cumbersome. Some care needs.

Reference Documents

1.dble micro classroom https://opensource.actionsky.com/20191125-dble/ 2. open-source distributed middleware DBLE Quick Start Guide https://www.jianshu.com/p/cd5911058c

Guess you like

Origin www.cnblogs.com/buddy-yuan/p/12091941.html