Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Set up MySQL read-write separation (with source code package included)

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Introduction to Amoeba

Amoeba (amoeba) project, the open source framework began to release an Amoeba for Mysql software in 2008. This software is dedicated to MySQL's distributed database front-end proxy layer. It mainly acts as a SQL routing function when the application layer accesses MySQL and focuses on distributed database proxy layer (Database Proxy) development. Located between Client and DB Server (s), transparent to the client. With load balancing, high availability, SQL filtering, read and write separation, routing to the target database, concurrent requests for multiple database merge results. Through Amoeba, we can achieve the functions of high availability, load balancing and data slicing of multiple data sources. at present, Amoeba has been used in the production line of many enterprises.

Read-write separation schematic diagram

Experimental environment

Related package link: https://pan.baidu.com/s/1TANw0pEGgnxgEfGNU9hsGQ password: 0s4h

Experimental objectives:

Successful construction of mysql read-write separation

Experimental procedure

First, build master-slave replication first. Refer to https://blog.51cto.com/13760351/2173559.

2. Configure amoeba service

1. Turn off the firewall, security

Setenforce 0systemctl start firewalld.service

two。 Install the java environment on the host amoeba

Cp jdk-6u14-linux-x64.bin / usr/local/ # copy the jdk package to the Linux system cd / usr/localchmod + x jdk-6u14-linux-x64.bin # gives execute permission. / jdk-6u14-linux-x64.bin # execute jdk, type yes, and then press entermv jdk1.6.0_14/ / usr/local/jdk1.6 # to move the jdk software to this directory

3. Configure system environment variables

Vim / etc/profile # configure the system environment variable export JAVA_HOME=/usr/local/jdk1.6export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/libexport PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/binexport AMOEBA_HOME=/usr/local/amoebaexport PATH=$PATH:$AMOEBA_HOME/bin

Source / etc/profile # refresh to enable system environment variables to take effect

4. Install and configure amoeba softwar

Mkdir / usr/local/amoeba tar zxvf amoeba-mysql-binary-2.2.0.tar.gz-C / usr/local/amoeba/chmod-R 755 / usr/local/amoeba/ # Grant permissions / usr/local/amoeba/bin/amoeba # start amoeba

5. Configure amoeba read-write separation

(1) add permissions to master,slave1,slave2 and open them to amoeba access

Grant all on *. * to test@'192.168.65.%' identified by '123.com'

(2) Edit amoeba.xml configuration file

Cd / usr/local/amoeba # back to amoeba server vim conf/amoeba.xml

(3) Edit dbServers.xml configuration file

Vim conf/dbServers.xml

(4) start the amoeba software

/ usr/local/amoeba/bin/amoeba start&netstat-anpt | grep java

III. Test the client

Install the mysql client

Yum install-y mysql

two。 Access mysql through proxies

Mysql-u amoeba-p123456-h 192.168.65.162-P8066

3. Create a table on MASTER

Mysql-u root-pmysql > use hhhh;Mysql > create table zz (id int (10), name varchar (10), address varchar (20))

4. Insert data on the primary server

Insert into zz values ('1century, recording, writing, mastery, etc.)

5. Insert data from server 1

Insert into zz values ('2century, recording, etc.)

6. Insert data from server 2

Insert into zz values ('3century, recording, etc.)

7. Test on the client

8. Insert data on the client

Insert into zz values ('5times, recording, writing, writing, testing, etc.)

The inserted statement cannot be queried on the client side, but can only be seen on the master, proving that the write operation is on the master server.

9. View on the master server

It is verified that the data written after connecting to the database through the client is in master, and then synchronized to the slave1,slave2, and all read operations are allocated to the slave slave server to share the pressure on the database.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report