环境:

  1. 一台CentOS6.5-x64最小化安装(ip:10.0.0.226)

    软件:jdk-8u60-linux-x64.rpm, amoeba-mysql-binary-2.2.0.tar.gz

    下载地址:链接: http://pan.baidu.com/s/1c04Wmys 密码: 4tqe

2.一台CentOS6.5-x64最小化安装(ip:10.0.0.222)

    为了节省资源,本次使用的是mysql多实例。3306为主(master),3307为从(slave).

    主从同步这里就不在说明了,创建好主从同步后要先停止从库同步。进入mysql后slave stop;

3.测试机(ip:10.0.0.111)

    测试机应事先有装过mysql,不然登陆的amoeba服务器的时候会出现-bash: mysql: command not found.(如果不是这样的,还希望大侠能留下相关办法。谢谢!)

    3306主库(master)创建用户,这个用户是用来给amoeba写数据时候使用。语句如下:

    mysql> GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'amoeba'@'10.0.0.%' IDENTIFIED BY '123456';

    3307从库(slave)创建用户,这个用户是用来给amoeba查询数据时候使用。语句如下:

    mysql> GRANT SELECT ON *.* TO 'amoeba'@'10.0.0.%' IDENTIFIED BY '123456';


Amoeba安装和配置

    安装:

        [root@amoeba ~]# rpm -ivh jdk-8u60-linux-x64.rpm

        [root@amoeba ~]# ln -s /usr/java/jdk1.8.0_60/ /usr/java/jdk1.8   #做个软连接,方便后面操作

        [root@amoeba ~]# vi /etc/profile

        在最后面添加以下两行:

        

        export JAVA_HOME=/usr/java/jdk1.8

        export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

        [root@amoeba ~]# source /etc/profile    #使刚加入的两行生效

        [root@amoeba ~]# mkdir -p /usr/local/amoeba

        [root@amoeba ~]# cd /usr/local/amoeba

        [root@amoeba amoeba]# tar xf amoeba-mysql-binary-2.2.0.tar.gz

        [root@amoeba amoeba]# rm amoeba-mysql-binary-2.2.0.tar.gz

        [root@amoeba amoeba]# chmod 700 -R bin/

    配置:

    2.2.0和1.3.1有些不一样

    1.3.1是只要修改/usr/local/amoeba/conf/amoeba.xml这个配置文件就可以的

    2.2.0是把/usr/local/amoeba/conf/amoeba.xml这个配置文件分开了,一个是amoeba.xml,另一个是dbServers.xml

    下面贴出配置,尽供参考:

dbServers.xml

[root@amoeba conf]# cat dbServers.xml 



               


        abstractServer1" abstractive="true">

               

                        ${defaultManager}

                        64

                        128


                       

                        3306


                       

                        test


                       

                        amoeba


                       

                        123456


               


               

                        500

                        500

                        10

                        600000

                        600000

                        true

                        true

                        true

               

       

        abstractServer2" abstractive="true">

               

                        ${defaultManager}

                        64

                        128


                       

                        3307


                       

                        test


                       

                        amoeba


                       

                        123456


               


               

                        500

                        500

                        10

                        600000

                        600000

                        true

                        true

                        true

               

       

        server1"  parent="abstractServer1">

               

                       

                        10.0.0.222

               

       


        server2"  parent="abstractServer2">

               

                       

                        10.0.0.222

               

       


        master" virtual="true">

               

                       

                        1


                       

                        server1

               

       

        slave" virtual="true">

               

                       

                        1


                       

                        server2

               

       


 amoeba.xml  

[root@amoeba conf]# cat amoeba.xml 



       

        

               

               

                       

                        8066

                        

                       

                       

                        10.0.0.226

                        

                        

                        ${clientConnectioneManager}

                        

                       

                               

                                        128

                                        64

                               

                       

                        

                       

                               

                                        

                                        root

                                        

                                        123456

                                        

                                       

                                               

                                                        ${amoeba.home}/conf/access_list.conf

                                               

                                       

                               

                       

                        

               

                

               

               

                       

                       

                       

                        127.0.0.1

                        true

                        ${clientConnectioneManager}

                       

                               

                       

                        

               

                

               

                       

                        20

                        

                       

                        30

                        

                       

                        30

                        

                       

                        500

                        

                       

                        60

               

                

       

        

       

       

               

                        com.meidusa.amoeba.net.ConnectionManager

                       

               

               

                        com.meidusa.amoeba.net.AuthingableConnectionManager

                        

                       

               

       

        

               

       

                ${amoeba.home}/conf/dbServers.xml

       

        

       

               

                       

                                ${amoeba.home}/conf/rule.xml

                                ${amoeba.home}/conf/ruleFunctionMap.xml

                       

               

                ${amoeba.home}/conf/functionMap.xml

                1500

                master

                

               

                master

                slave

                

                true

       


    启动:

    

