一、环境介绍
Master-IP:10.0.0.201
Slave- IP:10.0.0.202
Amobea-IP:10.0.0.203
二、安装JDK
# mkdir /Amoeba
# tar -xvf jdk-7u40-linux-x64.tar.gz -C /Amoeba/
# vim /etc/profile
JAVA_HOME=/Amoeba/jdk1.7.0_40
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH
export CLASSPATH
# java -version
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
三、安装Amoeba
# unzip amoeba-mysql-1.3.1-BETA.zip -d /usr/local/amoeba/
# chmod -R +x /usr/local/amoeba/bin/
四、主从授权
>grant all privileges on *.* to ‘amobea‘@‘%‘ identified by ‘amoeba123‘;
>flush privileges;
五、配置Amoeba文件
# cd /usr/local/amoeba/conf
# vim amoeba.xml
更改的第一个区域
#========================================================
<!-- proxy server绑定的端口 -->
<property name="port">9006</property>
<!-- proxy server绑定的IP -->
<property name="ipAddress">10.0.0.203</property>
<!-- proxy server net IO Read thread size -->
<property name="readThreadPoolSize">20</property>
<!-- proxy server client process thread size -->
<property name="clientSideThreadPoolSize">30</property>
<!-- mysql server data packet process thread size -->
<property name="serverSideThreadPoolSize">30</property>
<!-- socket Send and receive BufferSize(unit:K) -->
<property name="netBufferSize">128</property>
<!-- Enable/disable TCP_NODELAY (disable/enable Nagle‘s algorithm). -->
<property name="tcpNoDelay">true</property>
<!-- 对外验证的用户名 -->
<property name="user">root</property>
<!-- 对外验证的密码 -->
<property name="password">123456</property>
更改的第二个区域《配置master端登录的信息》
#========================================================
<dbServer name="server1">
<!-- PoolableObjectFactory实现类 -->
<factoryConfig class="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory">
<property name="manager">defaultManager</property>
<!-- 真实mysql数据库端口 -->
<property name="port">3306</property>
<!-- 真实mysql数据库IP -->
<property name="ipAddress">10.0.0.201</property>
<property name="schema">test</property>
<!-- 用于登陆mysql的用户名 -->
<property name="user">amobea</property>
<!-- 用于登陆mysql的密码 -->
<property name="password">amoeba123</property>
</factoryConfig>
<!-- ObjectPool实现类 -->
<poolConfig class="com.meidusa.amoeba.net.poolable.PoolableObjectPool">
<property name="maxActive">200</property>
<property name="maxIdle">200</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>
更改的第三个区域《配置slave端登录的信息》
#========================================================
<dbServer name="server2">
<!-- PoolableObjectFactory实现类 -->
<factoryConfig class="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory">
<property name="manager">defaultManager</property>
<!-- 真实mysql数据库端口 -->
<property name="port">3306</property>
<!-- 真实mysql数据库IP -->
<property name="ipAddress">10.0.0.202</property>
<property name="schema">test</property>
<!-- 用于登陆mysql的用户名 -->
<property name="user">amobea</property>
<!-- 用于登陆mysql的密码 -->
<property name="password">amoeba123</property>
</factoryConfig>
<!-- ObjectPool实现类 -->
<poolConfig class="com.meidusa.amoeba.net.poolable.PoolableObjectPool">
<property name="maxActive">200</property>
<property name="maxIdle">200</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>
更改的第四个区域《配置master和slave负载均衡池(pool)》
#=======================================================
<dbServer name="master" virtual="true">
<poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
<!-- 负载均衡参数 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
<property name="loadbalance">1</property>
<!-- 参与该pool负载均衡的poolName列表以逗号分割 -->
<property name="poolNames">server1</property>
</poolConfig>
</dbServer>
<dbServer name="slave" virtual="true">
<poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
<!-- 负载均衡参数 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
<property name="loadbalance">1</property>
<!-- 参与该pool负载均衡的poolName列表以逗号分割 -->
<property name="poolNames">server1,server2</property>
</poolConfig>
</dbServer>
更改的第五个区域《配置master和slave读写分离》
#=======================================================
<queryRouter class="com.meidusa.amoeba.mysql.parser.MysqlQueryRouter">
<property name="ruleConfig">${amoeba.home}/conf/rule.xml</property>
<property name="functionConfig">${amoeba.home}/conf/functionMap.xml</property>
<property name="ruleFunctionConfig">${amoeba.home}/conf/ruleFunctionMap.xml</property>
<property name="LRUMapSize">1500</property>
<!-- 配置master和slave读写分离 Begin-->
<property name="defaultPool">master</property>
<property name="writePool">master</property>
<property name="readPool">slave</property>
<!-- 配置master和slave读写分离 End-->
<property name="needParse">true</property>
</queryRouter>
六、修改log4j.xml 取消日志文件生成(太大了,磁盘很容易满)
<param name="file" value="${amoeba.home}/logs/project.log"/>
改成
<param name="file" value="<![CDATA[${amoeba.home}/logs/project.log>/dev/null]]>"/>
七、修改Amoeba启动脚本
# vim /usr/local/amoeba/bin/amoeba
#DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss128k" 将此行注释掉,增加一下行
DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss256k" 增加这一行
八、启动Amoeba脚本
# nohup bash -x /usr/local/amoeba/bin/amoeba &
# cat nohup.out 日志是否成功?
# ps -ef | grep amoeba 查看进程是否启动成功
root 1896 1637 1 03:28 pts/3 00:00:06 /Amoeba/jdk1.7.0_40/bin/java -server -Xms256m -Xmx256m -Xss256k -Damoeba.home=/usr/local/amoeba -Dclassworlds.conf=/usr/local/amoeba/bin/amoeba.classworlds -classpath /usr/local/amoeba/lib/classworlds-1.0.jar org.codehaus.classworlds.Launcher
Mysql高级集群-读写分离Amoeba,布布扣,bubuko.com
原文地址:http://8448262.blog.51cto.com/8438262/1408373