Amoeba

原理:amoeba相当于业务员,处理client的读写请求,并将读写请求分开处理。amoeba和master以及slave都有联系,如果是读的请求,amoeba就从slave读取信息反馈给client;如果是写的请求,amoeba会将相关数据写入master。

实验设备:其中master、slave1、slave2是接上一个MYSQL主从复制操作

master:192.168.200.125

slave1:192.168.200.124

slave2:192.168.200.111

amoeba:192.168.200.130

client:192.168.200.122

Amoeba操作:安装java因为Amoeba是基于jdk1.5版本开发的(版本1.5-1.7不建议使用高版本)

1:导入amoeba以及jdk源码包并修改主配置文件

[root@localhost ~]# rz
z waiting to receive.**B0100000023be50
[root@localhost ~]# ls
amoeba-mysql-binary-2.2.0.tar.gz    apache-tomcat-8.5.40.tar.gz      jdk-7u65-linux-x64.tar.gz
anaconda-ks.cfg        initial-setup-ks.cfg               original-ks.cfg

[root@localhost ~]# tar xf jdk-7u65-linux-x64.tar.gz
[root@localhost ~]# mv jdk1.7.0_65/ /usr/local/java

[root@localhost ~]# vim /etc/profile

在末尾添加如下五行

JAVA_HOME=/usr/local/java
CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
PATH=$PATH:$JAVA_HOME/lib:$JAVA_HOME/jre/bin:$HOME/bin AMOEBA_HOME=/usr/local/amoeba
PATH=$PATH:$AMOEBA_HOME/bin

[root@localhost ~]# source /etc/profile
[root@localhost ~]# java -version

2:删除高版本java程序文件

[root@localhost ~]# rm -rf /usr/bin/java
[root@localhost ~]# source /etc/profile
[root@localhost ~]# java -version

3:安装并配置Amoeba

[root@localhost ~]# mkdir /usr/local/amoeba
[root@localhost ~]# tar xf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
[root@localhost ~]# chmod -R 775 /usr/local/amoeba/

4:配置Amoeba读写分离。两个slave读负载均衡

编辑amoeba.xml配置文件

[root@localhost ~]# cd /usr/local/amoeba/conf/
[root@localhost conf]# ls
access_list.conf      amoeba.xml      dbServers.xml     functionMap.xml     log4j.xml       ruleFunctionMap.xml
amoeba.dtd            dbserver.dtd      function.dtd         log4j.dtd                   rule.dtd        rule.xml

[root@localhost conf]# cp amoeba.xml amoeba.xml.bak

[root@localhost conf]# vim amoeba.xml

35行左右修改用户名和登入密码
# 提供客户端连接amoeba时需要使用这里设定的账号 (这里的账号密码和amoeba连接后端数据库服务器的密码无关)
<property name="user">amoeba</property>
<property name="password"></property> 115行左右修改

<property name="defaultPool">master</property>          #默认找master

<property name="writePool">master</property>            #写的值交给master
  <property name="readPool">slaves</property>             #读交给slaves(slaves包括:slave1、slave2)

[root@localhost conf]# cp dbServers.xml dbServers.xml.bak

[root@localhost conf]# vim dbServers.xml

23行左右修改:

<property name="port"></property>
<!-- mysql schema -->
<property name="schema">test</property>
<!-- mysql user -->
<property name="user">test</property> #在master、slave1、slave2三台服务器中配置Amoeba访问授权的用户:
<!-- mysql password-->
<property name="password">.com</property> #授权的密码 45行左右修改:

<dbServer name="master" parent="abstractServer">       #dbServer指定服务器为master
  <factoryConfig>
              <!-- mysql ip -->
  <property name="ipAddress">192.168.200.125</property>  #dbServer指定服务器为ip
  </factoryConfig>
  </dbServer>

