LinuxEye - Linux系统教程

LinuxEye - Linux系统教程

当前位置: 主页 > 数据库 >

MySQL Proxy - 架构篇

时间:2013-03-21 09:38来源:开源中国社区 编辑:摩云飞 点击:
架构篇(architecture) MySQL Proxy 的定位是存在于 mysql client 和 mysql server 之间的一个简单的程序,能够对从其上通过的数据进行检查、转换和直接进行相应操作。 应用范围包括: 负载均衡
架构篇(architecture)
       MySQL Proxy 的定位是存在于 mysql client 和 mysql server 之间的一个简单的程序,能够对从其上通过的数据进行检查、转换和直接进行相应操作。

应用范围包括:
  1. 负载均衡(load balancing)
  2. 故障处理(fail over)
  3. 查询追踪(query tracking)
  4. 查询分析(query analysis)
  5. (...)

       内部实现上讲,MySQL Proxy 是这样的一个协议栈:

基于这个 core 能够将 protocol 的各个 phase 暴露给 plugin 。
  • connect -> auth;
  • auth -> command;
  • command -> disconnect;
  • command -> command;
  • connect -> disconnect;
  • auth -> disconnect;

       上述生命周期中的每一个阶段都包含了多种协议状态变迁。以鉴权过程为例,其包含了至少 3 个包:

life-cycle 中涉及的实体: Client, Proxy, Server;
Client -> Proxy [ label = "accept()" ];
Proxy -> Proxy [ label = "script: connect_server()" ];
Proxy -> Server [ label = "connect()" ];
...;

Server -> Proxy [ label = "recv(auth-challenge)" ];
Proxy -> Proxy [ label = "script: read_handshake()" ];

Proxy -> Client [ label = "send(auth-challenge)" ];
Client -> Proxy [ label = "recv(auth-response)" ];
Proxy -> Proxy [ label = "script: read_auth()" ];
Server -> Proxy [ label = "send(auth-response)" ];
Server -> Proxy [ label = "recv(auth-result)" ];
Proxy -> Proxy [ label = "script: read_auth_result()" ];
Proxy -> Client [ label = "send(auth-result)" ];
...;

当核心层 core 面对大量 connection 的时候是具备自由伸缩特性时,plugin/scripting 层就能够轻易对 end-users 隐藏细节,并简化客户端的实现。

MySQL Proxy 是通过各种库(Chassis, libraries and Plugins)构建出来的协议栈:

其中 chassis 提供了命令行和作为 daemon 应用所需的所有通用函数实现,包括:
  1. 命令行和配置文件(commandline and configfiles)
  2. 日志(logging)
  3. 支持 daemon/service 方式运行(daemon/service support)
  4. plugin 加载(plugin loading)

同时 MySQL Procotol 的 libraries 还实现了实现了各种编码解码功能:
  1. 客户端协议(client protocol)
  2. binlog 协议(binlog protocol)
  3. myisam 文件处理(myisam files)
  4. frm 文件处理(frm files)
  5. masterinfo 文件处理(masterinfo files)

转载请保留固定链接: https://linuxeye.com/database/1393.html

------分隔线----------------------------
标签:mysqlProxy
栏目列表
推荐内容