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

The method of using amoeba to realize the Separation of read and write in mysql Database

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article will explain in detail the method of using amoeba to achieve the separation of reading and writing in mysql database. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

There are many read-write separation architectures about mysql, and almost all of Baidu's words are implemented in mysql_proxy. Because proxy is based on lua scripting language, many netizens on the Internet say that proxy is inefficient and unstable, and it is not recommended to use it in production environment.

Amoeba is a database read-write separation project developed by Ali (read-write separation is only a small function of it). Since it is written based on java, the running environment needs to install jdk.

Related tutorials: mysql Video tutorial

Preparatory work:

1. Two databases, one master and one slave, master-slave synchronization

Master: 172.22.10.237 3306; the main library is responsible for the write operation

Slave: 10.4.66.58 3306; read from the library

Amoeba: 172.22.10.237 amoeba 8066; I installed amoeba on the server where the main library is located, of course, you can also install it on the third server

All server operating systems are centos7

two。 Configure and install jdk on the same server as amoeba

I installed jdk1.8.

The path is: JAVA_HOME=/usr/local/java/jdk1.8.0_131

The above must be built and configured on your own, the master and slave work normally, and add the jdk environment variable: / etc/profile

There are many ways to install amoeba, so it's not a waste of breath here. I downloaded the amoeba-mysql-3.0.5-RC-distribution installation package and decompressed it directly to use it.

Extract the directory: / usr/local/amoeba/

Obviously, there are configuration files in conf and startup programs in bin.

I just mentioned that amoeba can do more than read-write separation, but if you only use read-write separation, you only need to configure these files: conf/dbServers.xml conf/amoeba.xml and bin/launcher.

Conf/dbServers.xml:

`3306 # set the port of the mysql database to be connected by Amoeba. The default is 3306 testdb # 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 database. Because the operation will dispatch to each backend dbserver test1 # to set the account and password for amoeba to connect to the backend database server, it is necessary to create the user on all backend databases and authorize the amoeba server to connect 111111 500 # maximum number of connections Default 500500 # maximum idle connections 1 # latest idle connections # set a backend writable database, which is defined here as writedb, which can be named arbitrarily Later, we will use 172.22.10.237 # to set the ip of the backend writable dbserver # set the backend readable database 10.4.66.58 # setting to define a virtual dbserver, which is actually equivalent to a dbserver group. Here, the readable database ip is uniformly put into a group, and the name of this group is myslave 1 # selection scheduling algorithm. 1 indicates replication equilibrium, 2 indicates weight, and 3 indicates HA. Here, select 1 slave01 # myslave group member`

Conf/amoeba.xml:

# start the script, you need to configure the jdk environment variable; # add: JAVA_HOME=/usr/local/java/jdk1.8.0_131 on the first line after the comment

Launcher is a startup script. If you do not configure JAVA_HOME, you may get an error even if you configure the environment variable in / etc/profile: the jdk environment variable is not configured

There is also a configuration file: jvm.properties

# memory usage profile #-Xss parameter must be greater than 228 to start JVM # modify: JVM_OPTIONS= "- server-Xms1024m-Xmx1024m-Xss256k-XX:PermSize=16m-XX:MaxPermSize=96m"

Experienced operators know that anything that has anything to do with jdk is basically related to memory tuning, and amoeba is no exception.

Now you can start:

After startup, you can see port 8066 of this machine:

At this point, you only need to connect to the database through port 8066 of the local ip and the account password set in your configuration file. The written data will be sent to the master, and the read data will be read from the slave.

Test:

Close the master database and still read: execute the select view command

Or

If you close the slave database, you can still write: execute update, inster commands

On the use of amoeba to achieve the separation of mysql database read and write method to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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