<dbServer name="slave1" parent="abstractServer">       #dbServer指定服务器为slave1
  <factoryConfig>
              <!-- mysql ip -->
  <property name="ipAddress">192.168.200.124</property>  #dbServer指定服务器为ip
  </factoryConfig>
  </dbServer>

<dbServer name="slave2" parent="abstractServer">       #dbServer指定服务器为slave2
  <factoryConfig>
             <!-- mysql ip -->
  <property name="ipAddress">192.168.200.111</property>   #dbServer指定服务器为ip
  </factoryConfig>
  </dbServer>

66行左右修改:

<dbServer name="slaves" virtual="true">                  #声明组为slaves
  <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">
           <!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->
  <property name="loadbalance">1</property>                #声明为1表示轮询

<!-- Separated by commas,such as: server1,server2,server1 -->
  <property name="poolNames">slave1,slave2</property>      #声明组的成员

[root@localhost conf]# vim /usr/local/amoeba/bin/amoeba

58行修改如下:

   原:DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss128k"
修改后:DEFAULT_OPTS="-server -Xms256m -Xmx256m -Xss256k"

[root@localhost ~]# vim /etc/my.cnf

max_allowed_packet = 16M

5:配置无误后,启动Amoeba软件,默认端口为TCP协议8066

[root@localhost conf]# /usr/local/amoeba/bin/amoeba start &

[root@localhost conf]# netstat -anpt | grep 8066
tcp6 0 0 :::8066 :::* LISTEN 18841/java

6:关闭防火墙
[root@localhost conf]# systemctl stop firewalld
[root@localhost conf]# iptables -F
[root@localhost conf]# setenforce 0

master主机服务器测试:

创建一个库以及表,会自动同步到各个从服务器上,然后关掉各个服务器上的slave功能,再分别插入语句测试

MariaDB [(none)]> create database db_test;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cmx |
| db_test |
| liuxiang |
| mysql |
| performance_schema |
+--------------------+
6 rows in set (0.00 sec)

