MySQL ---- separate read and write

MySQL ---- separate read and write

A: Principle

  • Separate read and write is only on the primary server to write, read-only from the server

  • The main transactional database query processing, and the processing select from a database query

  • Database replication is used to query the transaction due to changes sync to the cluster from the database

Two: Amoeba definition

  • Amoeba is a MySQL to as the underlying data store, and MySQL applications Proxy protocol interface. It is concentrated in response to the application request, the user according to the rules set in advance, the SQL execution request to a specific database. Based on this load balancing can be achieved, separate read and write, and high availability requirements.
  • Amoeba SQL requests corresponding to a router, for the purpose of load balancing, separate read and write, provides a mechanism for high availability, they are not fully realized. It requires a combination of MySQL Replication and other mechanisms to achieve replica synchronization.

To download the installation package:

After you copy the contents of this open Baidu network disk phone App, oh operation more convenient link: https: //pan.baidu.com/s/1kRkbem91iPxeQ-bZUObTxg extraction code: bg88

Three: Experimental configuration

[Pictures of foreign chains dump fails, the source station may have a security chain mechanism, it is recommended to save the picture down directly upload (img-mkkcnnSm-1578915582717) (C: \ Users \ xumin \ AppData \ Roaming \ Typora \ typora-user-images \ 1578914254089.png)]

1, Environment Description

  • Prepare three Mysql servers (one master server, a slave server)

  • A Amoeba, for separate read and write

  • As a client validation

Mysql replication master from the read and write functions are closely related, is achieved by copying data from a master synchronization, and then to enhance the load capability database concurrency by separate read and write.

2. Experimental Procedures

  • Amoeba server configuration
[root@localhost ~]# hostnamectl set-hostname amoeba
[root@localhost ~]# su        '修改主机名'
[root@amoeba ~]# systemctl stop firewalld.service 
[root@amoeba ~]# setenforce 0         ‘关闭防火墙’
[root@amoeba ~]# mkdir /abc
[root@amoeba ~]# mount.cifs //192.168.10.24/share /abc     ‘挂载软件包’
  • Installation Management jdk
[root@amoeba abc]# cp jdk-6u14-linux-x64.bin /usr/local/   ‘复制jdk-6u...到/usr/local下’
[root@amoeba abc]# cd /usr/local/    ‘查看是否复制到’
[root@amoeba local]# ./jdk-6u14-linux-x64.bin     ‘执行jdk’ 

After input yes, wait a few moments, the installation can be completed.

[Pictures of foreign chains dump fails, the source station may have a security chain mechanism, it is recommended to save the picture down directly upload (img-0aQDJ8AU-1578915582718) (C: \ Users \ xumin \ AppData \ Roaming \ Typora \ typora-user-images \ 1578900149083.png)]

  • For ease of administration, will be renamed jdk package name
[root@amoeba local]# mv jdk1.6.0_14/ /usr/local/jdk1.6
  • Modify the profile file
[root@amoeba local]# vim /etc/profile           ‘在末尾添加’

export JAVA_HOME=/usr/local/jdk1.6
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/bin
export AMOEBA_HOME=/usr/local/amoeba
export PATH=$PATH:$AMOEBA_HOME/bin

Here Insert Picture Description

  • The environment variables to take effect
[root@amoeba local]# source /etc/profile
  • Create a directory amoeba
[root@amoeba local]# mkdir /usr/local/amoeba
  • Unzip the package amoeba
[root@amoeba abc]# tar zvxf amoeba-mysql-binary-2.2.0.tar.gz -C /usr/local/amoeba/
  • Give authority to verify that the installation was successful
[root@amoeba abc]# chmod -R 755 /usr/local/amoeba/
[root@amoeba abc]# /usr/local/amoeba/bin/amoeba
amoeba start|stop       ‘表示安装成功’
  • In the mysql server is equipped with three add permissions to allow access amoeba
mysql> grant all on *.* to test@'192.168.34.%' identified by '123';
  • Configuring separate read and write functions on the server amoeba
[root@amoeba abc]# cd /usr/local/amoeba/conf
[root@amoeba conf]# vim amoeba.xml

Here Insert Picture Description

[root@amoeba conf]# vim dbServers.xml

[Pictures of foreign chains dump fails, the source station may have a security chain mechanism, it is recommended to save the picture down directly upload (img-8Lns3LuI-1578915582720) (C: \ Users \ xumin \ AppData \ Roaming \ Typora \ typora-user-images \ 1578907959006.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Rr53T8FN-1578915582721)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1578908339266.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ON2giJxj-1578915582722)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1578908457552.png)]

  • Start amoeba, the process in the background, a long time to wait
[root@amoeba conf]# /usr/local/amoeba/bin/amoeba start &

Four: the Client (client) test

1, modify the host name, turn off the firewall
[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# setenforce 0
[root@localhost ~]# hostnamectl set-hostname client
[root@localhost ~]# su
2, direct installation mysql service
[root@client ~]# yum install mysql -y
3, the server connecting amoeba
[root@client ~]# mysql -u amoeba -p123 -h 192.168.34.182 -P8066

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-uvxo3JSB-1578915582722)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1578913503733.png)]

4, in the main view from the server, you can see info table

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-R7v23sd4-1578915582723)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1578912475988.png)]

5, two closed from the server, view status, two NO

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Qgj718mN-1578915582723)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1578912847699.png)]

6, after closing the service, insert a message in the info table in the client, you can view the main server

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-BCF2LoDd-1578915582724)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1578912992342.png)]

7, viewing the table information from the server and not the client, enabling the separate read and write

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pRNNVDZT-1578915582725)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1578913209129.png)]

8, two from each add a data service

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2hxYxyWt-1578915582726)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1578913792556.png)]

9, the client info View the table of contents, one by one to read the information in the table

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-eZBnuybf-1578915582726)(C:\Users\xumin\AppData\Roaming\Typora\typora-user-images\1578914005399.png)]

After the client data connection to the database server writes only the main record, it does not record from the server. Turn on the main, the case will sync from sync (copy) from the server to the primary server. (As do the master-slave synchronization, each is the same data from the server and the main server). At high concurrent requests, achieving load balancing to ensure the efficient operation of data security, server.

Published 60 original articles · won praise 11 · views 2122

Guess you like

Origin blog.csdn.net/XuMin6/article/details/103963204