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

How to separate read and write from mysql based on amoeba

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

The following brings you about how mysql achieves read-write separation based on amoeba. If you are interested, let's take a look at this article. I believe it will be of some help to you after reading how mysql achieves read-write separation based on amoeba.

Environment:

Host A (huangzp2): 172.16.115.157

Host B (huangzp3): 172.16.115.100

Host C (huangzp4): 172.16.115.87

Description:

Depends on the master-slave structure

Need middleware (connect two independent applications or independent systems to exchange data for them even without the same interface) implementation, such as tomcat, weblogic, database middleware

Mysql proxy supports read-write separation, load balancing and failover. Disadvantages: poor performance, not supporting a large number of forwarding, need to use lua script

Atlas, with poor performance and long corresponding time, does not support configuration loading of dynamic parameters, that is, closing the database first, which is not suitable for online business.

Amoeba, developed and used by Ali, not only supports the separation of read and write, but also supports database partitioning and table operation, which has less performance on the database, because R & D engineers move to Shanda for fear of data leakage.

Cobar, Ali is now using middleware, semi-open source software, with more restrictions)

1. Install mysql and mysql-server on the master-slave machine AB, modify configuration files and authorization, and view status

Yum install-y mysql mysql-server

Master A: modify the configuration file vim / etc/my.cnf, restart, authorize (all permissions, more convenient), status

Grant all privileges on *. * to 'silen'@'%' identified by' 123456'

Description:

From above B: modify configuration file vim / etc/my.cnf, restart, fill in Master.info information, open slave, check status

Lord A:

From the top B:

two。 Authorization is also required from above to allow middleware access.

Grant all privileges on *. * to 'silen'@'%' identified by' 123456'

3. Middleware CVM settings

3.1 Environment:

(1) install the gcc environment first

Yum install-y gcc*

(2) need to obtain the amoeba main program: amoeba-mysql-1.3.1-BETA.zip

Download link: http://101.110.118.21/jaist.dl.sourceforge.net/project/amoeba/Amoeba%20for%20mysql/amoeba-mysql-1.3.1-BETA.zip

(3) installation package of java: jdk-7u40-linux-x64.tar.gz

Download link:

Http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html

3.2 configure global variables

3.2.1 create the / amoeba directory and extract the java to this directory

Mkdir / amoeba

Tar-zxvf jdk-7u40-linux-x64.tar.gz-C / amoeba/

3.2.2 the title of the directory is long, just make a soft link.

Ln-s jdk1.7.0_40/ jdk

3.2.3 Editing global variables

Vim / etc/profile configure java option (everything in java needs to be declared)

JAVA_HOME=/amoeba/jdk

Export JAVA_HOME

PATH=$JAVA_HOME/bin:$PATH

Export PATH

CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH

Export CLASSPATH

Description:

JAVA_HOME represents the directory location of java and is set to a global variable so that other shell can also use the

Tool scripts under the java directory are added to system environment variables to facilitate command execution and upgrade to global variables

CLASSPATH represents the environment variable of the library of the java class, adding the tool.jar,dt.jar under the current directory. Java to the variable (separated by colon under Linux and semicolon under Windows), and also upgraded to global variable

3.2.4. Refresh the global variable file

Source / etc/profile

3.2.5 verify that java is available

3.3 install and configure amoeba

3.3.1 extract to / usr/local/amoeba directory

Unzip amoeba-mysql-1.3.1-BETA.zip-d / usr/local/amoeba

3.3.2 add command execution permissions to facilitate command invocation

Chmod-R + x / usr/local/amoeba/bin/

3.3.3 modify the amoeba main configuration file

Vim / usr/local/amoeba/conf/amoeba.xml

... (CVM performance section settings)

a. Find:

To annotate, change amoeba's CVM (middleware) ip to:

172.16.115.87

b. Find:

To uncomment, change the root login password of amoeba to 123456:

123456

(amoeba, each database CVM corresponds to a dbServer) (set in the database CVM list section)

a. Find the following:

127.0.0.1

Change the ip address to the ip of primary one (port and database name can default to 3306, test):

172.16.115.157

b. Find:

Root

Change the user name to the authorized zhangshan:

Silen

c. Find:

Remove the comments and change the password to 123456:

123456

d. Find:

Change the name of the dbserver pool to master (define which of the following server belong to the master pool to expand the CVM):

e. Find:

Server1

If there are more primary CVMs in the master pool, such as server1 (already in the master pool), server2, and server3, modify them to:

Server1,server2,server3

f. Since there are two database CVMs and the primary CVM has been set up, you need to copy the dbServer of the master CVM as a template to modify the slave CVM dbServer

Copy (64-109 lines) and paste in. Within the scope:

...

(1) modify the name of dbServer to server2:

DbServer name= "server2"

(2) change the ip address to 192.168.9.252:

172.16.115.100

(3) next, change the name of the pool to slave:

(4) change the server CVM name under the slave pool to server2:

Server2

Finally, jump out:

a. Find:

Server1

Change the name of a single CVM to the name of the pool (if there are multiple hosts, poll and assign them in turn) as the default access CVM:

Master

b. Find:

Remove the comments, change the write pool to master, and the read pool to slave:

Master

Slave

3.4 View and edit the execution script file for amomeba:

Vim / usr/local/amoeba/bin/amoeba

a. Find:

DEFAULT_OPTS= "- server-Xms256m-Xmx256m-Xss128k"

Modified to:

DEFAULT_OPTS= "- server-Xms256m-Xmx256m-Xss256k"

3.5 start the amoeba program and view the process

Description: the nohup command indicates that if you start it in the background, it can run even if you use a remote connection and the remote connection is cut off.

Nohup bash-x / usr/local/amoeba/bin/amoeba &

4. Middleware CVM, install mysql, do not need to install mysql-server, log in to amoeba

Description: the user is the user and password specified in the configuration file. The default port is 8066. The actual login middleware calls the mysql on the master-slave service. The mysql installed here is just a login tool.

Yum install mysql-y

Mysql-u root-p123456-h272.16.115.87-P 8066

Test: in the actual production environment, there is no need for operation!

Disable the slave slave, that is, stop slave, and create an A1 table in the test library on the master and slave CVM (the table name needs to be the same because it is the master-slave), and insert a data master and slave, respectively.

Lord:

From the top:

Conclusion: the middleware looks at the data in the A1 table, and repeated queries are all slave, indicating that the query data is obtained from the cloud server.

Middleware, insert a data amoeba into A1 table

Conclusion: amoeba data is seen in the A1 table on the primary cloud server, indicating that the write data is written in the primary cloud server.

Lord:

From the top:

Finally, delete the tb1 table in the test library on the master and slave respectively, and open slave from the top.

Read the above details about how mysql achieves read-write separation based on amoeba, and whether there is anything to gain. If you want to know more about it, you can continue to follow our industry information section.

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