MySQL middleware amoeba for MySQL read-write separation

Source: Internet
Author: User

Amoeba is a proxy that uses MySQL as the underlying data store and provides the MySQL protocol interface accordingly. It responds centrally to the application's requests, based on the rules set by the user beforehand. Sends a SQL request to a specific database to run. This allows for load balancing, read-write separation, and high availability. Compared to MySQL's official MySQL proxy, the author emphasizes the convenience of the amoeba configuration (XML-based configuration file, which uses the SQLJEP syntax to write rules that are simpler than the Lua script-based MySQL proxy). This article is to implement a simple amoeba configuration

Lab Environment:
192.168.1.121 for Amoebaserver, provides read/write separation
192.168.1.141 is the primary server for MySQL
192.168.1.142 for MySQL from the server

1. Providing configuration for MySQL master server
Edit/ETC/MY.CNF, which provides the following configuration
Log_bin=index
Server_id=1
Authorizing on the primary server
Mysql> Grant replication Slave,replication client on [e-mail protected] ' 192.168.1.142 ' identified by "123456";
mysql> flush Privileges;
2. Provision configuration for MySQL from the service
Edit/ETC/MY.CNF, which provides the following configuration
server_id=10
Relay_log=relay
Go to MySQL command line interface
MySQL > Change master toMaster_host= "192.168.1.141", master_user= "USER", master_password= "123456", master_log_file= "index.000004", Master_ log_pos=429;
mysql > Start slave;
Assuming you can see the Slave_io_running:yes and Slave_sql_running:yes two lines of information, it proves that the master-slave configuration has succeeded.
3. Install the amoeba on the 192.168.1.121
Amoeba is developed in Java. So we need to install the JDK first.
[Email protected] ~]# chmod +x jdk-6u43-linux-x64.bin
[Email protected] ~]#./jdk-6u43-linux-x64.bin
# vi/etc/profile.d/java.sh
Export Java_home=/root/jdk1.6.0_43/bin
Export path= $JAVA _home/bin: $PATH
# source/etc/profile.d/java.sh
Installing Amoeba
# wget Http://sourceforge.net/projects/amoeba/files/Amoeba%20for%20mysql/2.2.x/amoeba-mysql-binary-2.2.0.tar.gz/download
# Mkdir/usr/local/amoeba
# Tar XF amoeba-mysql-binary-2.2.0.tar.gz-c/usr/local/amoeba

Go to the Amoeba folder and you'll see a few folders.
Bechmark: Pressure test
Bin: Script File
Conf: Configuration file
LIB: library

There are many configuration files under the Conf file. Here to achieve the effect of read and write separation, only need two files can be amoeba.xml and dbserver.xml. The configuration that needs to be changed under the Amoeba.xml file is:

<service name= "Amoeba for Mysql" class= "Com.meidusa.amoeba.net.ServerableConnectionManager" >
<!--Port--
<property name= "Port" >3306</property> #连接amoeba时所使用的端口号

<!--bind IpAddress--
<!--
<property name= "IpAddress" >127.0.0.1</property> #
-
<property name= "ipAddress" >0.0.0.0</property> #监听地址
<property name= "Manager" >${clientConnectioneManager}</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= "Authenticator" >
<bean class= "Com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator" >

<property name= "User" >root</property> #连接amoeba时候的账户

<property name= "Password" >amoeba</property> #连接amoeba时候的密码

<property name= "Filter" >
<bean class= "Com.meidusa.amoeba.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" >server1</property>--> #不须要默认路由
<property name= "Writepool" >test1</property> #写路由到test1上去
<property name= "Readpool" >test2</property> #读路由到test2上去

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

The configuration that needs to be changed in the Dbserver.xml file is:
<factoryconfig class= "Com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory" >
<property name= "Manager" >${defaultManager}</property>
<property name= "Sendbuffersize" >64</property>
<property name= "Receivebuffersize" >128</property>

<!--MySQL Port--
<property name= "Port" >3306</property> #后端mysql的端口
<!--MySQL Schema--
<property name= "schema" >amoeba</property> #后端mysql的默认连接数据库
<!--mysql User--
<property name= "User" >root</property> #连接后端mysql的账户
<!--mysql Password
<property name= "Password" >password</property>
-
<property name= "Password" >amoebapass</property> #连接后端mysql使用的密码
</factoryConfig>

<dbserver name= "test1" parent= "Abstractserver" >
<factoryConfig>
<!--mysql IP--
<property name= "ipAddress" >192.168.1.141</property> #后端MySQL的ip
</factoryConfig>
</dbServer>

<dbserver name= "test2" parent= "Abstractserver" >
<factoryConfig>
<!--mysql IP--
<property name= "IpAddress" >192.168.1.142</property>
</factoryConfig>
</dbServer>

On the backend agent MySQL to amoeba authorization, run on 192.168.1.141 such as the following operations:
Grant all on * * to ' root ' @ ' 192.168.1.121 ' identified by ' Amoebapass ';(do not run in the standby, and will actively synchronize the past)
All the things are ready to start amoeba, run:/usr/local/amoeba/bin/amoeba You may encounter the following error:
The stack size specified is too small, and specify at least 160k Could isn't create the Java virtual machine.

Change the amoeba file, Vi/usr/local/amoeba/bin/amoeba, to find files such as the following:
Default_opts= "-server-xms256m-xmx256m-xss128k"
Change it to:
Default_opts= "-server-xms256m-xmx256m-xss256k

Run/usr/local/amoeba/bin/amoeba again. Assuming amoeba start|stop, you can start amoeba.
#/usr/local/amoeba/bin/amoeba Start
After successful startup, install a MySQL client on the server where amoeba is installed to test
# yum Install MySQL
# mysql-uroot-pamoeba-h192.168.1.121
Suppose the connection succeeds. and the creation of a successful statement can be displayed on the backend agent MySQL, proving that the amoeba configuration is successful. Of course it is assumed that the complete master-slave separation has been achieved. Able to capture the package analysis to see.

MySQL middleware amoeba for MySQL read-write separation

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.