MariaDB [(none)]> grant all on *.* to 'test'@'192.168.200.%' identified by '123.com';       #配置Amoeba的访问授权
Query OK, 0 rows affected (0.15 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> use db_test;
Database changed

MariaDB [db_test]> create table student(id int(10),name varchar(10),address varchar(20));
Query OK, 0 rows affected (0.01 sec)

MariaDB [db_test]> insert into student(id,name,address) values('1','crushlinux','this_is_master');
Query OK, 1 row affected (0.01 sec)

 master测试来自client的数据:

MariaDB [db_test]> select * from student;
+------+------------+----------------+
| id | name | address |
+------+------------+----------------+
| 1 | crushlinux | this_is_master |
| 4 | crushlinux | this_is_client |
+------+------------+----------------+
2 rows in set (0.00 sec)

两台slave从服务器测试操作一致:

允许200网段内的账号为test密码为123.com的主机连接数据库

MariaDB [(none)]> grant all on *.* to 'test'@'192.168.200.%' identified by '123.com';       #slave1、slave2都配置这个Amoeba的访问授权
Query OK, 0 rows affected (0.15 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> show databases;                           
+--------------------+
| Database |
+--------------------+
| information_schema |
| client |
| cmx |
| db_test |
| liuxiang |
| mydb |
| mysql |
| performance_schema |
| shuifei |
| var |
| yg |
+--------------------+
11 rows in set (0.13 sec)

MariaDB [(none)l]> use db_test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [db_test]> select * from student;
+------+------------+----------------+
| id | name | address |
+------+------------+----------------+
| 1 | crushlinux | this_is_master |
| 2 | crushlinux | this_is_slave1 |
+------+------------+----------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> stop slave;                                           #主服务器插入完数据后再执行stop slave
Query OK, 0 rows affected (0.01 sec)

MariaDB [db_test]> insert into student values('2','crushlinux','this_is_slave1');          #slave2改为('3,'crushlinux','this_is_slave2');  
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)

测试来自client的数据:

MariaDB [(none)]> select * from db_test.student;                    #slave1的测试

+------+------------+----------------+
| id | name | address |
+------+------------+----------------+
| 1 | crushlinux | this_is_master |
| 2 | crushlinux | this_is_slave1 |
| 4 | crushlinux | this_is_client |
+------+------------+----------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> select * from db_test.student;                       #slave2的测试
+------+------------+----------------+
| id | name | address |
+------+------------+----------------+
| 1 | crushlinux | this_is_master |
| 3 | crushlinux | this_is_slave2 |
| 4 | crushlinux | this_is_client |
+------+------------+----------------+
3 rows in set (0.00 sec)

Client机配置:

安装mariadb做访问amoeba机的测试

[root@localhost ~]# yum install mariadb mariadb-server -y

远程登陆mysql客户端通过指定amoeba配置文件中指定的用户名、密码、和端口以及amoeba服务器ip地址链接mysql数据库

[root@localhost ~]# mysql -u amoeba -p123456 -h 192.168.200.130 -P 8066
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 411716403
Server version: 5.1.45-mysql-amoeba-proxy-2.2.0

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

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

测试读操作:

MySQL [db_test]> select * from student;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 1696547550
Current database: db_test

+------+------------+----------------+
| id | name | address |
+------+------------+----------------+
| 1 | crushlinux | this_is_master |
| 2 | crushlinux | this_is_slave1 |
+------+------------+----------------+
2 rows in set (0.20 sec)

MySQL [db_test]> select * from student;
+------+------------+----------------+
| id | name | address |
+------+------------+----------------+
| 1 | crushlinux | this_is_master |
| 3 | crushlinux | this_is_slave2 |
+------+------------+----------------+
2 rows in set (0.01 sec)

MySQL [db_test]> select * from student;
+------+------------+----------------+
| id | name | address |
+------+------------+----------------+
| 1 | crushlinux | this_is_master |
| 2 | crushlinux | this_is_slave1 |
+------+------------+----------------+
2 rows in set (0.01 sec)

MySQL [db_test]> select * from student;
+------+------------+----------------+
| id | name | address |
+------+------------+----------------+
| 1 | crushlinux | this_is_master |
| 3 | crushlinux | this_is_slave2 |
+------+------------+----------------+
2 rows in set (0.01 sec)

 测试写操作:

MySQL [db_test]> insert into student values('4','crushlinux','this_is_client');
Query OK, 1 row affected (0.01 sec)

MySQL [db_test]> select * from student;
+------+------------+----------------+
| id | name | address |
+------+------------+----------------+
| 1 | crushlinux | this_is_master |
| 2 | crushlinux | this_is_slave1 |
| 4 | crushlinux | this_is_client |
+------+------------+----------------+
3 rows in set (0.01 sec)

MySQL [db_test]> select * from student;
+------+------------+----------------+
| id | name | address |
+------+------------+----------------+
| 1 | crushlinux | this_is_master |
| 3 | crushlinux | this_is_slave2 |
| 4 | crushlinux | this_is_client |
+------+------------+----------------+
3 rows in set (0.01 sec)

测试完成可读可写!

基于Amoeba读写分离的更多相关文章

  1. amoeba读写分离

    第一单元   高性能mysql读写分离的实现 5.1      mysql读写分离 5.1.1  mysql读写分离概述 5.1.2  mysql读写分离原理 5.2      mysql读写分离配置 ...

  2. 001.Amoeba读写分离部署

    一 Amoeba简介 Amoeba(变形虫)项目,该开源框架于2008年 开始发布一款 Amoeba forMysql软件.这个软件致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQ ...

  3. Amoeba读写分离(MySQL)

    实验操作环境: centos服务器  三台机器 role: 192.168.189.129  master-主 192.168.189.130  master-从 192.168.189.131    ...

  4. mysql主从之基于atlas读写分离

    一 mysql读写分离的概念 写在主库,主库一般只有一个,读可以分配在多个从库上,如果写压力不大的话,也能把读分配到主库上. 实现是基于atlas实现的,atlas是数据库的中间件,程序只需要连接at ...

  5. 基于Spring读写分离

    为什么是基于Spring的呢,因为实现方案基于Spring的事务以及AbstractRoutingDataSource(spring中的一个基础类,可以在其中放多个数据源,然后根据一些规则来确定当前需 ...

  6. mysql基于Altas读写分离并实现高可用

    实验环境准备: master:192.168.200.111 slave1:192.168.200.112 slave2:192.168.200.113 Altas:192.168.200.114 c ...

  7. Mysql 基于 Amoeba 的 读写分离

    首先说明一下amoeba 跟 MySQL proxy在读写分离的使用上面的区别: 在MySQL proxy 6.0版本 上面如果想要读写分离并且 读集群.写集群 机器比较多情况下,用mysql pro ...

  8. Linux下Mysql主从复制(Master-Slave)与读写分离(Amoeba)实践

    一.为什么要做Mysql的主从复制(读写分离)?通俗来讲,如果对数据库的读和写都在同一个数据库服务器中操作,业务系统性能会降低.为了提升业务系统性能,优化用户体验,可以通过做主从复制(读写分离)来减轻 ...

  9. Mysql读写分离方案-Amoeba环境部署记录

    Mysql的读写分离可以使用MySQL Proxy,也可以使用Amoeba.Amoeba(变形虫)项目是一个类似MySQL Proxy的分布式数据库中间代理层软件,是由陈思儒开发的一个开源的java项 ...

随机推荐

  1. pyodbc 一些内容

    如果表格里是空的,读出来是会变为None,所以用是否等于None来判断内容是否为空.

  2. adb 无线连接手机设备

    连接语法: $ adb connect ip:port 断开连接: $ adb disconnect ip:port 可能遇到问题:unable to connect to 192.168.199.2 ...

  3. CSS盒子模型探讨

    盒模型 html文档中的每个元素都被描绘成矩形盒子,这些矩形盒子通过一个模型来描述其占用空间,这个模型称为盒模型.盒模型通过四个边界来描述:margin(外边距),border(边框),padding ...

  4. JavaScript 运算,流程控制和循环

    算数运算符 算术运算符 描叙 运算符 实例 加 + 10 + 20 = 30 减 - 10 – 20 = -10 乘 * 10 * 20 = 600 除 / 10 / 20 = 0.5 取余数 % 返 ...

  5. Failed to start mysqld.service: Unit not found

    输入命令 systemctl start mysql.service 要启动MySQL数据库是却是这样的提示 Failed to start mysqld.service: Unit not foun ...

  6. 【译】通过 Rust 学习解析器组合器 — Part 1

    原文地址:Learning Parser Combinators With Rust 原文作者:Bodil 译文出自:掘金翻译计划 本文永久链接:https://github.com/xitu/gol ...

  7. 1015 Reversible Primes

    1. 题目 2. 抽象建模 无 3. 方法 无 4. 注意点 素数判断(1不是素数) 数值的倒转 5. 代码 #include<stdio.h> #include<math.h> ...

  8. CF1288F Red-Blue Graph

    Link 考虑上下界+费用流. 对于左部点\(u\): 如果颜色为\(B\),连\((s,u,[1,+\infty),0)\). 如果颜色为\(R\),连\((u,t,[1,+\infty),0)\) ...

  9. 深入 js 深拷贝对象

    前言 对象是 JS 中基本类型之一,而且和原型链.数组等知识息息相关.不管是面试中,还是实际开发中我们都会碰见深拷贝对象的问题. 顾名思义,深拷贝就是完完整整的将一个对象从内存中拷贝一份出来.所以无论 ...

  10. 【C语言】输入三个正整数a,b,c,求最大值,要求定义一个计算最大值的函数max(a,b),返回a,b的值

    #include<stdio.h> int max(int a, int b)/*定义函数*/ { if (a > b) return a; else return b; } int ...