Mysql Scalability(3)Amoeba - Proxy - Reads and Writes

Mysql Scalability(3)Amoeba - Proxy - Reads and Writes

Oh, seem that the Amoeba is working with version 2.2.0. I will try this version with source codes.

Find the start script file bin/amoeba, find the line which configure the JAVA_OPTS, change it as follow:
DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss256k"

Then we can run 
>bin/amoeba start

One Machine Proxy
Check the configuration files for db connection information
>vi dbServers.xml

<dbServer name="server1"  parent="abstractServer">    
<factoryConfig>
<property name="ipAddress">ubuntu-master</property>
</factoryConfig>
</dbServer>
<!--
<dbServer name="server2"  parent="abstractServer">               
<factoryConfig>
<property name="ipAddress">ubuntu-client1</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</property>
</poolConfig>
</dbServer>

Check the Proxy Connection Configuration
>vi amoeba.xml 

<service 
             name="Amoeba Monitor Server"
             class="com.meidusa.amoeba.monitor.MonitorServer">                        
<!-- port -->                        
<!--  default value: random number                        
       <property name="port">9066</property>                        
-->                        
<!-- bind ipAddress --> 
<property name="ipAddress">0.0.0.0</property>
<property name="daemon">true</property>
<property name="manager">${clientConnectioneManager}</property>                        <property name="connectionFactory">
<bean class="com.meidusa.amoeba.monitor.net.MonitorClientConnectionFactory"></bean>
</property>
</service>

 

After star the amoeba, we can use this proxy to connect to the DB.

>mysql -h ubuntu-master -u root -P 8066 -p


Multiple Machine - Separating Writes and Reads

Grant the Privileges
>use mysql;
>grant all privileges on test.* to root@"%" identified by 'kaishi';
>flush privileges;

Show the SQL
>use mysql
>show variables like "%general_log%";
+------------------+----------------------------------+ | Variable_name    | Value                            | +------------------+----------------------------------+ | general_log      | OFF                              | | general_log_file | /var/lib/mysql/ubuntu-master.log | +------------------+----------------------------------+ 2 rows in set (0.00 sec)
>set global general_log = true;

>sudo tail -f /var/lib/mysql/ubuntu-master.log

Prepare the Configurations
        <dbServer name="master1"  parent="abstractServer"]]>                <factoryConfig>                        <property name="ipAddress"]]>ubuntu-master</property>                </factoryConfig>        </dbServer>         <dbServer name="slave11"  parent="abstractServer"]]>                <factoryConfig>                        <property name="ipAddress"]]>ubuntu-client1</property>                </factoryConfig>        </dbServer>         <dbServer name="slavePool1"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"]]>slave11</property>                </poolConfig>        </dbServer>

        <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"]]>master1</property>                <property name="readPool"]]>slavePool1</property>                <property name="needParse"]]>true</property>        </queryRouter>


Execute these SQLs to Verify
>insert into branduser(id,username,age) values (2, "kiko", 28);
>select * from branduser;

Here is the slave machines
140729 11:14:15  44 Queryselect * from branduser 140729 11:16:13    1 QueryBEGIN                    1 Queryinsert into branduser(id,username,age) values (2, "kiko", 28)                    1 QueryCOMMIT /* implicit, from Xid_log_event */ 140729 11:16:53  44 Queryselect * from branduser

Here is the master machines
140729 11:16:13  43 Queryinsert into branduser(id,username,age) values (2, "kiko", 28)

That works well to separate the reads and writes.

References:
Download the mysql-proxy all versions
https://downloads.skysql.com/archive/index/p/mysql-proxy/v/0.8

http://askubuntu.com/questions/477873/how-do-i-work-around-a-stack-size-specified-is-too-small-error-in-java-on-powe

http://boke.25k5.com/kan16489.html
http://www.cnblogs.com/taven/archive/2012/09/11/2680282.html
http://www.aslibra.com/blog/post/amoeba_mysql_proxy_rw_split.php
https://www.centos.bz/2012/05/amoeba-for-mysql/
http://pengranxiang.iteye.com/blog/1145342

http://sillycat.iteye.com/blog/2070163 mysql logging

你可能感兴趣的:(mysql)