700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 使用Amoeba实现MySQL读写分离详细步骤(推荐的方式)

使用Amoeba实现MySQL读写分离详细步骤(推荐的方式)

时间:2019-01-29 07:04:59

相关推荐

使用Amoeba实现MySQL读写分离详细步骤(推荐的方式)

什么是Amoeba

为什么使用Amoeba

安装Amoeba

①安装jdk并配置环境变量

vi /etc/profile

source /etc/profile 使配置生效

上传Amoeba安装文件: 如果没有安装zip/unzip软件先yum install一下

修改配置文件:

vi dbServers.xml

输入d + G清空配置文件中的内容, 重新进行配置

dbServer.xml配置内容:

<?xml version="1.0" encoding="gbk"?><!DOCTYPE amoeba:dbServers SYSTEM "dbserver.dtd"><amoeba:dbServers xmlns:amoeba="/"><!-- 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 --><dbServer name="abstractServer" abstractive="true"><factoryConfig class="com.meidusa..MysqlServerConnectionFactory"><property name="connectionManager">${defaultManager}</property><property name="sendBufferSize">64</property><property name="receiveBufferSize">128</property><!-- mysql port --><property name="port">3306</property><!-- mysql schema --><property name="schema">msb</property><!-- mysql user --><property name="user">root</property><property name="password">123456</property></factoryConfig><poolConfig class="com.mon.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><dbServer name="writedb" parent="abstractServer"><factoryConfig><!-- mysql ip --><property name="ipAddress">192.168.85.11</property></factoryConfig></dbServer><dbServer name="slave" parent="abstractServer"><factoryConfig><!-- mysql ip --><property name="ipAddress">192.168.85.12</property></factoryConfig></dbServer><dbServer name="myslave" 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">slave</property></poolConfig></dbServer></amoeba:dbServers>

amoeba.xml配置内容:

<?xml version="1.0" encoding="gbk"?><!DOCTYPE amoeba:configuration SYSTEM "amoeba.dtd"><amoeba:configuration xmlns:amoeba="/"><proxy><!-- service class must implements com.meidusa.amoeba.service.Service --><service name="Amoeba for Mysql" class="com.meidusa.amoeba.mysql.server.MySQLService"><!-- port --><property name="port">8066</property><!-- bind ipAddress --><!-- <property name="ipAddress">127.0.0.1</property>--><property name="connectionFactory"><bean class="com.meidusa..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">123456</property><property name="filter"><bean class="com..authenticate.server.IPAccessController"><property name="ipFile">${amoeba.home}/conf/access_list.conf</property></bean></property></bean></property></service><runtime class="com.meidusa.amoeba.mysql.context.MysqlRuntimeContext"><!-- proxy server client process thread size --><property name="executeThreadSize">128</property><!-- per connection cache prepared statement size --><property name="statementCacheSize">500</property><!-- default charset --><property name="serverCharset">utf8</property><!-- query timeout( default: 60 second , TimeUnit:second) --><property name="queryTimeout">60</property></runtime></proxy><!-- Each ConnectionManager will start as threadmanager responsible for the Connection IO read , Death Detection--><connectionManagerList><connectionManager name="defaultManager" class="com..MultiConnectionManagerWrapper"><property name="subManagerClassName">com..AuthingableConnectionManager</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">writedb</property><property name="writePool">writedb</property><property name="readPool">myslave</property><property name="needParse">true</property></queryRouter></amoeba:configuration>

启动amoeba

如果出现栈内存配置不够的错误提示, 需要改下配置文件, 进入amoeba文件夹, vi jvm.properties

./launcher启动amoeba:

登录:

测试amoeba

将写库所在的节点停掉:

再进行insert的操作,会报错:

同样地,如果将读库所在的节点停掉, 也会报错:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。