welcome to xlongwei.com

欢迎大家一起学习、交流、分享


QQ:9167702333 邮箱:admin@xlongwei.com

amoeba 分布式数据库代理


分类 MySQL   关键字 分享   标签 linux   mysql   发布 hongwei  1432709337502
注意 转载须保留原文链接,译文链接,作者译者等信息。  
amoeba是一款分布式数据库代理软件,它向客户端模拟了数据库访问协议,后端支持数据库主从配置。

# wget http://tool.xlongwei.com/softwares/amoeba-mysql-3.0.5-RC-distribution.zip
# unzip amoeba-mysql-3.0.5-RC-distribution.zip
# mv amoeba-mysql-3.0.5-RC amoeba
# vi amoeba/jvm.properties #-Xss256k 默认值192k运行时有警告
JVM_OPTIONS="-server -Xms256m -Xmx1024m -Xss256k -XX:PermSize=16m -XX:MaxPermSize=96m"

配置访问密码和读写分离(写主库server1,读从库multiPool池)
# vi amoeba/conf/amoeba.xml   #配置访问密码和读写分离(写主库server1,读从库multiPool池)
<property name="authenticateProvider">
<bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">
<property name="user">ite</property>
<property name="password">dbpass</property>
<property name="filter">
<bean class="com.meidusa.toolkit.net.authenticate.server.IPAccessController">
<property name="ipFile">${amoeba.home}/conf/access_list.conf</property>
</bean>
</property>
</bean>
</property>
<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="defaultPool">server1</property>
<property name="writePool">server1</property>
<property name="readPool">multiPool</property>
<property name="needParse">true</property>
</queryRouter>

配置后端数据库及访问密码
# vi amoeba/dbServers.xml
<factoryConfig class="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory">
<property name="connectionManager">${defaultManager}</property>
<property name="sendBufferSize">64</property>
<property name="receiveBufferSize">128</property>

<!-- mysql port -->
<property name="port">3306</property>

<!-- mysql schema -->
<property name="schema">ite</property>

<!-- mysql user -->
<property name="user">ite</property>

<property name="password">dbpass</property>
</factoryConfig>

<dbServer name="server1" parent="abstractServer">
<factoryConfig>
<property name="ipAddress">127.0.0.1</property>
</factoryConfig>
</dbServer>
<dbServer name="server2" parent="abstractServer">
<factoryConfig>
<property name="ipAddress">127.0.0.1</property>
</factoryConfig>
</dbServer>
<dbServer name="multiPool" 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">server1,server2</property>
</poolConfig>
</dbServer>

运行amoeba,测试访问
# sh amoeba/bin/launcher
# mysql -h127.0.0.1 -P8066 -uite -pdbpass -Dite
> show tables;

从库需要配置读权限,可以适当限制主机
grant select on ite.* to ite@'%' identified by 'dbpass';
数据库配置
ds.url=jdbc:mysql://127.0.0.1:8066/ite?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
ds.username=ite
ds.password=dbpass

参考网址:http://docs.hexnova.com/amoeba/ http://sourceforge.net/projects/amoeba/files/