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

amoeba for mysql 部署读写分离

先简单介绍下amoeba
Amoeba(变形虫)项目,该开源框架于2008年 开始发布一款 Amoeba for Mysql软件。这个软件致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的 时候充当SQL路由功能,专注于分布式数据库代理层(Database Proxy)开发。座落与 Client、DB Server(s)之间,对客户端透明。具有负载均衡、高可用性、SQL 过滤、读写分离、可路由相关的到目标数据库、可并发请求多台数据库合并结果。 通过Amoeba你能够完成多数据源的高可用、负载均衡、数据切片的功能。

初次使用,amoeba是基于java开发的,运行时需要java环境。

amoeba分为4个只要的配置文件,
分别位于/conf 文件夹下
amoeba.XML 是基本的配置信息,主要是外部访问amoeba时的一些验证及地址端口的配置。DBserver.XML这个是mysqlserver list? ,将所有的数据库服务器写入到此文件。
rule.xml 这个是读写分离,负载均衡、数据切片的一些规则。
access_list.conf 是访问amoeba机器的控制。

以上4个配置文件为常用的几个,其他的文件就不一一说明了,可以看一下amoeba的使用说明http://docs.hexnova.com/amoeba/index.html


安装:
http://sourceforge.net/projects/amoeba/files/ 为amoeba的下载地址。

下载完成直接加压到相对应的目录即可,我解压到d:/下目录为D:\amoeba。
然后下cmd下 进入到D:\amoeba\bin,输入amoeba验证是否正确(jdk的运行环境安装就不在这里说了)

配置:
amoeba.xml

<?xml version="1.0" encoding="gbk"?>

<!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd">
<amoeba:configuration xmlns:amoeba="http://amoeba.meidusa.com/">

<proxy>

<!-- service class must implements com.meidusa.amoeba.service.Service -->
<service name="Amoeba for Mysql" class="com.meidusa.amoeba.net.ServerableConnectionManager">
<!-- port -->
<property name="port">8066</property>   #访问的端口

<!-- bind ipAddress -->
<!--
<property name="ipAddress">127.0.0.1</property>
-->

<property name="manager">${clientConnectioneManager}</property>

<property name="connectionFactory">
<bean class="com.meidusa.amoeba.mysql.net.MysqlClientConnectionFactory">
<property name="sendBufferSize">128</property>
<property name="receiveBufferSize">64</property>
</bean>
</property>

<property name="authenticator">
<bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">

<property name="user">monkey</property>   #对外部提供的用户名

<property name="password">monkey@123</property>#对外部提供的密码

<property name="filter">
<bean class="com.meidusa.amoeba.server.IPAccessController">
<property name="ipFile">${amoeba.home}/conf/access_list.conf</property>
</bean>
</property>
</bean>
</property>

</service>

<!-- server class must implements com.meidusa.amoeba.service.Service -->
<service name="Amoeba Monitor Server" class="com.meidusa.amoeba.monitor.MonitorServer">
<!-- port -->
<!--  default value: random number
<property name="port">9066</property>
-->
<!-- bind ipAddress -->
<property name="ipAddress">192.168.0.165</property> #对外部提供访问的地址
<property name="daemon">true</property>
<property name="manager">${clientConnectioneManager}</property>
<property name="connectionFactory">
<bean class="com.meidusa.amoeba.monitor.net.MonitorClientConnectionFactory"></bean>
</property>

</service>

<runtime class="com.meidusa.amoeba.mysql.context.MysqlRuntimeContext">
<!-- proxy server net IO Read thread size -->
<property name="readThreadPoolSize">20</property>

<!-- proxy server client process thread size -->
<property name="clientSideThreadPoolSize">30</property>

<!-- mysql server data packet process thread size -->
<property name="serverSideThreadPoolSize">30</property>

<!-- per connection cache prepared statement size  -->
<property name="statementCacheSize">500</property>

<!-- query timeout( default: 60 second , TimeUnit:second) -->
<property name="queryTimeout">60</property>
</runtime>

</proxy>

<!--
Each ConnectionManager will start as thread
manager responsible for the Connection IO read , Death Detection
-->
<connectionManagerList>
<connectionManager name="clientConnectioneManager" class="com.meidus