DBLE Quick‑Start Guide: Environment Setup, Installation, Configuration, Sharding and Read‑Write Separation
This article provides a step‑by‑step tutorial for preparing the environment, installing DBLE, configuring its sharding and read‑write‑separation features, and verifying the setup with command‑line examples and configuration file snippets, enabling developers to quickly get started with the DBLE middleware.
1. Environment Preparation
Download the DBLE project resources and install a JDK (Java 1.8 or higher). Ensure the JAVA_HOME variable points to the JDK directory.
# yum install java-1.8.0-openjdk
java -version
openjdk version "1.8.0_191"
OpenJDK 64‑Bit Server VM (build 25.191‑b12, mixed mode)2. Install DBLE
Download the latest DBLE release from the official GitHub repository, extract the tarball, and place the files in a working directory.
mkdir -p $working_dir
cd $working_dir
tar -xvf actiontech-dble-$version.tar.gz
cd $working_dir/dble/confAfter extraction the directory structure should look like the screenshot shown in the original article.
3. Configure DBLE
All configuration files reside in the conf directory. The most important files are server.xml, schema.xml, and rule.xml.
3.1 Application Scenario 1 – Data Sharding
Define a logical schema that splits the users table across two MySQL instances (A and B) using a modulo‑2 hash algorithm.
<!-- server.xml snippet (relevant parts) -->
<system>
<property name="serverPort">8066</property>
<property name="managerPort">9066</property>
</system>
<user name="man1" password="654321" manager="true"/>
<user name="test" password="password" schemas="testdb"/> <!-- schema.xml snippet -->
<dble:schema xmlns:dble="http://dble.cloud/">
<schema name="testdb">
<table name="users" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-mod2"/>
</schema>
<dataNode name="dn1" dataHost="Group1" database="testdb"/>
<dataNode name="dn2" dataHost="Group2" database="testdb"/>
<dataHost name="Group1" maxCon="1000" minCon="10" balance="0" switchType="1" slaveThreshold="100">
<heartbeat>show slave status</heartbeat>
<writeHost host="MySQLA" url="172.16.3.1:14014" user="test" password="password"/>
</dataHost>
<dataHost name="Group2" maxCon="1000" minCon="10" balance="0" switchType="1" slaveThreshold="100">
<heartbeat>show slave status</heartbeat>
<writeHost host="MySQLA" url="172.16.3.1:14015" user="test" password="password"/>
</dataHost>
</dble:schema> <!-- rule.xml snippet -->
<tableRule name="sharding-by-mod2">
<rule>
<columns>id</columns>
<algorithm>hashmod2</algorithm>
</rule>
<function name="hashmod2" class="Hash">
<property name="partitionCount">2</property>
<property name="partitionLength">1</property>
</function>
</tableRule>Create the logical table in the underlying MySQL databases:
CREATE TABLE `users` (
`id` int(11) NOT NULL,
`user` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;3.2 Application Scenario 2 – Read‑Write Separation
Configure a master‑slave pair for MySQL A (master) and MySQL B (slave) and adjust the balance attribute to enable read‑write splitting.
<!-- schema.xml for read‑write separation -->
<schema name="testdb" dataNode="dn1">
</schema>
<dataNode name="dn1" dataHost="Group1" database="testdb"/>
<dataHost name="Group1" maxCon="1000" minCon="10" balance="3" switchType="1" slaveThreshold="100">
<heartbeat>show slave status</heartbeat>
<writeHost host="MySQLA" url="172.16.3.1:14014" user="test" password="password"/>
<readHost host="MySQLB" url="172.16.3.1:14015" user="test" password="password"/>
</dataHost>The balance="3" setting tells DBLE to route read traffic to the slave host while writes go to the master.
4. Verify the Configuration
Start DBLE:
# ./bin/dble start
## DBLE logs show successful startup ##
STATUS | wrapper | 2019/01/21 17:31:43 | --> Wrapper Started as Daemon
INFO | jvm 1 | 2019/01/21 17:31:44 | Server startup successfully.Connect to DBLE’s business port (8066) and perform basic SQL operations:
mysql -P8066 -h 127.0.0.1 -utest -ppassword
INSERT INTO users(id,user) VALUES(1,'zhangsan');
INSERT INTO users(id,user) VALUES(2,'lisi');
EXPLAIN SELECT * FROM users;The EXPLAIN output shows that the query is dispatched to both data nodes dn1 and dn2, confirming sharding.
+-----------+----------+---------------------+
| DATA_NODE | TYPE | SQL/REF |
+-----------+----------+---------------------+
| dn1 | BASE SQL | select * from users |
| dn2 | BASE SQL | select * from users |
+-----------+----------+---------------------+For read‑write separation, log into the management port (9066) and run show @@datasource. The READ_LOAD counter on the slave node increases, demonstrating that read queries are routed to the slave.
5. Summary
The guide walks through two typical DBLE use‑cases—hash‑based data sharding and master‑slave read‑write separation—by preparing the environment, installing the middleware, editing server.xml, schema.xml, and rule.xml, and finally validating the setup with command‑line tests.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Aikesheng Open Source Community
The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
