使用Amoeba 实现MySQL DB 读写分离
Amoeba(变形虫)项目是一个开源框架,于2008年开始发布一款 Amoeba for Mysql软件;
这个软件致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当SQL路由功能,专注于分布式数据库代理层(Database Proxy)开发;位于 Client、DB Server(s)之间,对客户端透明;
===================================================================
1 简介
2 准备
2.1 时间同步
2.2 配置MySQL主从复制架构
3 ameoba安装配置
3.1 安装配置JDK
3.2 安装ameoba
3.3 配置ameoba
3.4 使用验证
3.5 后期扩展
4 问题记录
===================================================================
1 简介
Amoeba(变形虫)项目是一个开源框架,于2008年开始发布一款 Amoeba for Mysql软件;
这个软件致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当SQL路由功能,专注于分布式数据库代理层(Database Proxy)开发;位于 Client、DB Server(s)之间,对客户端透明;
具有负载均衡、高可用性、SQL 过滤、读写分离、可路由相关的请求到目标数据库、可并发请求多台数据库并合并结果;
通过Amoeba你能够完成多数据源的高可用、负载均衡、数据切片的功能,目前Amoeba已在很多企业的生产线上面使用;
2 准备
2.1 时间同步
# crontab -e
# Dscrip: Time Sync
# CTime: 2014.03.23
*/5 * * * * /usr/sbin/ntpdate 172.16.0.1 &>/dev/null
2.2 配置MySQL主从复制架构
详见博文"MariaDB 主从复制"
3 ameoba安装配置
3.1 安装配置JDK
chmod +x jdk-6u31-linux-x64-rpm.bin
vi /etc/profile.d/java.sh # 采用bin文件安装jdk
export JAVA_HOME=/usr/java/latest
export PATH=$JAVA_HOME/bin:$PATH
3.2 安装ameoba

mkdir /usr/local/amoeba
tar xf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba # 使用二进制程序文件安装amoeba
cd /usr/local/amoeba
bin/amoeba start # 前台运行
nohup /usr/local/amoeba/bin/amoeba start & # 后台运行
mysql -h127.0.0.1 -uroot -p -P8066 # amoeba默认监听端口为8066

3.3 配置ameoba

cd /usr/local/amoeba/conf
vi ameoba.xml # 前端定义配置文件
# 修改ameoba前端监听端口
<service name="Amoeba for Mysql" class="com.meidusa.amoeba.net.ServerableConnectionManager">
<property name="port">3306</property> # 默认端口是8066,修改为3306,便于实现前端程序连接数据库的透明性
# 修改连接amoeba接口的认证信息
<property name="authenticator">
<bean class="com.meidusa.amoeba.mysql.server.MysqlClientAuthenticator">
<property name="user">root</property>
<property name="password">mypass</property> # 添加登录密码
# 查询路由设置
<queryRouter class="com.meidusa.amoeba.mysql.parser.MysqlQueryRouter">
<property name="ruleLoader">
<bean class="com.meidusa.amoeba.route.TableRuleFileLoader">
<property name="ruleFile">${amoeba.home}/conf/rule.xml</property>
<property name="functionFile">${amoeba.home}/conf/ruleFunctionMap.xml</property>
</bean>
</property>
<property name="sqlFunctionFile">${amoeba.home}/conf/functionMap.xml</property>
<property name="LRUMapSize">1500</property>
<property name="defaultPool">master</property> # 设定默认节点
<property name="writePool">master</property> # 设定可写节点,节点定义见dbServers.xml文件
<property name="readPool">readservers</property> # 设定只读池,可配置多个slave节点
<property name="needParse">true</property>
</queryRouter>
vi dbServers.xml # 后端节点配置文件
# 定义抽象服务器,为每个后端MySQL服务器提供默认连接配置
<dbServer name="abstractServer" abstractive="true">
<factoryConfig class="com.meidusa.amoeba.mysql.net.MysqlServerConnectionFactory">
<property name="manager">${defaultManager}</property>
<property name="sendBufferSize">64</property>
<property name="receiveBufferSize">128</property>
<property name="port">3406</property>
<property name="schema">test</property>
<property name="user">root</property>
<property name="password">magedu</property>
</factoryConfig>
# 定义后端MySQL的IP地址,一个master,一个slave
<dbServer name="master" parent="abstractServer">
<factoryConfig>
<property name="ipAddress">192.168.0.45</property>
</factoryConfig>
</dbServer>
<dbServer name="slave" parent="abstractServer">
<factoryConfig>
<property name="ipAddress">192.168.0.46</property>
</factoryConfig>
</dbServer>
# 定义虚拟服务器组,即只读池readservers
<dbServer name="readservers" virtual="true">
<poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
<property name="loadbalance">1</property>
<property name="poolNames">master,slave</property>
</poolConfig>
</dbServer>

