In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What is master-slave replication
Master-slave replication is used to establish a database environment exactly the same as the master database, which is called the slave database. The master database is generally a quasi-real-time business database. Single item and asynchronous assignment are supported in the most commonly used mysql databases. During the assignment process, one server acts as the master server and the other server acts as the slave server; at this point the master server writes the update information to a specific binary file. An index of the file is maintained to track log loops. This log can be recorded and sent to updates from the server. When a slave server connects to the master server, the slave server informs the master server to read the location of the last successful update from the server's log file. The slave server then receives any updates from which time it occurs, then locks it and waits for the master server to notify the new update.
Second, the role of master-slave replication
First, to ensure the security of the data; do the hot backup of the data, as a backup database, after the failure of the master database server, you can switch to the slave database to continue to work to avoid the loss of data.
The second is to improve the performance of Iwhite O; with the increasing amount of business in daily production, the access frequency of Ihammer O is getting higher and higher, which cannot be satisfied by a single machine, so it is necessary to store multiple databases at this time, which can effectively reduce the frequency of disk Isign O access and improve the performance of a single device.
The third is the separation of read and write, so that the database can support greater concurrency, which is especially important in the report. As part of the report sql statement is very slow, resulting in table lock, affecting the front desk service. If the foreground uses master and the report uses slave, then the report sql will not cause the foreground lock and ensure the speed of the foreground.
Third, the principle of master-slave replication
Files involved in master-slave replication
Main library: binlog
From the library:
Relaylog Relay Lo
Master.info main library information file
Information about relaylog.info relaylog applications
Three threads involved in master-slave replication
Main library:
Binlog_Dump Thread:
From the library:
SLAVE_IO_THREAD
SLAVE_SQL_THREAD
The specific principle is shown in the figure:
1. Execute the change master to command from the database (connection information of the primary database + starting point of replication)
two。 The above information will be recorded to the master.info file from the database.
3. Execute the start slave command from the database and start the SLAVE_IO_THREAD and SLAVE_SQL_THREAD threads immediately
From the database SLAVE_SQL_THREAD, read the information in the master.info file to obtain the location information of the IP,PORT,User,Pass,binlog from the database SLAVE_IO_THREAD request to connect to the main database, the main database specially provides a MASTER_DUMP_THREAD, which is responsible for interacting with the SLAVE_IO_THREAD SLAVE_IO_THREAD according to the location information of the binlog, request the new binlog master database to send the latest binlog through Binlog_DUMP_Thread Receive the new binlog log to the SALVE_IO_THREADSLAVE_IO_THREAD from the database through the network TP, store it in the TCP/IP cache, immediately return the ACK to the master database, and update the master.info
9.SLAVE_IO_THREAD dumps the data in the TCP/IP cache to the disk relaylog. Slave _ SQL_THREAD reads the information in the relay.info and obtains the location information of the last applied relaylog. SLAVE_SQL_THREAD will play back the latest relaylog according to the last location point, and update the relay.info information again from the database will automatically purge the relay for regular cleaning.
Once the master-slave replication is successfully constructed, new changes take place in the master database, and signals will be sent to SLAVE_IO_THREAD through Binlog_dump_THREAD, which enhances the real-time performance of master-slave replication.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.