本文主要是介绍Amoeba,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.介绍
Amoeba是mysql代理,增强mysql。类似的产品还有MyCat (mysql代理)
2.资源:点击打开链接c82k
3.准备:amoeba是基于java的所以必须有jdk
4.上传amoeba
5.解压tar包
6.配置文件
amoeba配置文件两个
dbServers.xml 多个数据源,多个数据库
amoeba.xml 启动参数,谁负责读,谁负责写,谁负责负载均衡
##################################dbServers.xml-start######################################
<?xml version="1.0"encoding="gbk"?>
<!DOCTYPE amoeba:dbServers SYSTEM"dbserver.dtd">
<amoeba:dbServersxmlns:amoeba="http://amoeba.meidusa.com/">
<!--
EachdbServer needs to be configured into a Pool,
Ifyou need to configure multiple dbServer with load balancing that can besimplified by the following configuration:
add attribute with name virtual ="true" in dbServer, but the configuration does not allow the elementwith name factoryConfig
such as 'multiPool' dbServer
-->
<dbServername="abstractServer" abstractive="true"><--建立抽象server动态代理-->
<factoryConfigclass="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory">
<propertyname="manager">${defaultManager}</property>
<propertyname="sendBufferSize">64</property>
<propertyname="receiveBufferSize">128</property>
<!--mysql port ,所有的主从复制的数据库的用户名和密码都要用一套-->
<propertyname="port">3306</property>
<!--mysql schema默认的要去检查schema,一般是test的数据库默认不变 -->
<propertyname="schema">test</property>
<!--mysql user,用户名默认都是root -->
<propertyname="user">root</property>
<!-- mysql password ,密码是root-->
<propertyname="password">root</property>
</factoryConfig>
<poolConfigclass="com.meidusa.amoeba.net.poolable.PoolableObjectPool">
<propertyname="maxActive">500</property>
<propertyname="maxIdle">500</property>
<propertyname="minIdle">10</property>
<propertyname="minEvictableIdleTimeMillis">600000</property>
<propertyname="timeBetweenEvictionRunsMillis">600000</property>
<propertyname="testOnBorrow">true</property>
<propertyname="testOnReturn">true</property>
<propertyname="testWhileIdle">true</property>
</poolConfig>
</dbServer>
<dbServername="master" parent="abstractServer"><-默认继承了上面的abstractServer,所以是公用一套上面的配置--->
<factoryConfig>
<!--mysql ip 主的ip地址-->
<propertyname="ipAddress">192.168.170.43</property>
</factoryConfig>
</dbServer>
<dbServername="slave" parent="abstractServer">
<factoryConfig>
<!--mysql ip -->
<propertyname="ipAddress">192.168.170.85</property>
</factoryConfig>
</dbServer>
<dbServername="multiPool" virtual="true"><--多个池-->
<poolConfigclass="com.meidusa.amoeba.server.MultipleServerPool">
<!--Load balancing strategy(负载均衡算法): 1=ROUNDROBIN轮询 , 2=WEIGHTBASED权重 , 3=HA高可用-->
<propertyname="loadbalance">1</property>
<!--Separated by commas,such as: server1,server2,server1配置那个数据库是负责读数据的 -->
<propertyname="poolNames">master,slave</property>
</poolConfig>
</dbServer>
</amoeba:dbServers>
##################################dbServers.xml-end######################################
##################################amoeba.xml-end######################################
<?xml version="1.0"encoding="gbk"?>
<!DOCTYPE amoeba:configuration SYSTEM"amoeba.dtd">
<amoeba:configurationxmlns:amoeba="http://amoeba.meidusa.com/">
<proxy>
<!--service class must implements com.meidusa.amoeba.service.Service -->
<servicename="Amoeba for Mysql"class="com.meidusa.amoeba.net.ServerableConnectionManager">
<!--port ,amoeba的端口-->
<propertyname="port">8066</property>
<!--bind ipAddress ,绑定地址,谁可以访问amoeba,如果要让所有的主机都可以访问,就不需要设置-->
<!--
<propertyname="ipAddress">127.0.0.1</property>
-->
<propertyname="manager">${clientConnectioneManager}</property>
<propertyname="connectionFactory">
<beanclass="com.meidusa.amoeba.mysql.net.MysqlClientConnectionFactory">
<propertyname="sendBufferSize">128</property>
<propertyname="receiveBufferSize">64</property>
</bean>
</property>
<propertyname="authenticator">
<beanclass="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">
<propertyname="user">root</property><-访问amoeba的用户名和密码--->
<propertyname="password">root</property>
<propertyname="filter">
<beanclass="com.meidusa.amoeba.server.IPAccessController">
<propertyname="ipFile">${amoeba.home}/conf/access_list.conf</property>
</bean>
</property>
</bean>
</property>
</service>
<!--server class must implements com.meidusa.amoeba.service.Service 阿米巴监控的,不需要监控默认不修改-->
<servicename="Amoeba Monitor Server"class="com.meidusa.amoeba.monitor.MonitorServer">
<!--port -->
<!-- default value: random number
<propertyname="port">9066</property>
-->
<!--bind ipAddress -->
<propertyname="ipAddress">127.0.0.1</property>
<propertyname="daemon">true</property>
<propertyname="manager">${clientConnectioneManager}</property>
<propertyname="connectionFactory">
<beanclass="com.meidusa.amoeba.monitor.net.MonitorClientConnectionFactory"></bean>
</property>
</service>
<runtimeclass="com.meidusa.amoeba.mysql.context.MysqlRuntimeContext">
<!--proxy server net IO Read thread size这些事实时运行的配置,默认不用改 -->
<propertyname="readThreadPoolSize">20</property>
<!--proxy server client process thread size -->
<propertyname="clientSideThreadPoolSize">30</property>
<!--mysql server data packet process thread size -->
<propertyname="serverSideThreadPoolSize">30</property>
<!--per connection cache prepared statement size -->
<propertyname="statementCacheSize">500</property>
<!--query timeout( default: 60 second , TimeUnit:second) -->
<propertyname="queryTimeout">60</property>
</runtime>
</proxy>
<!--
EachConnectionManager will start as thread
managerresponsible for the Connection IO read , Death Detection
-->
<connectionManagerList>
<connectionManagername="clientConnectioneManager" class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper">
<propertyname="subManagerClassName">com.meidusa.amoeba.net.ConnectionManager</property>
<!--
default value is avaliable Processors
<propertyname="processors">5</property>
-->
</connectionManager>
<connectionManagername="defaultManager"class="com.meidusa.amoeba.net.MultiConnectionManagerWrapper">
<propertyname="subManagerClassName">com.meidusa.amoeba.net.AuthingableConnectionManager</property>
<!--
default value is avaliable Processors
<propertyname="processors">5</property>
-->
</connectionManager>
</connectionManagerList>
<!--default using file loader 指定刚刚配置过的dbServer.xml文件,将配置文件读入-->
<dbServerLoaderclass="com.meidusa.amoeba.context.DBServerConfigFileLoader">
<propertyname="configFile">${amoeba.home}/conf/dbServers.xml</property>
</dbServerLoader>
<queryRouterclass="com.meidusa.amoeba.mysql.parser.MysqlQueryRouter">
<propertyname="ruleLoader">
<beanclass="com.meidusa.amoeba.route.TableRuleFileLoader">
<propertyname="ruleFile">${amoeba.home}/conf/rule.xml</property>
<propertyname="functionFile">${amoeba.home}/conf/ruleFunctionMap.xml</property>
</bean>
</property>
<propertyname="sqlFunctionFile">${amoeba.home}/conf/functionMap.xml</property>
<propertyname="LRUMapSize">1500</property>
<propertyname="defaultPool">master</property><--默认池只有master能写,所以要配主-->
<propertyname="writePool">master</property><--master能写,所以要配主-->
<propertyname="readPool">multiPool</property><--dbServer.xml中配置过能写的数据库,把他的属性写过来-->
<propertyname="needParse">true</property>
</queryRouter>
</amoeba:configuration>
##################################amoeba.xml-end######################################
7. 打开8066端口
/sbin/iptables -I INPUT -p tcp --dport 8066 -j ACCEPT
/etc/rc.d/init.d/iptables save #修改生效
/etc/init.d/iptables status #查看配置
8.启动和关闭amoeba
启动:./bin/amoeba start 或 ./bin/amoeba start &
关闭:
./bin/amoeba stop
9.启动报错
是因为jdk默认(128k)的栈太小了,而根据上述报错,栈需要228k才行
默认配置Xss比较小128k,启动时提示太小,则修改/amoeba/bin/amoeba文件,修改为256k即可。
DEFAULT_OPTS="-server -Xms256m-Xmx256m -Xss256k"
再次启动,ok
检查是否启动成功
10.使用第三方软件链接amoeba
使用主从复制的bug来检查是链接到了主还是从,将主数据库和从数据库中各添加一条独特的数据
11.如果链接上amoeba后发现查不出数据
根据状态可知主从配置失败了,需要从新配置
从错误可知,主键重了,重新配置
1)将从停了
2)到主上查看位置pos
重新执行挂接命令
启动从服务
验证
然后根据那个bug来看,经过amoeba链接的是从还是主
上图链接的是主
修改的话修改的是主数据库
这篇关于Amoeba的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!