首页 > 代码库 > amoeba 使用笔记

amoeba 使用笔记

环境

延用MySQL 主主+主从笔记的环境

Java version “1.8.0_73”

安装

wget  http://nchc.dl.sourceforge.net/project/amoeba/Amoeba%20for%20mysql/2.2.x/amoeba-mysql-binary-2.2.0.tar.gz

mkdir /opt/amoeba/
tar -zxvf amoeba-mysql-binary-2.2.0.tar.gz -C /opt/amoeba/ 
cd /opt/amoeba/

配置

./bin/amoeba

The stack size specified is too small, Specify at least 228k
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit
#修改./bin/amoeba的
DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss128k"
为
DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss228k"

修改amoeba.xml配置

vim .conf/amoeba.xml
...
<!--登陆的用户名-->
<property name="authenticator">
                                <bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">

                                        <property name="user">root</property>

                                        <property name="password">123123</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>

 ...
 <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">master1</property>

                <property name="writePool">multWritePool</property>
                <property name="readPool">multReadPool</property>
                <property name="needParse">true</property>
        </queryRouter>
...

修改dbServers.xml 配置

...
<!--连接真实数据库的用户和密码-->
<!-- mysql port -->
                        <property name="port">3306</property>

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

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

                        <property name="password">123123</property>
...
<!--master为读写的mysql,slave1为只读的mysql -->
<dbServer name="master1"  parent="abstractServer">
                <factoryConfig>
                        <!-- mysql ip -->
                        <property name="ipAddress">192.168.42.28</property>
                </factoryConfig>
        </dbServer>
<dbServer name="master2"  parent="abstractServer">
                <factoryConfig>
                        <!-- mysql ip -->
                        <property name="ipAddress">192.168.42.29</property>
                </factoryConfig>
        </dbServer>

        <dbServer name="slave1"  parent="abstractServer">
                <factoryConfig>
                        <!-- mysql ip -->
                        <property name="ipAddress">192.168.42.33</property>
                </factoryConfig>
        </dbServer>
        <!-- 读的Pool -->
        <dbServer name="multReadPool" 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,slave1,master1,master2</property>
                </poolConfig>
                </dbServer>
        <!-- 写的Pool  -->
                 <dbServer name="multWritePool" 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">master1,master2</property>
                </poolConfig>
        </dbServer>
...

启动

./bin/amoeba start

连接

mysql -uroot -p123123 -P 8066 -h0.0.0.0

 

amoeba 使用笔记