MySQL single-machine multi-instance read-write separation can be achieved through third-party software, one of which is called simple read-write separation software is today brought to everyone's amoeba software.
The amoeba software used for this time is amoeba-mysql-binary-2.1.0-rc5.tar.gz
The software is based on the Java environment, so the need for Java environment support, the specific environment configuration does not do a detailed explanation.
This article mainly explains the two main configuration files.
1, Dbserver.xml
This file is configured with the parent configuration (used to supplement the default child configuration)
Real MySQL server port, database name, MySQL user and password
The primary server, from the server, and from the server connection pool. Only the database addresses are defined here, and their users and passwords are the settings in the abstractserver above.
Note the user that is used to connect to the real MySQL server must have remote connection permissions.
<?xml version= "1.0" encoding= "GBK"?> <! doctype amoeba:dbservers system "DBSERVER.DTD" > <amoeba:dbservers xmlns:amoeba= "http ://amoeba.meidusa.com/"> <!-- each dbserver needs to be configured Into a pool, if you need to configure multiple dbserver with load balancing that can be simplified by the following Configuration: add attribute with name virtual = "true" in Dbserver, but the configuration does not allow the element with name factoryconfig such as ' Multipool ' dbServer -<!-- Default parent configuration, the same entries for all child configurations from this read --> <dbserver name= "Abstractserver" abstractive= "true" > < Factoryconfig class= "Com.meidusa.amoeba.mysql.net.MysqlServerConnectionFActory "> <property name=" manager ">${defaultManager}</property> <property name=" Sendbuffersize ">64</property> <property name=" receivebuffersize ">128</property> <!- IP address of the- mysql ip mysql end --> <property name= "IpAddress" >172.16.1.52</ property> <!-- mysql port mysql Port --> <!--<property name= "Port" > 3306</property>-<!-- mysql schema mysql-end monitoring work library --> <property name= " Schema ">amoeba</property> <!-- mysql user mysql-side library for users --> <property Name= "User" >amoeba</property> <!-- mysql user mysql-side libraries corresponding to users ' passwords --> < Property name= "Password" >123456</property> </factoryConfig> <!-- Default pool parameter configuration, generally do not change --> <poolconfig class= "Com.meidusa.amoeba.net.poolable.PoolableObjectPool" > <property name= "Maxactive">500</property> <property name= "Maxidle" >500</property> <property name= "
Minidle ">10</property> <property name=" Minevictableidletimemillis ">600000</property> <property name= "Timebetweenevictionrunsmillis" >600000</property> <property name= " Testonborrow ">true</property> <property name=" Testwhileidle ">true</property> </ Poolconfig> </dbServer> <!-- Custom configuration pool to set read or write --> <dbserver name= "Server1" parent= "Abstractserver" > <factoryConfig> <!-- mysql ip --> <!--< Property name= "ipAddress" >172.16.1.52</property> <property name= "Port" >3306</ Property> </factoryConfig> </dbServer> <!-- Define a pool as primary (that is, write)-<dbserver name= "
Master " virtual=" true "> <poolconfig class=" Com.meidusa.amoeba.server.MultipleServerPool "> <!--&NBSP;LOAD&Nbsp;balancing strategy: 1=roundrobin , 2=weightbased , 3=ha If more than one master can configure this, 1 for polling, 2 for weight-<property name= "LoadBalance" >1</property> <!-- separated by commas,such as: server1,server2,server1 Specify the pool for the main---<property name= "
Poolnames ">server1</property> </poolConfig> </dbServer> <!-- Same master configuration --> <dbserver name= "Server2" parent= "Abstractserver" > <factoryConfig> <!-- mysql ip --> <!--<property name= "ipAddress" >172.16.1.52</property>--< Property name= "Port" >3307</property> </factoryConfig> </dbServer> <dbServer Name= "Slave" 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" >server2</property> </ Poolconfig> </dbServer> </amoeba:dbServers>
2, Amoeba.xml
The contents of the configuration are as follows:
Define the user and password used to authenticate when connecting amoeba
True read and write separation configuration
Defaultpool: The default database node is configured, and some statements except Select\update\insert\delete are executed in Defaultpool.
Writepool: The database Write library is configured, usually with master, as it is configured as a previously defined master database.
Readpool: A database read library is configured, usually with a database pool of slave or slave, as in this case the Virtualslave database pool before configuration
<?xml version= "1.0" encoding= "GBK"?> <! doctype amoeba:configuration system "AMOEBA.DTD" > <amoeba:configuration xmlns:amoeba= "http://amoeba.meidusa.com/" > <proxy> <!-- service class must implements com.meidusa.amoeba.service.service --> <service name= "Amoeba for mysql" class= " Com.meidusa.amoeba.net.ServerableConnectionManager "> <!-- port amoeba Server-to-web-provided work Port -- > <property name= "Port" >3306</property> <!-- bind ipAddress Amoeba server-to-web work ip --> <property name= "ipAddress" >172.16.1.9</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" > <!-- Amoeba server to Web-side work users --> <property name= "user" >root</property> <!-- Amoeba the password of the working user that the server provides to the Web side --> <property name= "password" >123456</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> </service> <!-- server class must implements com.meidusa.amoeba.service.service --> <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" >127.0.0.1</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> <runtime class=" Com.meidusa.amoeba.mysql.context.MysqlRuntimeContext "> <!-- proxy server net IO read thread size --> <property name= "Readthreadpoolsize" >200</property> <! -- proxy server client process thread size --> <property name= " Clientsidethreadpoolsize ">300</property> <!-- mysql server data packet
Process thread size --><property name= "Serversidethreadpoolsize" >300</property> <!-- per connection cache prepared statement size --> <property name= "Statementcachesize ">500</property> <!-- query timeout ( default: 60 second , Timeunit:second) --> <property name= "QueryTimeout" >60</property> </runtime> </ proxy> <!-- Each connectionmanager will start as thread manager Responsible for the connection io read , death detection-< connectionmanagerlist> <connectionmanager name= "Clientconnectionemanager" class= " Com.meidusa.amoeba.net.MultiConnectionManagerWrapper "> <property name=" Submanagerclassname "> com.meidusa.amoeba.net.connectionmanager</property> <!-- default value is avaliable Processors ≪property name= "Processors" >5</property> --> </connectionManager> < Connectionmanager name= "Defaultmanager" class= "Com.meidusa.amoeba.net.MultiConnectionManagerWrapper" > <property name= "Submanagerclassname" >com.meidusa.amoeba.net.authingableconnectionmanager</ property> <!-- default value is avaliable Processors < Property name= "Processors" >5</property> --> </connectionManager> </ connectionmanagerlist> <!-- default using file loader --> <dbserverloader class= "Com.meidusa.amoeba.context.DBServerConfigFileLoader" > <property name= "configfile" >${ amoeba.home}/conf/dbservers.xml</property> </dbServerLoader> <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> <!-- Specify the specified pool for read and write --> <property name= "Writepool" >server1</ property> <property name= "Readpool" >server2</property> <property name= "Needparse" >true</property> </queryRouter> </amoeba:configuration>
MySQL standalone Multi-instance configuration file content simple comment to this end.
Amoeba Multi-instance profile annotation for MySQL standalone