Based amoeba separate read and write

Environment configuration:

MySQL Master IP: 192.168.200.111

MySQL Slave1 IP: 192.168.200.112

MySQL Slave2 IP: 192.168.200.113

MySQL Amoeba IP: 192.168.200.114

MySQL Client IP: 192.168.200.115

1, java environment installed on the host Amoeba

Because Amoeba is based on jdk1.5 version of the development, it is recommended to use the official version 1.5 or 1.6, the high version is not recommended.

[root@localhost ~]# chmod +x jdk-6u31-linux-x64.bin

[root@localhost ~]# ./jdk-6u31-linux-x64.bin

[root@localhost ~]# mv jdk1.6.0_31/ /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.6.0_31"

Java(TM) SE Runtime Environment (build 1.6.0_31-b04)

Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

 

High version comes with java problem

[root@localhost ~]# java -version

openjdk version "1.8.0_161"

OpenJDK Runtime Environment (build 1.8.0_161-b14)

OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

Method one: Uninstall higher version

[root@localhost ~]# rpm -qa | grep -i openjdk

java-1.7.0-openjdk-1.7.0.171-2.6.13.2.el7.x86_64

java-1.7.0-openjdk-headless-1.7.0.171-2.6.13.2.el7.x86_64

java-1.8.0-openjdk-1.8.0.161-2.b14.el7.x86_64

java-1.8.0-openjdk-headless-1.8.0.161-2.b14.el7.x86_64

[root@localhost ~]# rpm -e java-1.7.0-openjdk-headless java-1.7.0-openjdk java-1.8.0-openjdk-headless java-1.8.0-openjdk –nodeps

Method Two: Remove the high version of java program files

[root@localhost ~]# which java

/usr/bin/java

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

openjdk version "1.8.0_161"

OpenJDK Runtime Environment (build 1.8.0_161-b14)

OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)

[root@localhost ~]#

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

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

 

2, install and configure 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 755 /usr/local/amoeba

 

3, Amoeba arranged separate read and write, read load balancing two Slave

Amoeba configured in Master, Slave1, Slave2 server access authorization

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

Query OK, 0 rows affected (0.00 sec)

 

MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.01 sec)

 

Edit the configuration file amoeba.xml

[root@localhost ~]# cp /usr/local/amoeba/conf/amoeba.xml{,.bak}

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

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

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

 

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

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

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

Edit the configuration file dbServers.xml

[root@localhost ~]# cp /usr/local/amoeba/conf/dbServers.xml{,.bak}

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

                            <!-- mysql port -->

                            <property name="port">3306</property>

                           

                            <!-- mysql schema -->

                            <property name="schema">test</property>

                           

                            <!-- mysql user -->

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

                           

                            <!--  mysql password -->

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

 

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

                   <factoryConfig>

                            <property name="ipAddress">192.168.200.111</property>

                   </factoryConfig>

         </dbServer>

        

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

                   <factoryConfig>

                            <property name="ipAddress">192.168.200.112</property>

                   </factoryConfig>

         </dbServer>

        

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

                   <factoryConfig>

                            <property name="ipAddress">192.168.200.113</property>

                   </factoryConfig>

         </dbServer>

        

         <dbServer name="slaves" virtual="true">

                   <poolConfig class="com.meidusa.amoeba.server.MultipleServerPool">

                            <!-- Load balancing strategy: 1=ROUNDROBIN , 2=WEIGHTBASED , 3=HA-->

                            <property name="loadbalance">1</property>

                           

                            <!-- Separated by commas,such as: server1,server2,server1 -->

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

                   </poolConfig>

         </dbServer>

 

After the configuration is correct, start Amoeba software, the default port is TCP protocol 8066

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

[root@localhost ~]# netstat -anpt |grep :8066

tcp6       0      0 :::8066                 :::*                    LISTEN 

65320/java

 

[root@localhost ~]# netstat -anpt |grep :3306

tcp6 0 0 192.168.200.114:7232 192.168.200.113:3306 established

