Amoeba简单配置分片测试实验

下载 Amoeba : http://sourceforge.net/projects/amoeba/files/

配置: \amoeba-mysql-3.0.5-RC\conf

  dbServers.xml

    server1继承abstractServer

 1 <dbServer name="server1"  parent="abstractServer">
 2         <factoryConfig>
 3             <!-- mysql ip -->
 4             <property name="ipAddress">127.0.0.1</property>
 5 
 6             <!-- mysql port -->
 7             <property name="port">3306</property>
 8 
 9         </factoryConfig>
10     </dbServer>

multiPool为多数据源配置,即是数据库切片配置, 注意下面poolNames要包含所有参与分片的数据源名称

1     <dbServer name="multiPool" virtual="true">
2         <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
3             <!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
4             <property name="loadbalance">1</property>
5             
6             <!-- Separated by commas,such as: server1,server2,server1 -->
7             <property name="poolNames">server1,server2</property>
8         </poolConfig>
9     </dbServer>

 

 

  amoeba.xml

  rule.xml

    定义返回的数据内容为数据源名称。parameters为表的字段名称,定以后,下面的expression中可以引用计算(VB脚本)

1     <rule name="rule1" ruleResult="POOLNAME">
2             <parameters>asg_order_id</parameters>
3             <expression><![CDATA[
4                 var division = asg_order_id%2;
5                 case division when 0 then 'server1';
6                               when 1 then 'server2';
7                 end case;
8             ]]></expression>
9         </rule>

 

参考配置: http://docs.hexnova.com/amoeba/

 

上面完成后,进入amoeba命令行:

  mysql -uUSER-pPASS -h127.0.0.1 -P8066

 

插入多条数据测试

insert into asgordertest values (1,'111111111',2,2,'abc',1,1,'2016-01-27 00:00:00');
insert into asgordertest values (2,'222222222',2,2,'abc',1,1,'2016-01-27 00:00:00');
insert into asgordertest values (3,'333333333',2,2,'abc',1,1,'2016-01-27 00:00:00');

 

使用数据库等工具可以看到分别在server1和server2中存在分片数据,测试成功

你可能感兴趣的:(Amoeba简单配置分片测试实验)