1、因为amoeba使用Java写的,所以要在服务器上安装JAVA,这里JAVA安装忽略,说一下JAVA环境变量的设置:
Vim /etc/profile
在底部增加以下代码:
export JAVA_HOME=/usr/java/jdk1.7.0_67
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOMR/bin
环境变量即时生效:
source /etc/profile
2、Amoeba-mysql 版本下载: http://nchc.dl.sourceforge.net/project/amoeba/Amoeba%20for%20mysql/3.x/amoeba-mysql-3.0.5-RC-distribution.zip
3、安装Amoeba-mysql,直接把下载的源码包解压到amoeba文件夹
unzip amoeba-mysql-3.0.5-RC-distribution.zip -d /usr/local/
mv amoeba-mysql-3.0.5-RC amoeba
4、配置Amoeba-mysql
配置dbServers.xml
<dbServer name="abstractServer" abstractive="true">
<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">数据库名</property>
<!-- mysql user -->
<property name="user">数据库用户名</property>
<property name="password">数据库密码</property>
</factoryConfig>
<dbServer name="master" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.1.5</property>
</factoryConfig>
</dbServer>
<dbServer name="slave1" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.1.6</property>
</factoryConfig>
</dbServer>
<dbServer name="slave2" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.1.7</property>
</factoryConfig>
</dbServer>
<dbServer name="slave3" parent="abstractServer">
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.1.8</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">2</property>
<!-- Separated by commas,such as: server1,server2,server1 -->
<property name="poolNames">slave1,slave2,slave3</property>
</poolConfig>
</dbServer>
配置amoeba.xml主配置文件
<service name="Amoeba for Mysql" class="com.meidusa.amoeba.mysql.server.MySQLService">
<!-- port -->
<property name="port">8066</property>
<!-- bind ipAddress -->
<!-- <property name="ipAddress">127.0.0.1</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="authenticateProvider">
<bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">
<property name="user">连接amoeba的账号</property>
<property name="password">连接amoeba的密码</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>
</service>
<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">master</property>
<property name="writePool">master</property>
<property name="readPool">multiPool</property>
<property name="needParse">true</property>
</queryRouter>
5、启动amoeba
./launcher
发现错误
The stack size specified is too small, Specify at least 228k
在amoeba程序的根目录里有一个jvm.properties 优化设置
JVM_OPTIONS="-server -Xms256m -Xmx1024m -Xss196k -XX:PermSize=16m -XX:MaxPermSize=96m"
改为
JVM_OPTIONS="-server -Xms256m -Xmx1024m -Xss300k -XX:PermSize=16m -XX:MaxPermSize=96m"
只要大于上面提示的228K就可以了
然后重新运行:
./launcher
6、登录amoeba测试(这里用到之前配置文件 amoeba.xml 里面设置的账号密码)
mysql -u账号 -p密码 -h192.168.1.5 -P8066