amoeba

时间:2022-10-10 17:09:49

Amoeba

原理:amoeba相当于业务员,处理client的读写请求,并将读写请求分开处理。amoeba和master以及slave都有联系,如果是读的请求,amoeba就从slave读取信息反馈给client;如果是写的请求,amoeba会将相关数据写入master。


  • mysql的主从复制:一台负责mysql的写操作,一台负责mysql的读操作

  • java的配置环境


安装amoeba

[root@server2 software]# mkdir /usr/local/amoeba
[root@server2 software]# wget http://softlayer.dl.sourceforge.net/project/amoeba/Amoeba%20for%20mysql/2.x/amoeba-mysql-binary-2.1.0-RC5.tar.gz
[root@server2 software]# tar xzf amoeba-mysql-binary-2.1.0-RC5.tar.gz -C /usr/local/amoeba

配置用户环境变量

在~/.bash_profile文件中指定

    PATH=$PATH:$HOME/bin:/usr/local/amoeba/bin
JAVA_HOME=/usr/java/jdk1.6.0_32
export JAVA_HOME
export PATH

立即生效文件

	source  ~/.bash_profile

配置amoeba

  • /usr/local/amoeba/conf/dbServers.xml

    定义amoeba代理的数据库的链接:主机IP、端口、Amoeba使用的用户名和密码等等
<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">password</property>
-->
</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="testWhileIdle">true</property>
</poolConfig>
</dbServer>
以上内容定义了真实mysql服务器的端口,名称,用户以及密码等
<dbServer name="Master"  parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.0.1</property>
</factoryConfig>
</dbServer>
<dbServer name="Slave1" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.0.2</property>
</factoryConfig>
</dbServer>
<dbServer name="Slave2" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.0.3</property>
</factoryConfig>
</dbServer>
<dbServer name="virtualSlave" virtual="true">
<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">Slave1,Slave2</property>
</poolConfig>
</dbServer>
<dbServer name="Master" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.0.1</property>
</factoryConfig>
</dbServer>
<dbServer name="Slave1" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.0.2</property>
</factoryConfig>
</dbServer>
<dbServer name="Slave2" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.0.3</property>
</factoryConfig>
</dbServer>
<dbServer name="virtualSlave" virtual="true">
<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">Slave1,Slave2</property>
</poolConfig>
</dbServer>
以上内容用于定义主从服务器的链接
  • /usr/local/amoeba/conf/amoeba.xml

定义Amoeba代理的相关配置

<property name="authenticator">
<bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator"> <property name="user">root</property> <property name="password"></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>
定义连接amoeba时用来验证的用户及密码
<property name="defaultPool">Master</property>
<property name="writePool">Master</property>
<property name="readPool">virtualSlave</property>
defaultPool:配置了默认的数据库节点
writePool :配置了数据库写库,通常配为Master,如这里就配置为之前定义的Master数据库。
readPool :配置了数据库读库,通常配为Slave或者Slave组成的数据库池,如这里就配置之前的virtualSlave数据库池。

启动amoeba

启动命令

amoeba start

此命令以前台的方式启动,会输出启动时的信息,检查没有错误信息后,中断,并后台运行

amoeba start &