首页 > 其他 > 详细

基于Amoeba读写分离

时间:2019-10-25 20:09:38      阅读:84      评论:0      收藏:0      [点我收藏+]

准备五台主机

192.168.200.10主

192.168.200.11 从

192.168.200.12 从

192.168.200.14

192.168.200.15 客户端

在所有主机都关闭防火墙

systemctl stop firewalld

iptabales -F

setenforce 0

安装mariadb mariadb-server

yum -y install mariadb

yum -y install mariadb-server

在第四台主机上Amoeba上安装java环境

chmod +x jdk-6u31-linux-x64.bin

./jdk-6u31-linux-x64.bin

[root@localhost ~]# mv jdk1.6.0_14/ /usr/local/jdk1.6

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

添加:

export JAVA_HOME=/usr/local/jdk1.6

export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

export PATH=$PATH:$JAVA_HOME/lib:$JAVA_HOME/jre/bin:$HOME/bin

 

export AMOEBA_HOME=/usr/local/amoeba

export PATH=$PATH:$AMOEBA_HOME/bin

 

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

[root@localhost ~]# java -version

java version "1.7.0_75"

OpenJDK Runtime Environment (rhel-2.5.4.2.el7_0-x86_64 u75-b13)

OpenJDK 64-Bit Server VM (build 24.75-b04, mixed mode)

[root@localhost ~]# rm -rf /usr/bin/java

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

[root@localhost ~]# java -version

java version "1.6.0_14"

Java(TM) SE Runtime Environment (build 1.6.0_14-b08)

Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)

[root@localhost ~]# mkdir /usr/local/amoeba

[root@localhost ~]# ls

anaconda-ks.cfg         nginx-1.16.1.tar.gz  模板  图片  下载  桌面

jdk-6u14-linux-x64.bin  公共                 视频  文档  音乐

安装并配置Amoeba

[root@localhost ~]# mkdir /usr/local/amoeba

[root@localhost ~]# ls

anaconda-ks.cfg         nginx-1.16.1.tar.gz  模板  图片  下载  桌面

jdk-6u14-linux-x64.bin  公共                 视

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

[root@localhost ~]# chmod  -R 755 /usr/local/amoeba

[root@localhost ~]# cd /usr/local/amoeba/

[root@localhost amoeba]# ls

benchmark  bin  changelogs.txt  conf  lib  LICENSE.txt  README.html

[root@localhost amoeba]# cd conf/

[root@localhost conf]# ls

access_list.conf  dbserver.dtd   functionMap.xml  rule.dtd

amoeba.dtd        dbServers.xml  log4j.dtd        ruleFunctionMap.xml

amoeba.xml        function.dtd   log4j.xml        rule.xml

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

[root@localhost conf]# vim amoeba.xml

30              <property name="user">amoeba</property>

 

 32              <property name="password">123456</property>

115                 <property name="defaultPool">master</property>

116                 <property name="writePool">master</property>

117                 <property name="readPool">slaves</property>         

配置dbServers.xml配置文件

[root@localhost conf]# vim /usr/local/amoeba/conf/dbServers.xml

 26                         <property name="user">test</property>

 

 28                         <property name="password">123.com</property>   

        43         <dbServer name="master"  parent="abstractServer">

 44                 <factoryConfig>

 45                         <!-- mysql ip -->

 46                         <property name="ipAddress">192.168.200.10</property>

 47                 </factoryConfig>

 48         </dbServer>

 49

 50         <dbServer name="slave1"  parent="abstractServer">

 51                 <factoryConfig>

 52                         <!-- mysql ip -->

 53                         <property name="ipAddress">192.168.200.11</property>

 54                 </factoryConfig>

 55         </dbServer>

 56

 57         <dbServer name="slave2"  parent="abstractServer">

 58                 <factoryConfig>

 59                         <!-- mysql ip -->

 60                         <property name="ipAddress">192.168.200.12</property>

 61                 </factoryConfig>

 70                         <property name="poolNames">slave1,slave2</property>

 

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

