Amoeba实现读写分离

一、Amoeba工作原理

二、Amoeba安装及配置详解

    下载:

    wget 
http://iweb.dl.sourceforge.net/project/amoeba/Amoeba%20for%20mysql/3.x/amoeba-mysql-3.0.5-RC-distribution.zip



解压后可直接使用

本人主要测试读写分离

配置文件

amoeba.xml关键点配置:

<service name="Amoeba for Mysql" class="com.meidusa.amoeba.mysql.server.MySQLService">
                        <!-- port -->
                        <!--定义amoeba的端口号,默认8066-->
                        <property name="port">8066</property>

                        <!-- bind ipAddress -->
                        <!--定义amoeba的监听IP-->
                        <property name="ipAddress">192.168.0.3</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">root</property>
                                        <!--定义连接服务的密码-->
                                        <property name="password">123</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>

此段配置的是连接到amoeba的账号和密码,账号密码是自行设置


wKioL1Y8SdqwpFHeAADW3cmN-yQ927.jpg

此段设置的是读写分离的mysql服务器,server1,server2,mutipool等在dbServer.xml内设置

说明:此处defaultPool设定的mysql服务器是除/select/update/delete/insert以外的操作都会在此mysql执行,所以一般定义为master

writePool定义的是写数据库

readPool定义的是读数据库,如果要使用多台数据库进行读操作,可参考dbServer.xml的multiPool定义


dbServer.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 -->
                        <!-- 配置ameoaba连接mysql主从服务器的端口 -->
                        <property name="port">3306</property>

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

                        <!-- mysql user -->
                        <!-- 配置ameoaba连接mysql主从服务器的账号,需在主从服务器建立 -->
                        <property name="user">xtrabackup</property>
                        <!-- 配置ameoaba连接mysql主从服务器的密码 -->
                        <property name="password">test123</property>
                </factoryConfig>

                <poolConfig class="com.meidusa.toolkit.common.poolable.PoolableObjectPool">
                        <property name="maxActive">500</property>
                        <property name="maxIdle">500</property>
                        <property name="minIdle">1</property>
                        <property name="minEvictableIdleTimeMillis">600000</property>
                        <property name="timeBetweenEvictionRunsMillis">600000</property>
                        <property name="testOnBorrow">true</property>
                        <property name="testOnReturn">true</property>
                        <property name="testWhileIdle">true</property>
                </poolConfig>
        </dbServer>
        <!--定义主从服务器表示 ,parent表示使用上面定义的账号进行连接-->
        <dbServer name="server1"  parent="abstractServer">
                <factoryConfig>
                        <!-- mysql ip -->
                        <!--定义服务器IP-->
                        <property name="ipAddress">192.168.0.1</property>
                </factoryConfig>
        </dbServer>

        <dbServer name="server2"  parent="abstractServer">
                <factoryConfig>
                        <!-- mysql ip -->
                        <property name="ipAddress">192.168.0.2</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 -->
                        <!-- 定义多台server池-->
                        <property name="poolNames">server1,server2</property>
                </poolConfig>
        </dbServer>


启动服务

./bin/launcher &


注意点:

    1.需安装java

    2.需在主从服务器上建立可以让amoeba服务器进行远程连接的账号


三、测试

连接amoeba

mysql -uxtrabackup -ptest123 -P8066 -h 127.0.0.1

测试方式同mysql-proxy读写分离的测试方式


关闭主从服务器负载在一台添加新数据,进行查询测试

相关文章
相关标签/搜索