日期:2014-05-16  浏览次数:21090 次

mysql读写分离Amoeba3.x的实现


1)安装amoeba(http://sourceforge.net/projects/amoeba/files/)
下载amoeba(1.2.0-GA)后解压到本地(/usr/local/amoeba),即完成安装
2)配置amoeba
# ls
access_list.conf    amoeba.xml        dbServers.xml    functionMap.xml    log4j.xml    ruleFunctionMap.xml
amoeba.dtd                dbserver.dtd    function.dtd     log4j.dtd                rule.dtd     rule.xml
在这里我主要介绍配置  amoeba.xml、dbServers.xml、log4j.xml 三个主要的配置文件,其它文件没有特殊需要默认就可以了夺
# vi access_list.conf 修改允许访问列表
2.0)192.168.152.*:yes
# vi amoeba.xml 修改主配置文件
2.1)把默认端口8066改成3306;前提是你的数据库与amoeba安装的机器不在同一个机器上
<property name="port">3066</property>
2.2)把默认连接用户名和密码改成自己的
<property name="user">root</property>
<property name="password">123456</property>
2.3)把默认的代理服务器客户端进程线程大小数改成300
<!-- proxy server client process thread size -->
<property name="executeThreadSize">300</property>
2.4)把默认注释掉的读写分离选项,把注释去掉并readpool修改成server2
<property name="writePool">server1</property>
<property name="readPool">server2</property>

vi dbServers.xml
增加SEVER2模块,里面的连接用户名密码及地址都表示两台MYSQL的物理机器,192.168.1.11和192.168.1.13 另SERVER1是写,SERVER是读
需要手动增加SERVER2代码,最终改变成如下:
<?xml version="1.0" encoding="gbk"?>
<!DOCTYPE amoeba:dbServers SYSTEM "dbserver.dtd">
<amoeba:dbServers xmlns:amoeba="http://amoeba.meidusa.com/">
<!--   
      Each dbServer needs to be configured into a Pool,
      If you need to configure multiple dbServer with load balancing that can be simplified by the following configuration:
        add attribute with name virtual = "true" in dbServer, but the configuration does not allow the element with name factoryConfig
        such as 'multiPool' dbServer       
    -->
<dbServer name="abstractServer" abstractive="true">
    <factoryConfig class="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory">
      <property name="manager">${defaultManager}</property>
      <property name="sendBufferSize">64</property>
      <property name="receiveBufferSize">128</property>
      <!-- mysql port -->
      <property name="port">3306</property>
      <!-- mysql schema -->
      <property name="schema">test</property>
      <!-- mysql user -->
      <property name="user">root</property>
      <!-- mysql password -->
      <property name="password">123456</property>
    </factoryConfig>

    <poolConfig class="com.meidusa.amoeba.net.poolable.PoolableObjectPool">
      <property name="maxActive">500</property>
      <property name="maxIdle">500</property>
   &nb