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 implements mysql read-write separation + master-slave replication architecture

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

Share

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

I. Environment

System: centos6.5

Mysql version: mysql5.6

Master server: 192.168.1.21

Slave server: 192.168.1.100

Master write slave read

Second, realize mysql master-slave replication.

Add the following under the [mysqld] field in / etc/my.cnf of master:

Server_id=1

Log_bin=mysql-bin

Binlog_format=mixed

Relay-log=relay-bin

Relay-log-index=slave-relay-bin.index

Auto-increment-incremen=2

Auto-increment-offset=1

Then restart the mysql service: service mysqld restart

two。 Add the following under the [mysqld] field in / etc/my.cnf of slave:

Server_id=2

Log_bin=mysql-bin

Binlog_format=mixed

Relay-log=relay-bin

Relay-log-index=slave-relay-bin.index

Auto-increment-incremen=2

Auto-increment-offset=2

Then restart the mysql service: service mysqld restart

3. Then authorize the user in master and view the binary log status information

4. Establish a synchronous connection on the slave side, and execute start slave; to check the status:

Change master to master_host='192.168.1.21',master_user='zhangfei',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=1489

The master-slave replication is successful when you see the two yes in the figure above.

Third, to achieve the separation of reading and writing.

Install Java first

two。 Install amoeba

Download address: wget https://sourceforge.net/projects/amoeba/files/Amoeba%20for%20mysql/3.x/amoeba-mysql-3.0.5-RC-distribution.zip

1) authorize a mysql remote account to amoeba in master

Mysql > GRANT ALL PRIVILEGES ON *. * TO 'amoeba'@'192.168.1.%' IDENTIFIED BY' amoeba' WITH GRANT OPTION

2) decompress the amoeba package:

3) configure dbServers.xml under Amoeba:

Vi / usr/local/amoeba/conf/dbServers.xml

4) replace 192.168.5.10 with 192.168.1.21 in the figure

192.168.5.20 instead of 192.168.1.100

5) Edit amoeba.xml

Vi / usr/local/amoeba/conf/amoeba.xml

6) Edit jvm.properties:

Vim / usr/local/amoeba/jvm.properties

7) start amoeba:

/ usr/local/amoeba/bin/launcher > / var/log/amoeba.log 2 > & 1 &

Amoeba has started successfully at this point.

Fourth, test the separation of reading and writing

1. Turn off master-slave replication when testing: execute stop slave on the slave side

two。 Log in using mysql-uroot-p123456-h292.168.1.21-P8806 and insert a piece of data into the table

3. Log in to master and slave respectively and find that only master has newly inserted data but slave does not.

The write separation test was successful at this time.

4. Log in to the mysql of salve to insert a new piece of data into the table

5. Log in using mysql-uroot-p123456-h292.168.1.21-P8806

6. The newly added data on the slave side is found in the query table.

The read separation test was successful at this time.

So far, mysql master-slave replication + read-write separation is realized.

This article is for the purpose of simple and direct configuration. If you have any questions, you can leave a message.

2 I am

thirty-three

two

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