用amoeba做mysql数据水平切分与垂直切分

总结示例如下

192.168.17.131 amoeba 应用访问结点

192.168.17.133 作为键值奇数切分DB

192.168.17.134 作为键值偶数切分DB

 

配置如下

一、配置好java运行环境,就不用记录了

二、安装amoeba

1.mkdir /usr/local/amoeba

2.tar xf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba

3.几个关键的配置文件说明

<1.$AMOEBA_HOME/conf/dbServers.xml-------主机IP、端口、Amoeba使用的用户名和密码等

<2.$AMOEBA_HOME/conf/rule.xml--------------切分规则配置

<3.$AMOEBA_HOME/conf/functionMap.xml-----描述了函数名和函数处理的关系

<4.$AMOEBA_HOME/conf/ruleFunctionMap.xml-自己定义的函数

<5.$AMOEBA_HOME/conf/access_list.conf------可访问以及拒绝访问的主机IP地址

<6.$AMOEBA_HOME/conf/log4j.xml-------------输出日志级别以及方式,配置方法使用log4j的文件格式

三、在两台机器 上分别创建切入DB,tb

  create database db1;

  use db1;

  create datatable tb1(id int,name varchar(50));

   grant all on aaa.* to 'amoeba'@'192.168.17.131' identified by '123'; --授权

四、配置几个关键文件

<1.vim /usr/local/amoeba/conf/dbServers.xml

<property name="port">3306</property>

<property name="schema">db1</property>

<property name="user">amoeba</property>

<property name="password">123</property>

<dbServer name="server1"  parent="abstractServer">
  <factoryConfig>
    <property name="ipAddress">192.168.17.133</property>
  </factoryConfig>
</dbServer>

<dbServer name="server2"  parent="abstractServer">
<factoryConfig>
   <property name="ipAddress">192.168.17.134</property>
</factoryConfig>
</dbServer>

<2.vim /usr/local/amoeba/conf/amoeba.xml    --应用访问配置
<property name="user">amoeba</property>
<property name="password">123</property>

 

<3.vim /usr/local/amoeba/conf/rule.xml --定义数据切分的规则
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:rule SYSTEM "rule.dtd">

<amoeba:rule xmlns:amoeba="http://amoeba.meidusa.com/">
        <tableRule name="tb1" schema="db1" defaultPools="server1,server2">
                <rule name="rule1" ruleResult="POOLNAME">
                        <parameters>id</parameters>
                                <expression><![CDATA[
                                        var division = id % 2;
                                                case division when 0 then 'server1';
                                                              when 1 then 'server2';
                                                end case;
                                ]]></expression>
                </rule>
        </tableRule>
</amoeba:rule>

五、启动

bin/amoeba start

六、测试

insert into tb1(id,name)values(1,'1');--此数据进入了192.168.17.133

insert into tb1(id,name)values(2,'2');--此数据进入了192.168.17.134

---以上是水平切分

垂直切分待总结

 

posted @ 2012-10-27 20:39  bobsoft  阅读(461)  评论(0编辑  收藏  举报