amoeba的部署(mysql读写分离,负载均衡)
环境前提:java (负载均衡在主从复制环境下针对从库池,读写分离不需要主从复制,有也需要关掉服务才有测试效果)
amoeba是阿里沿用的mysql中间件,
下载包 amoeba-mysql-3.0.5-RC-distribution.zip
解压到/usr/src/
主要两个配置文件 dbServer.xml 控制代理端和逻辑库池间的关系 amoeba.xml控制amoeba的连接端口和密码
dbServers.xml 多个数据源,多个数据库
amoeba.xml 启动参数,谁负责读,谁负责写,谁负责负载均衡
[[email protected] ~]# vim /usr/src/amoeba/conf/dbServers.xml
<?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:
such as 'multiPool' dbServer
-->
<dbServer name="abstractServer" abstractive="true">
<factoryConfig class="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory">
<property name="connectionManager">${defaultManager}</property>
<property name="sendBufferSize">64</property>
<!--
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:
such as 'multiPool' dbServer
-->
<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 -->
<property name="port">3306</property>
<!-- mysql schema -->
<property name="schema">wkbbs</property>
<!-- mysql user -->
<property name="user">rs</property>
<property name="password">Rs123456.</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>
<?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:
such as 'multiPool' dbServer
-->
<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 -->
<property name="port">3306</property> #端口设置成3306
<!-- mysql schema -->
<property name="schema">wkbbs</property> #连接的实际数据库
<!-- mysql user -->
<property name="user">rs</property> #用户名为rs
<property name="password">Rs123456.</property> #密码是Rs123456.
</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>
<dbServer name="server1" parent="abstractServer"> #库名为server1 ip地址为192.168.3.7 主库 master
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.3.7</property>
</factoryConfig>
</dbServer>
<dbServer name="server2" parent="abstractServer"> #库名为server2 ip地址为192.168.3.8 从库 slave
<factoryConfig>
<!-- mysql ip -->
<property name="ipAddress">192.168.3.8</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">server2</property>
</poolConfig>
</dbServer>
</amoeba:dbServers>
amoeba.xml 的配置如下
[[email protected] ~]# vim /usr/src/amoeba/conf/amoeba.xml
[[email protected] ~]# vim /usr/src/amoeba/conf/amoeba.xml
<?xml version="1.0" encoding="gbk"?>
<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.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.amoeba.mysql.net.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">rs</property> #这里面的用户名和密码是amoeba自己的 和mysql的无关
<property name="password">Rs123456</property>
<property name="filter">
<bean class="com.meidusa.toolkit.net.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 thread
manager responsible for the Connection IO read , Death Detection
-->
<connectionManagerList>
<connectionManager name="defaultManager" class="com.meidusa.toolkit.net.MultiConnectionManagerWrapper">
<property name="subManagerClassName">com.meidusa.toolkit.net.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">server1</property> # 设定默认服务器节点 与dbServer.xml对应
<property name="writePool">server1</property> #可写服务器地址池 与dbServer.xml对应
<property name="readPool">server2</property> #可读服务器地址池 与dbServer.xml对应
<property name="needParse">true</property>
</queryRouter>
</amoeba:configuration>
server1 其实这里的server1 也可以换成一个地址池名
server2 其实这里的server2 也可以换成一个地址池名
最后启动amoeba bin目录下有个 launcher ./launcher
关于报错The stack size specified is too small, Specify at least 228kError: Could not create the Java Virtual Machine.Error: A fatal exception has occurred. Program will exit.
vim /root/amoeba/jvm.properties # 修改
JVM_OPTIONS="-server -Xms256m -Xmx1024m -Xss256k…
此时需要测试读写分离,需要关掉主从复制