1、運行環境
Host Name |
IP |
DB |
Mod |
data0 |
172.16.100.170 |
mysql |
|
data1 |
172.16.100.171 |
mysql |
|
data2 |
172.16.100.172 |
mysql |
|
2、安裝dble
一、上傳安裝dble
須要Java環境,1.8及以上版本mysql
直接解壓dble便可sql
二、dble結構以下
3、配置dble
配置文件放在conf目錄下url
一、配置server.xml 全局信息
cp server_template.xml server.xmlspa
[root@data0 conf]# cat server.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dble:server SYSTEM "server.dtd">
<dble:server xmlns:dble="http://dble.cloud/" version="1.0">
<system>
<property name="serverPort">8066</property> ##操做MySQL端口
<property name="managerPort">9066</property> ##管理MySQL端口
</system>
<!-- firewall config -->
<!--
<firewall>
<whitehost>
<host host="127.0.0.1" user="root"/>
<host host="0:0:0:0:0:0:0:1" user="root"/>
</whitehost>
<blacklist check="true">
<property name="selelctAllow">false</property>
</blacklist>
</firewall>
-->
<user name="man1"> ##管理用戶以及登錄密碼,而且不能設置schema
<property name="password">654321</property>
<property name="manager">true</property>
<!-- manager user can't set schema-->
</user>
<user name="test"> ##操做用戶以及密碼
<property name="password">123456</property>
<property name="schemas">testdb</property>
</user>
</dble:server>
[root@data0 conf]#
二、配置schema.xml 分片信息
cp schema_template.xml schema.xml
[root@data0 conf]# cat schema.xml
<?xml version="1.0"?>
<!DOCTYPE dble:schema SYSTEM "schema.dtd">
<dble:schema xmlns:dble="http://dble.cloud/" version="1.0">
<schema name="testdb">
<table name="users" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="sharding-by-mod2"/>
</schema>
<dataNode name="dn1" dataHost="data0" database="testdb1"/>
<dataNode name="dn2" dataHost="data1" database="testdb2"/>
<dataNode name="dn3" dataHost="data2" database="testdb3"/>
<dataHost name="data0" maxCon="1000" minCon="10" balance="0" switchType="-1" slaveThreshold="100">
<heartbeat>show slave status</heartbeat>
<writeHost host="data0" url="172.16.100.170:14014" user="test" password="123456">
</writeHost>
</dataHost>
<dataHost name="data1" maxCon="1000" minCon="10" balance="0" switchType="-1" slaveThreshold="100">
<heartbeat>show slave status</heartbeat>
<writeHost host="data1" url="172.16.100.171:14015" user="test" password="123456">
</writeHost>
</dataHost>
<dataHost name="data2" maxCon="1000" minCon="10" balance="0" switchType="-1" slaveThreshold="100">
<heartbeat>show slave status</heartbeat>
<writeHost host="data2" url="172.16.100.172:14016" user="test" password="123456">
</writeHost>
</dataHost>
</dble:schema>
[root@data0 conf]#
三、配置rule.xml 分片規則
cp rule_template.xml rule.xml
[root@data0 conf]# cat rule.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dble:rule SYSTEM "rule.dtd">
<dble:rule xmlns:dble="http://dble.cloud/" version="1.0">
<tableRule name="sharding-by-mod2">
<rule>
<columns>id</columns>
<algorithm>hashmod2</algorithm>
</rule>
</tableRule>
<function name="hashmod2" class="Hash">
<property name="partitionCount">3</property>
<property name="partitionLength">1</property>
</function>
</dble:rule>
[root@data0 conf]#
4、登錄驗證
mysql -utest -p123456 -P8066 -h127.0.0.1 testdb