remote application= .Amoeba:56071 response OK

amoeba server is running with port=56071

[root@localhost ~]# netstat -lnpt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1529/sshd          

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1637/master        

tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      1858/sshd: root@pts

tcp6       0      0 :::8066                 :::*                    LISTEN      8883/java          

tcp6       0      0 127.0.0.1:56071         :::*                    LISTEN      8883/java          

tcp6       0      0 :::22                   :::*                    LISTEN      1529/sshd          

tcp6       0      0 ::1:25                  :::*                    LISTEN      1637/master        

tcp6       0      0 ::1:6010                :::*                    LISTEN      1858/sshd: root@pts  

 

在主两个从的主机上

配置 Amoeda读写分离,两个Slave读负载均衡    

 [root@localhost ~]# mysql

 

MariaDB [(none)]> grant all on *.* to ‘test‘@‘192.168.200.%‘ identified by‘123.com‘;

Query OK, 0 rows affected (0.10 sec)

 

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

在mysql主服务器上创建一个表,会自动同步到各个从服务器上,然后关掉各个从服务器上的Slave功能,在分别插入语句测试。

 

主服务器

MariaDB [(none)]> create database db_test;

Query OK, 1 row 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.39 sec)

分别在两台从服务器上

MariaDB [db_test]> show databases;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| db_test            |

| mysql              |

| performance_schema |

| test               |

+--------------------+

5 rows in set (0.00 sec)

MariaDB [(none)]> stop slave;

Query OK, 0 rows affected (0.03 sec)

 

在主服务器上

MariaDB [db_test]> insert into student values(‘1‘,‘crushlinux‘,‘this_is_master‘);

Query OK, 1 row affected (0.02 sec)

在从服务器上1

MariaDB [(none)]> 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]> insert into student values(‘2‘,‘crushlinux‘,‘this_is_slave1‘);

Query OK, 1 row affected (0.10 sec)

在从服务器上2

MariaDB [(none)]> 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]> insert into student vlues(‘3‘,‘crushlinux‘,‘this_is_slave3‘);

Query OK, 1 row affected (0.10 sec)

 

测试读操作:

在测试机上第一次查询结果

MySQL [db_test]> select * from student;

+------+------------+----------------+

| id   | name       | address        |

+------+------------+----------------+

|    2 | crushlinux | this_is_slave2 |

+------+------------+----------------+

1 row in set (0.00 sec)

 

MySQL [db_test]> select * from student;

+------+------------+----------------+

| id   | name       | address        |

+------+------------+----------------+

|    3 | crushlinux | this_is_slave3 |

+------+------------+----------------+

1 row in set (0.15 sec)

 

在两个从服务器上

MariaDB [(none)]> start slave;

Query OK, 0 rows affected (0.00 sec)

 

测试写操作:

在客户端上插入一条语句

MySQL [(none)]> use db_test

MySQL [db_test]> insert into student values(‘4‘,‘crushlinux‘,‘write_test‘);

Query OK, 1 row affected (0.00 sec)

 

MySQL [db_test]> select * from student;

+------+------------+----------------+

| id   | name       | address        |

+------+------------+----------------+

|    2 | crushlinux | this_is_slave2 |

+------+------------+----------------+

1 row in set (0.01 sec)

 

MySQL [db_test]> select * from student;

+------+------------+----------------+

| id   | name       | address        |

+------+------------+----------------+

|    3 | crushlinux | this_is_slave3 |

|    1 | crushlinux | this_is_master |

|    4 | crushlinux | write_test     |

+------+------------+----------------+

3 rows in set (0.01 sec)

 

MySQL [db_test]> select * from student;

+------+------------+----------------+

| id   | name       | address        |

+------+------------+----------------+

|    2 | crushlinux | this_is_slave2 |

|    1 | crushlinux | this_is_master |

|    4 | crushlinux | write_test     |

+------+------------+----------------+

3 rows in set (0.00 sec)

基于Amoeba读写分离

原文:https://www.cnblogs.com/liyurui/p/11740560.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!