前提:配置好jdk环境
从http://sourceforge.net/projects/amoeba/files下载amoeba的源码(java),
创建 /usr/local/amoeba-mysql-2.2.0目录
将amoeba源码解压到 /usr/local/amoeba-mysql-2.2.0目录中,并创建链接amoeba->amoeba-mysql-2.2.0
配置相关环境变量
cat >> /etc/profile.d/amoeba.sh <<EOF
AMOEBA_HOME=/usr/local/amoeba
PATH=$PATH:$AMOEBA_HOME/bin
EOF
. /etc/profile.d/amoeba.sh
编辑配置文件
#cat 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">3306</property>
#设置amoeba监听的端口
<!-- bind ipAddress -->
<!--
<property name="ipAddress">127.0.0.1</property>
#设置监听的接口,如果不设置,则监听所有的IP
-->
<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">gentoo</property>
<property name="password">mypass</property>
<!--这里设置amoeba自己的认证机制,客户端连接amoeba时需要使用这里设定的账号密码,这里的账号密码和amoeba连接后端数据库服务器的密码无关-->
<property name="filter">
<bean class="com.meidusa.amoeba.server.IPAccessController">
<property name="ipFile">${amoeba.home}/conf/access_list.conf</property>
#设置ACL
</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>
-->
<property name="port">9066</property>
<!-- bind ipAddress -->
<property name="ipAddress">127.0.0.1</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.meidusa.amoeba.net.MultiConnectionManagerWrapper">
<property name="subManagerClassName">com.meidusa.amoeba.net.ConnectionManager</property>
<!--
default value is avaliable Processors
<property name="processors">5</property>
-->
</connectionManager>
<connectionManager name="defaultManager" class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper">
<property name="subManagerClassName">com.meidusa.amoeba.net.AuthingableConnectionManager</property>
<!--
default value is avaliable Processors
<property name="processors">5</property>
-->
</connectionManager>
</connectionManagerList>
<!-- default using file loader -->
<dbServerLoader class="com.meidusa.amoeba.context.DBServerConfigFileLoader">
<property name="configFile">${amoeba.home}/conf/dbServers.xml</property>
#设置dbServer的配置文件
</dbServerLoader>
<queryRouter class="com.meidusa.amoeba.mysql.parser.MysqlQueryRouter">
<property name="ruleLoader">
<bean class="com.meidusa.amoeba.route.TableRuleFileLoader">
<property name="ruleFile">${amoeba.home}/conf/rule.xml</property>
<property name="functionFile">${amoeba.home}/conf/ruleFunctionMap.xml</property>
</bean>
</property>
<property name="sqlFunctionFile">${amoeba.home}/conf/functionMap.xml</property>
<property name="LRUMapSize">1500</property>
<property name="writePool">node1</property>
<property name="readPool">mypool</property>
#指定读池,这里的值必须是dbServers.xml中设置 dbServer
<property name="defaultPool">node1</property>
#defaultPool是必需的
<!--
<property name="writePool">server1</property>
<property name="readPool">server1</property>
-->
<property name="needParse">true</property>
</queryRouter>
</amoeba:configuration>
#cat dbServers.xml
<?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">
#设置一个abstractive的dbServer,相当于一个template
<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">mydb</property>
#设置缺省的数据库,当连接amoeba时,操作表必须显式的指定数据库名,即采用dbname.tablename的方式,不支持 use dbname指定缺省库,因为操作会倍调度到各个后端dbserver
<!-- mysql user -->
<property name="user">amoeba</property>
<property name="password">amoebapass</property>
#设置amoeba连接后端数据库服务器的账号和密码,需在后端数据库器上创建该用户,并允许amoeba连接
</factoryConfig>
<poolConfig class="com.meidusa.amoeba.net.poolable.PoolableObjectPool">
<property name="maxActive">500</property>
#最大连接数
<property name="maxIdle">500</property>
#最大空闲连接数
<property name="minIdle">10</property>
<property name="minEvictableIdleTimeMillis">600000</property>
<property name="timeBetweenEvictionRunsMillis">600000</property>
<property name="testOnBorrow">true</property>
<property name="testOnReturn">true</property>
<property name="testWhileIdle">true</property>
</poolConfig>
</dbServer>
<dbServer name="node1" parent="abstractServer">
#设置一个后端的dbServer,名为node1――自己随便取
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">10.0.9.11</property>
#后端dbserver的IP
</factoryConfig>
</dbServer>
<dbServer name="slave" parent="abstractServer">
#继承抽象服务器abstractServer的值,比如password的值就是继承上面abstractServer的设置
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">10.0.9.1</property>
</factoryConfig>
</dbServer>
<dbServer name="mypool" virtual="true">
#指定一个虚拟的dbServer,将上面定义的dbserver加入这个虚拟的dbserver,相当于一个组
<poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
<!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
<property name="loadbalance">1</property>
#设置调度算法
<!-- Separated by commas,such as: server1,server2,server1 -->
<property name="poolNames">node1,slave,slave,slave</property>
#负载均衡,即使不是有加权的调度算法,slave当成3个服务器进行调度,这模拟量加权的调度算法。注意这里使用的dbserver必须是已经定义了的
</poolConfig>
</dbServer>
</amoeba:dbServers>
amoeba本身是个shell脚本,可在其中配置amoeba启动时使用的一些设置,比如
DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss128k" 配置JAVA相关的变量