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

Amoeba realizes the separation of database read and write

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

Share

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

Environment and software version:

System: CentOS Linux release 7.2.1511 (Core)

Mysql:Server version: 5.6.33

Amoeba:amoeba-mysql-3.0.5-RC-distribution

JDK:1.7.0_80-b15 (jdk is required for Amoeba to run)

Second, install Amoeba:

1 download the required software:

Lsamoeba-mysql-3.0.5-RC-distribution.zip jdk-7u80-linux-x64.rpm

2 install jdk

Yum-y install jdk-7u80-linux-x64.rpm# java-version java version "1.7.0o80" Java (TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot (TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

3 decompress Amoeba

Unzip amoeba-mysql-3.0.5-RC-distribution.zip # mv amoeba-mysql-3.0.5-RC / usr/local/amoeba # mv amoeba-mysql-3.0.5-RC / usr/local/amoeba # cd / usr/local/amoeba/conf/ # vim amoeba.xml3306 # set the port for amoeba listening The default is 8066 10.0.0.159 # set the ip address of amoeba listener root # set the user connecting to amoeba 123456 # set the password to connect to amoeba # (the account password here has nothing to do with the password of amoeba connecting to the backend database server) master # set amoeba default pool, here set to matster # these two options are logged out by default and need to be uncommented This is used to specify the write library and read library master multiPool # this is given to a group, if there are multiple dbServers in this group, it can be load balanced. This group is set in dbServers.xml

Set the information of the mysql library in the dbServers.xml file in the current directory

Vim dbServers.xml # set the port 3306 of amoeba to connect to the backend mysql # set the default database. When connecting to amoeba, the operation table must explicitly specify the database name, that is, in the way of dbname.tablename, use dbname is not allowed to specify the default library. Because the operation will be dispatched to each backend dbserver test # set the user name and password of the amoeba connection backend mysql amoeba 123456 # set a backend dbServer, here set the connection writable master library, this name can be customized, but it needs to be the same as the name called in amoeba.xml. # ip address of backend mysql 10.0.0.176 # set a backend dbServer, where the connection readable salve is set. This name can be customized, but it needs to be the same as the name called in amoeba.xml. # ip address of backend mysql 10.0.0.193 # define a dbserver group # # Select scheduling algorithm, 1 for polling load balancer, 2 for weight, 3 for HA Select 1 1 slave # group members here, separated by commas when there are multiple

Three mysql authorizes amoeba users to log in (here my two mysql servers master and slave have done master-slave synchronization and have verified it successfully. If you need to do master-slave synchronization, please see https://blog.51cto.com/zengzeyang/1911173)

Authorization on master:

Mysql > grant select,insert,update,delete on. To 'amoeba'@'10.0.0.%' identified by' 123456'

Mysql > flush privileges

Authorization on slave:

Mysql > grant select on. To 'amoeba'@'10.0.0.%' identified by' 123456'

Mysql > flush privileges

Note: the password of the authorized user here should be the same as that configured in dbServers.xml. If your mysql enables all master-slave synchronization, the users you authorize on the master will synchronize to the slave library. The solution is: 1 to reduce the rights on the slave library; 2. Do not allow the mysql library to synchronize when the master-slave synchronization occurs.

Fourth, start amoeba:

# cd / usr/local/amoeba/bin

Vim launcher add JAVA_HOME:

JAVA_HOME=/usr/java/jdk1.7.0_80

# cd / usr/local/amoeba/ # vim jvm.properties modify VM_OPTIONS: JVM_OPTIONS= "- server-Xms1024m-Xmx1024m-Xss256k-XX:PermSize=16m-XX:MaxPermSize=96m" # / usr/local/amoeba/bin/launcher 2018-01-02 23:34:21 [INFO] Project Name=Amoeba-MySQL, PID=48981, starting... Log4j:WARN log4j config load completed from file:/usr/local/amoeba/conf/log4j.xml 2018-01-02 23 Amoeba for Mysql current versoin=5.1.45- mysql-amoeba-proxy-3.0.4-BETAlog4j:WARN ip access config load completed from file:/usr/local/amoeba/conf/access_list.conf2018 3415 INFO context.MysqlRuntimeContext-Amoeba for Mysql current versoin=5.1.45- mysql-amoeba-proxy-3.0.4-BETAlog4j:WARN ip access config load completed from file:/usr/local/amoeba/conf/access_list.conf2018-01-02 23 24 INFO net.ServerableConnectionManager-Server listening on / 10.0.0.159 3306. # launched successfully # ss-tanlp LISTE 128:: ffff:10.0.0.159:3306:: *

Five tests: connect to amoeba with another mysql client. During the test, I paused the master-slave synchronization to see the effect more directly.

Mysql-uroot-p123456-h20.0.0.159

Add a piece of data to the main database

Add a piece of data from the library

Back to the client verification of the mysql connection:

Can only view the data from the library, indicating that it is basically successful, further verification, and insert a piece of data in the client.

And the client did not query the newly inserted data from the slave database, so go back to the master database to confirm:

After the verification is successful, master-slave synchronization can be enabled to achieve read-write separation (before starting synchronization, please clean up the differential data by yourself so that the master-slave can run normally)

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