[root@amoeba bin]# ./amoeba start

log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml

2015-10-20 21:12:18,932 INFO  context.MysqlRuntimeContext - Amoeba for Mysql current versoin=5.1.45-mysql-amoeba-proxy-2.2.0

log4j:WARN ip access config load completed from file:/usr/local/amoeba/conf/access_list.conf

2015-10-20 21:12:19,593 INFO  net.ServerableConnectionManager - Amoeba for Mysql listening on /10.0.0.226:8066.

2015-10-20 21:12:19,608 INFO  net.ServerableConnectionManager - Amoeba Monitor Server listening on /10.0.0.226:17877.



[root@amoeba bin]# netstat -lntp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      932/sshd            

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1008/master         

tcp        0      0 ::ffff:10.0.0.226:17877     :::*                        LISTEN      1673/java           

tcp        0      0 :::22                       :::*                        LISTEN      932/sshd            

tcp        0      0 ::1:25                      :::*                        LISTEN      1008/master         

tcp        0      0 ::ffff:10.0.0.226:8066      :::*                        LISTEN      1673/java      

看到以上相关数据,说明已经起动成功。

===========================================================================================

    验证:

    为了能明显看出效果,这里先暂停主从同步。使用命令slave stop结束。

    先进入主库3306[master],查看测试数据库tudou的test表,内容如下

    

        mysql> select * from test;

        +--------+

        | name   |

        +--------+

        | shanqi |

        | shanqi |

        +--------+

     再进入从库3307[slave],查看测试数据库tudou的test表,内容如下

    

        mysql> select * from test;

         +--------+

         | name   |

         +--------+

         | shanqi |

         | shanqi |

         | green  |

         +--------+

        
    这里已事先在从库插入一条主库没有的记录,方便接下来的测试。

    使用一台测试机(IP:10.0.0.111)

    登陆

         [root@mail amoeba]# mysql -uroot -p123456 -P8066 -h10.0.0.226

        Welcome to the MySQL monitor.  Commands end with ; or \g.

        Your MySQL connection id is 1093642553

        Server version: 5.1.45-mysql-amoeba-proxy-2.2.0 Source distribution

        

        Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

        

        Oracle is a registered trademark of Oracle Corporation and/or its

        affiliates. Other names may be trademarks of their respective

        owners.

        

        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

        

        mysql> show databases;

        +--------------------+

        | Database           |

        +--------------------+

        | information_schema |

        | ccmate             |

        | mysql              |

        | performance_schema |

        | test               |

        | tudou              |

        +--------------------+

        6 rows in set (0.00 sec)

       查询的时候,amoeba会自动去从库查询。

        mysql> select * from tudou.test;

        +--------+

        | name   |

        +--------+

        | shanqi |

        | shanqi |

        | green  |

        +--------+

        3 rows in set (0.01 sec)

        插入一条记录到测试表tudou.test,然后去主库[master]查询下

        mysql> insert into tudou.test values("test");

        Query OK, 1 row affected (0.04 sec)

        然后去主库[master]查询下

        

        mysql> select * from test;

        +--------+

        | name   |

        +--------+

        | shanqi |

        | shanqi |

        | test   |

        +--------+

        3 rows in set (0.00 sec)

        到此说明amoeba读写分离成功。

            

        问题:
        启动的时候会出现以下问题:

        

        [root@amoeba bin]# ./amoeba start

        

        The stack size specified is too small, Specify at least 228k

        Error: Could not create the Java Virtual Machine.

        Error: A fatal exception has occurred. Program will exit.

        

        这里是amoeba 启动脚本判断时有个地方设置过小,需要修改下

        [root@amoeba bin]# vi amoeba

        找到DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss128k"这一行,把128改成256即可