首先说明一下amoeba 跟 MySQL proxy在读写分离的使用上面的区别:

 

在MySQL proxy 6.0版本 上面如果想要读写分离并且 读集群、写集群 机器比较多情况下,用mysql proxy 需要相当大的工作量,目前mysql proxy没有现成的 lua脚本。mysql proxy根本没有配置文件, lua脚本就是它的全部,当然lua是相当方便的。那么同样这种东西需要编写大量的脚本才能完成一 个复杂的配置。而Amoeba只需要进行相关的配置就可以满足需求。

 

 

假设有这样的使用场景,有三个数据库节点分别命名为Master、Slave1、Slave2如下:

 

Amoeba: Amoeba <192.168.14.129>
Master: Master <192.168.14.131> (可读写)
Slaves:Slave1 <192.168.14.132>、Slave2<192.168.14.133> (2个平等的数据库。只读/负载均衡)

在 主从数据库 的复制的部分, 任然需要使用数据库自己的复制机制。 Amoeba 不提供复制功能。

 

1. 起动数据库的主从复制功能。

 

a. 修改配置文件

 

master.cnf
Cnf代码  
1. server-id = 1
2.   
3. # 增加 日志文件, 用于验证读写分离  
4. log = /home/mysql/mysql/log/mysql.log

 

slave1.cnf
Cnf代码  
1. server-id = 2
2.   
3. # 增加 日志文件, 用于验证读写分离  
4. log = /home/mysql/mysql/log/mysql.log

 

slave2.cnf
Cnf代码  
1. server-id = 3
2.   
3. # 增加 日志文件, 用于验证读写分离  
4. log = /home/mysql/mysql/log/mysql.log

 

b. Master 中 创建两个 只读权限 的用户。 用户名均为:repl_user   密码均为:copy  分别开放给 slave1, slave2

 

Sql代码  

1. mysql> grant replication slave on *.* to repl_user@192.168.14.132 identified by 'copy';  
2.   
3. mysql> grant replication slave on *.* to repl_user@192.168.14.133 identified by 'copy';

 

c. 查看 Master 信息

Sql代码  

    1. mysql> show master status;  
    2. +------------------+----------+--------------+------------------+
    3. | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |  
    4. +------------------+----------+--------------+------------------+
    5. | mysql-bin.000017 |     2009 |              |                  |  
    6. +------------------+----------+--------------+------------------+
    7. 1 row in set

     

    d. Slave1 ,Slave2 中 启动 Master - Slave 复制功能。

     

    分别执行以下命令

     

    Sql代码  

    1. mysql> slave stop;  
    2. Query OK, 0 rows
    3.   
    4. mysql> change master to
    5. '192.168.14.131',  
    6. 'repl_user',  
    7. 'copy',  
    8. 'mysql-bin.000017',  
    9.     -> master_log_pos=2009;  
    10. Query OK, 0 rows
    11.   
    12. mysql> start slave;  
    13. Query OK, 0 rows

     

    2. Amoeba 读写分离的配置

     

    a. Master , Slave1 ,Slave2 中开放权限给 Amoeba 访问。

     

    在 Master , Slave1 , Slave2 中分别执行

     

    Sql代码  

    1. mysql> grant all on test.* to test_user@192.168.14.129 indentified by '1234';  

    Amoeba 访问三个数据库的账号密码相同。

     

    b. 修改 Amoeba 的配置文件

     

    配置文件详细说明请查看 官方文档:http:///amoeba/rw-splitting.html

     

    dbServer.xml

    Xml代码 





    转载于:https://blog.51cto.com/devin223/1664830