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. ORA-01830

    问题:varchar2类型转换成date类型 select to_date(INVOICE_DATE,'yyyy-mm-dd') from tab; 提示 ORA-01830: 日期格式图片在转换整个 ...

  2. python3练习100题——020

    原题链接:http://www.runoob.com/python/python-exercise-example20.html 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半:再落下 ...

  3. Jarvis OJ - class10 -Writeup

    Jarvis OJ - class10 -Writeup 转载请注明出处:http://www.cnblogs.com/WangAoBo/p/7552266.html 题目: Jarivs OJ的一道 ...

  4. Pyarm的Pyqt的配置

    相关连接: Python PyQt 安装python3.4 x64到c盘根目录. 安装PyQt5-5.5.1-gpl-Py3.4-Qt5.5.1-x64.exe 安装pycharm-professio ...

  5. Educational Codeforces Round 76 (Rated for Div. 2) C. Dominated Subarray

    Let's call an array tt dominated by value vv in the next situation. At first, array tt should have a ...

  6. 题解 【Codeforces381A】 Sereja and Dima

    本题是很好的双指针练习题. 关于双指针,详见洛谷日报#73. 我们可以用两个指针l和r表示题中两人接下来要比较的数字,用fl标记下一个将要取的人,并分别用两个计数器统计双方的答案. 因此,我们有了如下 ...

  7. HDU4714 Tree2cycle 解题报告

    题意 给定一棵无根树,删除或连接一条边的代价为\(1\),求把树变为环的最小代价. 前置思路 如果删除了\(k\)条边,使得树变成\((k+1)\)条链,再用\((k+1)\)次连接操作把树变成一个环 ...

  8. .net core 2.2 使用imagemagick 将pdf转化为png

    工作需要将PDF文件每一页拆分为一个一个的png文件 测试环境:mac,visual studio for mac 2019 nuget:magick.net-Q16-AnyCPU 不能直接支持PDF ...

  9. python 字符串是否包含某个子字符串

    方法如下:以后再整理 if str1 in str2: 包含的话,True if str1.find(str2)>=0: 包含的话,返回第一次出现的位置,没有的话为负数 https://www. ...

  10. codeforce D. Shortest Cycle(floyd求最短环)

    题目链接:http://codeforces.com/contest/1206/problem/D 给n个点,如果点a[ i ] &a[ j ] 不为0,则点a[ i ] 和 a[ j ] 直 ...