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
更改的第一个区域
#========================================================
 
                9006

                
#当前amoeba的IP地址
                10.0.0.203

                
                20

                
                30

                
                30

                
                128

                
                true

                
                root

                
#当前amoeba的登录密码
                123456
                
更改的第二个区域《配置master端登录的信息》
#========================================================             
                

                        
                        
                                defaultManager

                                
                                3306
#Master端的IP地址
                                
                                10.0.0.201
                                test
#用于amoeba登录账户名
                                
                                amobea
#用于amoeba登录密码
                                


                                amoeba123


                        

                        
                        
                                200
                                200
                                10
                                600000
                                600000
                                true
                                true
                        
                
                
更改的第三个区域《配置slave端登录的信息》
#========================================================                  
                


                        
                        
                                defaultManager

                                
                                3306
#用于amoeba对于slave端的IP地址
                                
                                10.0.0.202
                                test
#用于amoeba登录slave端的账户名
                                
                                amoeba

                                

#用于amoeba登录slave端的账户密码
                                amoeba123


                        

                        
                        
                                200
                                200
                                10
                                600000
                                600000
                                true
                                true
                        
                                
               
更改的第四个区域《配置master和slave负载均衡池(pool)》
#=======================================================      
#进行修改为master         
                        
                                
                                1

                                
                                server1
                        
                


#进行修改为slave                
                        
                                
                                1
#设置客户端的pool池顺序以及账户
                                
                                server1,server2
                        
                
             
更改的第五个区域《配置master和slave读写分离》
#=======================================================                 

                ${amoeba.home}/conf/rule.xml
                ${amoeba.home}/conf/functionMap.xml
                ${amoeba.home}/conf/ruleFunctionMap.xml
                1500
#修改读写分离,以下三行!       
                master
                master
                slave
               
                true
        


六、修改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