3.4 使用验证
在主库上授权:

MariaDB [(none)]> grant all on *.* to'root'@'172.16.%.%' identified by 'magedu';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all on *.* to'root'@'%mysql.com' identified by 'magedu'; # 这里的密码应该与dbServer.xml中的数据库密码一致
Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)


# 登录验证
[root@mysql conf]# mysql -h127.0.0.1 -uroot -p -P3306
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2097086015
Server version: 5.1.45-mysql-amoeba-proxy-2.2.0 Source distribution
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000030 | 326 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
MySQL [(none)]>
# 读写验证
[root@mysql conf]# mysql -h127.0.0.1 -uroot -p -P3306
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2097086015
Server version: 5.1.45-mysql-amoeba-proxy-2.2.0 Source distribution
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> create database amoeba_test;
Query OK, 1 row affected (0.04 sec)
MySQL [(none)]>
[root@mysql bin]# mysql -h127.0.0.1 -uroot -p -P3406
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 33
Server version: 10.0.10-MariaDB-log Source distribution
Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| amoeba_test |
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
9 rows in set (0.01 sec)
MariaDB [(none)]>
# 从amoeba接口登录创建数据库amoeba_test后,再从主库的接口中去查询数据库已创建,说明写入确实是落在了主库节点上;
# 若要验证ameoba对于读操作的调度,则需要暂时停止从库的复制操作,然后在主库上更新数据,这样从ameoba读取数据将出现不一致的情况;