HED 65320/java          tcp6       0      0 192.168.200.114:36284   192.168.200.112:3306    ESTABLIS

HED 65320/java          tcp6       0      0 192.168.200.114:36280   192.168.200.112:3306    ESTABLIS

HED 65320/java          tcp6       0      0 192.168.200.114:7234    192.168.200.113:3306    ESTABLIS

HED 65320/java          tcp6       0      0 192.168.200.114:6938    192.168.200.111:3306    ESTABLIS

HED 65320/java          tcp6       0      0 192.168.200.114:6936    192.168.200.111:3306    ESTABLIS

HED 65320 / java

 

Client access tests on

[root@client ~]# yum -y install mairadb-devel mariadb

 

You can then access via proxy MySQL

[root@client ~]# mysql -uamoeba -p123456 -h192.168.200.114 -P8066

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MySQL connection id is 1305701886

Server version: 5.1.45-mysql-amoeba-proxy-2.2.0 MariaDB Server

 

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

 

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

 

MySQL [(none)]>

 

Mysql create a table on the main server, it will be automatically synchronized to each slave server, then turn off various functions on the Slave server, insert statements in each test.

 

Primary server

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.04 sec)

 

Two were from the server

MariaDB [(none)]> show databases;

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

| Database           |

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

| information_schema |

| db_test            |

| mysql              |

| performance_schema |

| sampdb             |

| test               |

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

6 rows in set (0.01 sec)

 

MariaDB [(none)]> use db_test;

Database changed

MariaDB [db_test]> show tables;

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

| Tables_in_db_test |

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

| student           |

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

1 row in set (0.00 sec)

 

MySQL [(none)]> stop slave;

Query OK, 0 rows affected (0.10 sec)

 

master

MySQL [(none)]> insert into student values('1','crushlinux','this_is_master');

Query OK, 1 row affected (0.18 sec)

 

slave1

MySQL [(none)]> use db_test

MySQL [(none)]> insert into student values('2','crushlinux','this_is_slave1');

Query OK, 1 row affected (0.07 sec)

 

slave2

MySQL [(none)]> use db_test

MySQL [(none)]> insert into student values('3','crushlinux','this_is_slave2');

Query OK, 1 row affected (0.07 sec)

 

Test read:

In the first test machine 1 results

MySQL [db_test]> select * from student;

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

| id   | name  | address        |

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

|    2 | crushlinux | this_is_slave1 |

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

1 row in set (0.01 sec)

 

In the first test machine twice query results

MySQL [db_test]> select * from student;

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

| id   | name  | address        |

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

|    3 | crushlinux | this_is_slave2 |

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

1 row in set (0.02 sec)

 

In the first three test machine results

MySQL [db_test]> select * from student;

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

| id   | name  | address        |

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

|    2 | crushlinux | this_is_slave1 |

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

1 row in set (0.01 sec)

 

Test writes:

On the Client inserts a statement:

MySQL [(none)]> use db_test

MySQL [(none)]> insert into student values('4','crushlinux','write_test');

 

MySQL [db_test]> select * from student;

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

| id   | name  | address        |

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

|    2 | crushlinux | this_is_slave1 |

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

1 row in set (0.01 sec)

 

MySQL [db_test]> select * from student;

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

| id   | name  | address        |

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

|    3 | crushlinux | this_is_slave2 |

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

1 row in set (0.01 sec)

 

But can not find on the Client, ultimately only be viewed on the Master to the content of this statement, indicating that the write operation on the master server

MySQL [(none)]> select * from student;

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

| id   | name  | address        |

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

|    1 | crushlinux | this_is_master |

|    4 | crushlinux | write_test     |

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

1 row in set (0.00 sec)

Thereby verifying, reading and writing Mysql separation has been achieved, all writes to the current on the primary Master server to avoid synchronization data, all the read operations to the Slave equally from the server, the database is used to share the pressure.

 

Slave functions are enabled on the server from two

MariaDB [db_test]> start slave;

Query OK, 0 rows affected (0.00 sec)

Guess you like

Origin www.cnblogs.com/2567xl/p/11688614.html