项目介绍:
Amoeba for Mysql软件,致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当SQL路由功能,专注于分布式数据库代理层(Database Proxy)开发。座落与Client、DB之间,对客户端透明。具有负载均衡、高可用性、SQL过滤、读写分离、可路由相关的到目标数据库、可并发请求多台数据库合并结果。
实验环境:
Master:192.168.0.1
Slave1:192.168.0.2
Slave2:192.168.0.3
Amoeba:192.168.0.4
均在Amoeba机器上操作
安装JDK,Amoeba for mysq是基于JAVA环境开发的,所以系统要支持JAVA
wget http://download.oracle.com/otn/java/jdk/6u45-b06/jdk-6u45-linux-x64-rpm.bin
chmod +x jdk-6u45-linux-x64-rpm.bin
./jdk-6u45-linux-x64-rpm.bin
配置JAVA环境
JKD默认安装到/usr/java/下
创建软链接
ln -s /usr/java/jdk1.6.0_45 /usr/java/jdk
编辑~/.bash_profile,添加以下内容
JAVA_HOME=/usr/java/jdk
export JAVA_HOME
export CLASSPATH=.:JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export PATH
安装Amoeba for mysql
wget http://jaist.dl.sourceforge.net/project/amoeba/Amoeba%20for%20mysql/3.x/amoeba-mysql-3.0.5-RC-distribution.zip
unzip amoeba-mysql-3.0.5-RC-distribution.zip
mv amoeba-mysql-3.0.5-RC /usr/local/amoeba
Amoeba到此就安装完毕,接下来就是配置读写分离,因为Amoeba3.x较2.x有较大改动,所以贴下我的配置项。
首先,设置conf/dbServer.xml中连接的库名及帐号密码
<dbServer name="abstractServer" abstractive="true">
- - - - - 省略 - - - - - -
<!-- mysql port -->
<property name="port">3306</property>
<!-- mysql schema -->
<property name="schema">数据库名</property>
<!-- mysql user -->
<property name="user">账号</property>
<property name="password">密码</property>
- - - - - - - - - 省略 - - - - - - -
</dbServer>
设置数据库池,其中Slave1,Slave2作轮询
<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="VirtualPool" 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>
接下来配置amoeba.xml
<property name="authenticateProvider">
- - - - - - 省略 - - -
<property name="user">账号</property>
<property name="password">密码</property>
<property name="filter">
- - - - - - 省略 - - -
</property>
<queryRouter class="com.meidusa.amoeba.mysql.parser.MysqlQueryRouter">
- - - - - - 省略 - - - - -
<property name="defaultPool">Master</property>
<property name="writePool">Master</property>
<property name="readPool">VirtualPool</property>
- - - - - - 省略 - - - - -
</queryRouter>
读写分离到此配置完成,接着启动amoebe
/usr/local/amoeba2/bin/launcher
在部署Amoeba时,注意下
1:防火墙要开放8066端口
2:给bin目录执行权限:chmod +x bin/*
优化性能:
1:在amoeba目录下有个JVM的配置文件,设置其中的JVM_OPTIONS="-server -Xms1024m -Xmx1024m -Xss256k -XX:PermSize=16m -XX:MaxPermSize=96m"可提升JVM性能,具体大小看各位需求;
2:多线程配置:runtime元素;
3:网络相关(缓冲区等):connectionFactory