3.5 后期扩展
利用MMM双主复制架构+Amoeba代理,可以实现对MySQL的高可用性和高性能;
关于MMM的内容参加博文"MySQL Scale Out"
4 问题记录
现象:使用mysql -uroot -p -P8066命令始终无法连接进入ameoba的配置接口,一直都是进入mysql数据库的配置接口
原因:在测试环境下,ameoba和mysql的主库都部署在同一台主机上,当启动ameoba服务后,即使指定-P8066连接,mysql客户端还是默认采用可被识别的socket文件(/tmp/mysql.sock)连接,同样指定-hlocalhost也是一样的;
当使用mysql命令连接mysqld时:
连接主机为localhost或不指定时,mysql会采用Unix Socket的连接方式;
连接主机为127.0.0.1时,mysql会采用TCP的方式连接;
解决方法:指定-h127.0.0.1连接即可,即mysql -h127.0.0.1 -uroot -p -P8066
http://www.cnblogs.com/xiaocen/p/3736095.html
使用Amoeba 实现MySQL DB 读写分离的更多相关文章
- (转)使用Amoeba 实现MySQL DB 读写分离
Amoeba(变形虫)项目是一个开源框架,于2008年开始发布一款 Amoeba for Mysql软件: 这个软件致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当SQ ...
- Amoeba实现mysql主从读写分离
Amoeba实现mysql主从读写分离 这段在网上看了下关于amoeba的文章,总体感觉好像要比mysql-proxy好的多,也参考了不少的资料,此文章可能与其他文章作者会有雷同的地方,请谅解,但是此 ...
- MySQL的读写分离的几种选择
MySQL的读写分离的几种选择 MySQL主从复制(Master-Slave)与读写分离(MySQL-Proxy)实践 原址如下: http://heylinux.com/archives/1004. ...
- Amoeba搞定mysql主从读写分离
前言:一直想找一个工具,能很好的实现mysql主从的读写分离架构,曾经试用过mysql-proxy发现lua用起来很不爽,尤其是不懂lua脚本,突然发现了Amoeba这个项目,试用了下,感觉还不错,写 ...
- 搭建基于MySQL的读写分离工具Amoeba
搭建基于MySQL的读写分离工具Amoeba: Amoeba工具是实现MySQL数据库读写分离的一个工具,前提是基于MySQL主从复制来实现的: 实验环境(虚拟机): 主机 角色 10.10.10.2 ...
- MySQL/MariaDB读写分离配置
DB读写分离描述 数据库的读写分离其实就是为了加减少数据库的压力:数据库的写入操作由主数据库来进行,读取操作由从数据库来进行操作.实现数据库读写分离技术是有很多方法的,在这里我就用一个比较简单的mys ...
- python实现mysql的读写分离及负载均衡
Oracle数据库有其公司开发的配套rac来实现负载均衡,目前已知的最大节点数能到128个,但是其带来的维护成本无疑是很高的,并且rac的稳定性也并不是特别理想,尤其是节点很多的时候. 但是,相对my ...
- MySQL ProxySQL读写分离实践
目的 在上一篇文章MySQL ProxySQL读写分离使用初探里初步介绍了ProxySQL的使用,本文继续介绍它的一些特点和DBProxy的性能差异.深入一些去了解ProxySQL,通过测试来说明Pr ...
- 应用集成mycat,实现mycat的高可用与mysql的读写分离
前言 开心一刻 一个女人自朋友圈写道:我家老公昨天和别人家的老婆出去旅游,迄今未归,我则被别人家的老公折腾了一天,好累哦! 圈子下面,评论无数,老公在下面评论到:能不能好好说话,我只不过陪女儿去毕业旅 ...
随机推荐
- C# 类中隐藏基类方法和Partial
今天对于.NET开发人员来说最开心的事情莫过于微软搞开源了,这觉得是给搞.NET开发的长脸.虽然我是一个初学者,这无疑给我极大的学习动力.Fighting!!! 当一个类从父类继承了一个成员时,也就继 ...
- 简易记事本(演示java文件io)
演示效果: 打开txt文件 输入文字,保存 选择保存地址 生成文件 源代码: package io; import java.io.*; import java.awt.*; import ja ...
- 十、mysql事务的简介
1. myisam跟memory支持表级别锁定 BDB 页级锁定 Innodb 行级锁定 2.表锁(不是表嫂哈) lock table read //只读表锁,也就是说执行了这个锁后,锁内的操作只能为 ...
- [gradle] is applicable for argument types
error: is applicable for argument types: (org.eclipse.jetty.server.Request) 很显然这个错误是因为 不是静态方法造成的,改为静 ...
- Cygwin安装与配置
Cygwin可以在windows环境下模拟Linux系统,而且可以重用Linux下面丰富的脚本工具.windows的cmd太弱了.Cygwin是由Cygnus(天鹅座) Solution公司开发,不过 ...
- Hibernate从入门到精通(五)一对一单向关联映射
上次的博文中Hibernate从入门到精通(四)基本映射我们已经讲解了一下基本映射和相关概念,接下来我们会讲稍微复杂点的映射——关系映射. 关系映射分类 关系映射即在基本映射的基础上处理多个相关对象和 ...
- Create CSS3 Buttons Compatible with All Browsers
Create CSS3 Buttons Compatible with All Browsers http://www.ourtuts.com/create-css3-buttons-compatib ...
- html 5 drag and drop upload file
compatible: chrome firefox ie 11 , not supported demo: http://demo.tutorialzine.com/2011/09/html5-fi ...
- Contest2037 - CSU Monthly 2013 Oct (problem A :Small change)
[题解]:二进制拆分 任意一个整数都可以拆分成 2^0 + 2^1 + 2^2 + 2^3 + ....+ m [code]: #include <iostream> #include & ...
- PAT-乙级-1026. 程序运行时间(15)
1026. 程序运行时间(15) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 要获得一个C语言程序的运行时间, ...