Amoeba for MySQL read-write separation configuration

Source: Internet
Author: User

First, installation and operation of Amoeba

1. Amoeba for MySQL Architecture:


2. Verifying the installation of Java
The amoeba framework was developed based on Java SE1.5, and it is recommended that you use Java SE1.5 above.
# java-version
Java Version "1.6.0_35"
Java (TM) SE Runtime Environment (build 1.6.0_35-B10)
Java HotSpot (TM) 64-bit Server VM (build 20.10-b01, Mixed mode)
Note: JDK installation method no longer elaborated, will not be able to refer to: http://www.minunix.com/2013/05/install_tomcat/Installation JDK section.
3. Install MySQL database and configure the master-slave copy section here no longer elaborated, can not be consulted: http://www.minunix.com/2013/05/mysql-slave/.
4. Download Amoeba
This example uses version: Amoeba-mysql-3.0.5-rc-distribution.zip
: Http://pan.baidu.com/s/1fkno
5. Installing Amoeba
After you have unpacked the downloaded compressed package, put it in the/usr/local/directory.
# Mkdir/usr/local/amoeba
# Unzip Amoeba-mysql-3.0.5-rc-distribution.zip
#/BIN/CP–RF amoeba-mysql-3.0.5-rc/*/usr/local/amoeba

Second, configure Amoeba for MySQL:
Amoeba for MySQL is very simple to use, mainly through the XML file to achieve.
1. Description of the configuration file:
(1.) Dbservers.xml Imagine Amoeba as a database agent layer, it must be in communication with many databases, so it has to know how it proxies the database to connect, such as the most basic: Host IP, port, amoeba user name and password used and so on. This information is stored in the $amoeba_home/conf/dbservers.xml.
(2.) Rule.xml Amoeba provides a complete segmentation rule configuration for Data segmentation, and it must know the segmentation rules in order to understand how to shard the data and how to consolidate the data returned by the database. The information related to the Shard rule is stored in the $amoeba_home/conf/rule.xml.
(3.) Functionmap.xml when we write SQL to manipulate the database, we often use many different database functions, such as Unix_timestamp (), Sysdate (), and so on. How are these functions parsed by amoeba? $AMOEBA _home/conf/functionmap.xml describes the relationship between function names and functional processing.
(4.) rulefunctionmap.xml the configuration of $amoeba_home/conf/rule.xml, we use some of our own defined functions, such as we need to hash the user ID value to slice the data, these functions in the $amoeba_ Defined in Home/conf/rulefunctionmap.xml.
(5.) access_list.conf Amoeba can develop some host IP addresses that can be accessed and denied access, which is configured in $amoeba_home/conf/access_list.conf.
(6.) Log4j.xml Amoeba allows the user to configure the output log level and mode, the configuration method uses the log4j file format, the file is $amoeba_home/conf/log4j.xml.
Among them, we mainly use Dbserver.xml and amoeba.xml.
2. Configuration of 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--><!-The port number used by the proxy connection database--
<property name= "Port" >3306</property>

<!-mysql schema--><!-The database used by the proxy connection database--
<property name= "schema" >test</property>

<!-mysql user--><!-Proxy connection database used by username--
<property name= "User" >minunix</property>
<!-Proxy Connection database using the password--
<property name= "Password" >minunix.com</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>

<!---Configure the address of the real database---
<!---Configure master-slave server and server connection pool--
<dbserver name= "Server1" parent= "Abstractserver" >

<factoryConfig>

<!--mysql IP--

<property name= "IpAddress" >192.168.0.162</property>

</factoryConfig>

</dbServer>

<dbserver name= "Server2" parent= "Abstractserver" >

<factoryConfig>

<!-mysql IP--

<property name= "IpAddress" >192.168.0.171</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>

3. Amoeba.xml Configuration:
The IP address, port, user name, and password that are bound when the client connects to amoeba. and IP access restrictions.

<service name= "Amoeba for Mysql" >
<!--Port--

<property name= "Port" >8066</property>



<!--bind IpAddress--

<!--

<property name= "IpAddress" >127.0.0.1</property>

-



<property name= "ConnectionFactory" >

<bean >

<property name= "Sendbuffersize" >128</property>

<property name= "Receivebuffersize" >64</property>

</bean>

</property>



<property name= "Authenticateprovider" >

<bean >

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

<property name= "Password" >minunix</property>



<property name= "Filter" >

<bean>

<property name= "Ipfile" >${amoeba.home}/conf/access_list.conf</property>

</bean>

</property>

</bean>

</property>



</service>

The following is a definition of read-write separation:

<queryrouter >
<property name= "Ruleloader" >

<bean >

<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" >multiPool</property>



<property name= "Writepool" >server1</property>

<property name= "Readpool" >server2</property>



<property name= "Needparse" >true</property>

</queryRouter>

Through the above simple configuration, the database can already be read and written separated.

Third, testing
# cd/usr/local/bin/
#./launcher \ \ (can also be started by nohup background or by writing a script yourself.) )
The amoeba default port for startup is 8066
Connect the amoeba test on the client:
# mysql-uroot–pminunix-h192.168.0.161--port 8066
mysql> show databases;
mysql> CREATE DATABASE Minunix; \ \ Create the database, and then view it separately in the master and slave libraries
Through amoeba login, data query and insert Update operations, and view the Mysql-log log, you can find that the INSERT, UPDATE, delete and other operations on the main library Server1 operation, select query statement is executed from the library Server2.

Amoeba for MySQL read-write separation configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.