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

A case study of using amoeba to realize the Separation of read and write in mysql Database

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

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you the use of amoeba to achieve mysql database read-write separation of the case, I hope you will learn something after reading this article, let's discuss it together!

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.

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 #. When connecting to amoeba, the operation table must explicitly specify the database name, that is, using dbname.tablename, and use dbname cannot specify the default database, because the operation will be scheduled to each backend dbserver test1 # set the account and password of amoeba connecting to the backend database server. Therefore, it is necessary to create the user on all back-end databases and authorize the amoeba server to connect 111111 500 # maximum number of connections, default 500500 # maximum number of idle connections 1 # latest number of free connections # set a backend writable database, 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 for replication balance, 2 for weight. 3 means HA. Select 1 slave01 # myslave group member`.

Conf/amoeba.xml:

8066 # set the port for amoeba listening. The default is 8066 127.0.0.1 # configure the listening interface, if not Default listening all IP # needs to use the account set here when the client connects to amoeba (the account password here has nothing to do with the password of amoeba connecting to the backend database server) root 123456 myslave # sets the amoeba default pool. Here, the two options set to writedb master # are logged out by default and need to be uncommented. This is used to specify the two read and write pools slave01 defined earlier.

Bin/launcher:

# 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

After reading this article, I believe you have a certain understanding of "the case of using amoeba to achieve the separation of reading and writing in mysql database". If you want to know more about it, welcome to follow the industry information channel, thank you for reading!

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