首页 > 数据库技术 > 详细

mysql基于amoeba配置读写分离

时间:2014-08-09 02:45:47      阅读:417      评论:0      收藏:0      [点我收藏+]
                     Mysql高级集群-读写分离Amoeba
                     
   mysql在配置好主从复制之后,已经达到双机热备和容灾的效果。此博客是建立在主从复制的前提上
,mysql基于amoeba的配置读写分离在我看来:就是为了达到数据库高可用性,安全性以及高并发,达到
负载均衡的效果。说简单点,我个人觉得意思就是让主服务器轻松点,不易挂掉。还有就是充分利用从服务器。 

本人水平有限,望各位大神多多指点指点。我非常乐意听取意见。
此版本建立在rhel6.4 x86_64 以及mysql 5.1.50 上,‘#’为需要修改的地方!
读写      数据同步               
Master-->Slave
                                                                    
一、环境介绍
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 ‘amoeba‘@‘%‘ identified by ‘amoeba123‘;
>flush privileges;


五、配置Amoeba文件
# cd /usr/local/amoeba/conf
# vim amoeba.xml
更改的第一个区域
#========================================================
 <!-- proxy server绑定的端口 -->
                <property name="port">9006</property>

                <!-- proxy server绑定的IP -->
#当前amoeba的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>

                <!-- 对外验证的密码 -->
#当前amoeba的登录密码
                <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>
#Master端的IP地址
                                <!-- 真实mysql数据库IP -->
                                <property name="ipAddress">10.0.0.201</property>
                                <property name="schema">test</property>
#用于amoeba登录账户名
                                <!-- 用于登陆mysql的用户名 -->
                                <property name="user">amobea</property>
#用于amoeba登录密码
                                <!-- 用于登陆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>
#用于amoeba对于slave端的IP地址
                                <!-- 真实mysql数据库IP -->
                                <property name="ipAddress">10.0.0.202</property>
                                <property name="schema">test</property>
#用于amoeba登录slave端的账户名
                                <!-- 用于登陆mysql的用户名 -->
                                <property name="user">amoeba</property>

                                <!-- 用于登陆mysql的密码 -->

#用于amoeba登录slave端的账户密码
                                <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)》
#=======================================================      
#进行修改为master         <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>


#进行修改为slave                <dbServer name="slave" virtual="true">
                        <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
                                <!-- 负载均衡参数 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
                                <property name="loadbalance">1</property>
#设置客户端的pool池顺序以及账户
                                <!-- 参与该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>


六、修改Amoeba启动脚本
# vim /usr/local/amoeba/bin/amoeba
#DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss128k" 将此行注释掉,增加一下行
DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss256k"  增加这一行

七、启动Amoeba脚本
# nohup bash -x 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 -uroot -p123456 -h 10.0.0.203 -P 9006


mysql基于amoeba配置读写分离,布布扣,bubuko.com

mysql基于amoeba配置读写分离

原文:http://6555709.blog.51cto.com/6545709/1537594

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!