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

Synchronization and Separation of MySQL Master and Slave

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

Share

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

Description:

In the actual production environment, if the read and write of the database are operated in the same database server, it can not meet the actual needs in terms of security, high availability, high concurrency and so on. Generally speaking, it is deployed and implemented through master-slave replication to synchronize data, and then through read-write separation to improve the concurrent load capacity of the database.

There is a close relationship between the master-slave replication of MySQL and the read-write separation of MySQL. First of all, master-slave replication must be deployed. Only when the master-slave replication is completed, can the data read-write separation be carried out.

.

.

The topology of the server used in the simulation build is as follows

.

.

The experimental environment is as follows:

The server installs the MySQL5.5 version

.

.

Download address of the lab package:

Link: https://pan.baidu.com/s/16n0zJBGeB3iGyRvXzxL5xA password: tcsn

.

.

The experimental steps are as follows:

.

.

1. On the primary server

First turn off the firewall and check whether ntp is installed, which is installed by default

Systemctl stop firewalld.service

Setenforce 0 # turn off the firewall

Rpm-Q ntp # check if ntp is installed

.

.

2. Enter the configuration file to configure

Vim / etc/ntp.conf

Server 127.127.200.0 # Local clock source

Fudge 127.127.200.0 stratum 8 # sets the time level to 8

Systemctl start ntpd # start clock source

.

.

3. Next, do the same thing from server 1 and from service 2

Systemctl stop firewalld.service

Setenforce 0 # turn off the firewall

Systemctl start ntpd # start clock source

/ usr/sbin/ntpdate 192.168.200.133 # synchronize time to master

.

.

4. Go back to the primary server

Vim / etc/my.cnf # for configuration files

Server-id = 11 # server number

.

Log-bin=master-bin # change log name for easy distinction

Log-slave-updates=true # allows synchronization of master server log files from server log files

.

.

5. Access to the database

GRANT REPLICATION SLAVE ON. TO 'myslave'@'192.168.200.%' IDENTIFIED BY' 123123 permissions; # Grant permissions

FLUSH PRIVILEGES; # refresh, effective immediately

Show master status; # View log file name

.

.

6. Back to the slave server, the two slave servers do the same thing.

Vim / etc/my.cnf # for configuration files

Server-id = 22 # change the port number. Note that the port number of slave server 2 cannot be the same as master and slave server 1

Relay-log=relay-log-bin # specifies the slave server log file

Relay-log-index=slave-relay-bin.index # specify file name and location

Systemctl restart mysqld.service # restart the database

.

.

7. Access to the database

Change master to master_host='192.168.200.133',master_user='myslave',master_password='123123',master_log_file='master-bin.000001',master_log_pos=339; # give credential

Start slave; # enable slave server identity

Show slave status\ G; # View synchronization status

Slave_IO_Running: Yes

Slave_SQL_Running: Yes # shows that yes shows that synchronization has started

.

.

8. At this point, you can create a new database in the main server database to verify whether it is synchronized.

Synchronization succeeded

.

.

After the master-slave synchronization is done, the following read-write separation operation is performed.

.

.

1. To enter the proxy server-amoeba, first of all, it is the same step.

Systemctl stop firewalld.service

Setenforce 0 # turn off the firewall

Mkdir / ooo # creates a directory and mounts it with

Mount.cifs / / 192.168.200.1/gx / ooo/ # Mount files into a directory

Cd / ooo/ # enter the directory

Cp jdk-6u14-linux-x64.bin / usr/local/ # is copied to the system file so that the system can recognize

Cd / usr/local/

. / jdk-6u14-linux-x64.bin # install the java environment package

.

.

2. Move or copy files to the / usr/ directory

Mv jdk1.6.0_14/ / usr/local/jdk1.6 # moved to the system file

Vim / etc/profile # goes to the configuration file and adds the following environment variable at the end. The system can use the commands and functions in the installation file:

Export JAVA_HOME=/usr/local/jdk1.6

Export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib

Export PATH=$JAVA_HOME/lib:$JAVA_HOME/jre/bin/:$PATH:$HOME/bin

Export AMOEBA_HOME=/usr/local/amoeba

Export PATH=$PATH:$AMOEBA_HOME/bin

Source / etc/profile # refresh takes effect

.

.

3. Extract the file to the specified directory

Mkdir / usr/local/amoeba # create a folder

Cd / ooo/

Tar zxvf amoeba-mysql-binary-2.2.0.tar.gz-C / usr/local/amoeba/ # unzip the compressed file to this directory file

.

.

4. Give relative permissions to files

Chmod-R 755 / usr/local/amoeba/

/ usr/local/amoeba/bin/amoeba

Amoeba start | stop # indicates successful installation

.

.

5. Add permissions on three MySQL to open to amoeba access

Grant all on. To 'test'@'192.168.201.%' identified by' 123123 visit three databases using test account

.

.

6. Then go back to the proxy server and operate the configuration file

Cd / usr/local/amoeba

Vim conf/amoeba.xml

30 lines-

Root # change user name

Line 32-

123123 # password

Line 115-117-

Master # maximum permissions to master

Master # write permission to master

Slaves # read permission

.

.

7. Go to the next configuration file for configuration

Vim conf/dbServers.xml

-- 26MUR 29MUR-remove comments

Test # login identity

123.com # login password

-- 42-47MW-main server

< dbServer name="master" parent="abstractServer">

# the main service is master

< property name="ipAddress">

192.168.201.131 # Master server ip address

-- 50-54 won-from server 1

< dbServer name="slave1" parent="abstractServer">

# from Server 1

192.168.201.129 # ip address

Copy 6 lines to do from service 2

-- 63 Murray-

< dbServer name="slaves" virtual="true">

# from the server pool

-- 70 murmurs.

Slave1,slave2 # defines two slave services

.

.

8. At this point, you can start the service.

/ usr/local/amoeba/bin/amoeba start& # enable amoeba service

.

.

9. Enter the client

Systemctl stop firewalld.service

Setenforce 0 # turn off the firewall

Yum install mysql-y # install the MySQL command

.

.

10. MySQL-u amoeba-p123123-h 192.168.200.131-P8066 # Log in to the cluster database

.

.

At this point, the slave server can only read the master server, and the client can read the slave server and write to the master server.

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