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

Mysql master-slave replication and read-write separation

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

Share

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

Lab Topology:

Address assignment:

Client 192.168.1.1

Amoeba 192.168.1.2

Mysql-Master 192.168.1.3

Mysql-slave1 192.168.1.4

Mysql-slave2 192.168.1.5

1. Configure time synchronization

1) install ntp using yum on Master, modify its configuration file / etc/ntp.conf and start the service. Open the iptables exception for udp port 123.

2) execute / usr/sbin/ntpdate 192.168.1.3 on two slave to synchronize time synchronization with Master synchronization.

2. Master-slave replication

Note: the iptables exception of tcp port 3306 is required on all three Mysql databases.

1) configuration of master server Master

Configuration of / etc/my.cnf

Restart the mysqld service

Execute mysql-u root-p to log in to the mysql database and authorize the server

2) configuration of slave server slave (the configuration of two slave servers is the same)

Configuration of / etc/my.cnf

Restart the service (service mysqld restart) and log in to mysql configuration to start slave

Use show slave status\ G to see if the master-slave replication is running properly. Master-slave replication depends on the SQL process and the IO process, and the status of these two processes is "yes", which means that they are running normally.

3. Separation of reading and writing

The separation of Mysql reading and writing can be realized in two ways, based on the internal implementation of program code and based on middleware. The use of Amoeba is one of the methods based on middleware.

1) configuration of Amoeba middleware server

Install jdk

Modify / etc/profile

The execution of source / etc/profile takes effect immediately, and java-version checks to see if the installation is complete.

Install Amoeba

Modify Amoeba configuration file / usr/local/amoeba/conf/amoeba.xml

Modify Amoeba configuration file / usr/local/amoeba/conf/dbServers.xml

Start Amoeba to view the port

So Amoeba middleware needs to open the tcp port 8066iptables exception.

2) all three Mysql need to be authorized to Aomeba (three have the same operation)

4. The client connects to Amoeba. (normally, you should add-P8066 after the command. I later changed the port to 3306, so I don't have to add the port number after it.)

Note: enter the password 'amoeba' password' 123456bpm at the horizontal line, while the password in the command is' chen' password '123456c'.

To sum up, the final effect is:

1) Log in to local mysql to write data on slave. Instead of synchronizing to master;, you can write data on master. You can synchronize it to slave.

2) disable master-slave replication and write data on client. You can see the data on master, but not on slave (because client write data will be written directly to master).

3) after turning off master-slave replication, log in to the local mysql write data on master, and client cannot read the data; on the contrary, log in to local write data on slave, and client can read it (because the client read data is read from slave).

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