300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > amoeba mysql_使用Amoeba 实现MySQL DB 读写分离

amoeba mysql_使用Amoeba 实现MySQL DB 读写分离

时间:2020-07-19 12:59:19

相关推荐

amoeba mysql_使用Amoeba 实现MySQL DB 读写分离

Amoeba(变形虫)项目是一个开源框架,于开始发布一款 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(变形虫)项目是一个开源框架,于开始发布一款 Amoeba for Mysql软件;

这个软件致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当SQL路由功能,专注于分布式数据库代理层(Database Proxy)开发;位于 Client、DB Server(s)之间,对客户端透明;

具有负载均衡、高可用性、SQL 过滤、读写分离、可路由相关的请求到目标数据库、可并发请求多台数据库并合并结果;

通过Amoeba你能够完成多数据源的高可用、负载均衡、数据切片的功能,目前Amoeba已在很多企业的生产线上面使用;

2 准备

2.1 时间同步

# crontab -e

# Dscrip: Time Sync

# CTime: .03.23

*/5 * * * * /usr/sbin/ntpdate 172.16.0.1 &>/dev/null

2.2 配置MySQL主从复制架构

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前端监听端口

3306 # 默认端口是8066,修改为3306,便于实现前端程序连接数据库的透明性

# 修改连接amoeba接口的认证信息

root

mypass # 添加登录密码

# 查询路由设置

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

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

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

1500

master # 设定默认节点

master # 设定可写节点,节点定义见dbServers.xml文件

readservers # 设定只读池,可配置多个slave节点

true

vi dbServers.xml # 后端节点配置文件

# 定义抽象服务器,为每个后端MySQL服务器提供默认连接配置

${defaultManager}

64

128

3406

test

root

magedu

# 定义后端MySQL的IP地址,一个master,一个slave

192.168.0.45

192.168.0.46

# 定义虚拟服务器组,即只读池readservers

1

master,slave

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'@'%' 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, , 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, , 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, , 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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。