


MariaDB database is installed and configured based on GTID master-slave synchronous replication
Aug 09, 2024 pm 01:32 PMOperating system: CentOS Linux release 7.3.1611 (Core)
Database:MariaDB-10.2.6-linux-glibc_214-x86_64
Main server:10.10.10.56
Slave server:10.10.10.163
1. What we need to do today is one-way master-slave synchronization
For information on MariaDB (MySQL) database installation, please refer to "Centos7.3 x64-bit binary installation (MySQL) MariaDB 10.1.20 database production". Next, the configuration process of the MariaDB (MySQL) server cluster begins.
2. Modify or add the following information in the MariaDB (MySQL) configuration file
vim /etc/my.cnf 主從通用配置 binlog-format = mixed #二進制日志記錄的模式(高版本默認開啟) binlog-checksum = CRC32 #可使主機為寫入二進制日志的事件寫入校驗(高版本默認開啟) sync-master-info = 1 #MariaDB依靠操作系統(tǒng)將master.info文件刷新到磁盤。 sync_relay_log_info = 1 #MariaDB依靠操作系統(tǒng)將relay-log.info文件刷新到磁盤。 expire_logs_days = 7 #日志文件過期天數(shù),默認是 0,表示不過期 master-verify-checksum = 1 #主服務器效驗 slave-sql-verify-checksum = 1 #從服務器效驗
3. In addition to the general configuration, the main server Master also needs to add the following code
server-id = 56 #MySQL服務器ID,不重復 log-bin = mysql-bin #二進制日志(默認開啟) sync-binlog = 1 #主服務器進行設置,用于事務安全 log-bin-index = mysql-bin
4. In addition to the general configuration, the slave server Slave also needs to add the following code
server-id = 163 relay-log = relay-bin #中繼日志 slave-parallel-threads = 2 #設定從服務器的SQL線程數(shù) #replicate-do-db = renwoleblogdb#復制指定的數(shù)據(jù)庫,多個寫多行 replicate-ignore-db = mysql #不備份的數(shù)據(jù)庫,多個寫多行 relay_log_recovery = 1 #從站崩潰后可以使用,防止損壞的中繼日志處理。 log-slave-updates = 1 #slave將復制事件寫進自己的二進制日志 relay-log-index = relay-bin
In addition, it is not necessary to enable the binary log on the Mysql slave server, but in some cases, it must be set. For example, if the slave is the master of another slave, bin_log must be set. I leave it on by default here.
5. The above is just a brief introduction to the role of each parameter. The specific settings of these parameters need to be adjusted according to the actual situation of the user. For details, please go to the official website
《復制和二進制日志服務器系統(tǒng)變量》 https://mariadb.com/kb/en/mariadb/replication-and-binary-log-server-system-variables/ 關于系統(tǒng)變量的兼容性,可參閱官方 《MariaDB與MySQL兼容性》 https://mariadb.com/kb/en/mariadb/mariadb-vs-mysql-compatibility/
6. Main server Master authorization configuration
Create a dedicated account on the main MariaDB server and authorize database permissions, as well as remote access from the server IP
# mysql -uroot -p Enter password:【輸入你的MySQL密碼回車】 MariaDB [(none)]> GRANT REPLICATION SLAVE ON *.* TO 'renwoleuseracc'@'%' IDENTIFIED BY 'renwoleuserpass'; //創(chuàng)建Slave專用備份賬號 MariaDB [(none)]> flush privileges; //刷新MySQL權限 MariaDB [(none)]> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; //查看授權情況 MariaDB [(none)]> flush tables with read lock; //鎖定數(shù)據(jù)庫防止master值變化 MariaDB [(none)]> show master status; //獲取master狀態(tài)值 +-----------------+----------+------------+-----------------+ | File |Position |Binlog_Do_DB|Binlog_Ignore_DB | +-----------------+----------+------------+-----------------+ | mysql-bin.000006| 627 | | | +-----------------+----------+------------+-----------------+ 1 row in set (0.00 sec)
7. Once you have obtained the correct Binlog location (file name and offset) during backup, you can use the BINLOG_GTID_POS() function to calculate the GTID
MariaDB [(none)]> SELECT BINLOG_GTID_POS("mysql-bin.000006", 627); +------------------------------------------+ | BINLOG_GTID_POS('mysql-bin.000006', 627) | +------------------------------------------+ | 0-56-4 | +------------------------------------------+ 1 row in set (0.01 sec)
8. Configure from server Slave
As the official said, starting from MariaDB version 10.0.13, mysqldump will automatically complete this work and write the GTID in the export file. Just set –master-data or –dump-slave and set –gtid at the same time.
In this case, the new SLAVE can set the starting position of replication by setting the value of @@gtid_slave_pos, use CHANGE MASTER to pass this value to the main library, and then start replication:
# mysql -uroot -p Enter password:【輸入你的MySQL密碼】 MariaDB [(none)]> SET GLOBAL gtid_slave_pos = "0-56-4"; MariaDB [(none)]> change master to master_host='10.10.10.56',MASTER_PORT = 3306,master_user='renwoleuseracc',master_password='renwoleuserpass',master_use_gtid=slave_pos; //進行主從授權 MariaDB [(none)]> START SLAVE; //啟動Slave MariaDB [(none)]> show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.10.10.56 Master_User: renwoleuseracc Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.000006 Read_Master_Log_Pos: 627 Relay_Log_File: relay.000035 Relay_Log_Pos: 537 Relay_Master_Log_File: mysql-bin.000006 Slave_IO_Running: Yes Slave_SQL_Running: Yes ... ... ... Using_Gtid: Slave_pos Gtid_IO_Pos: 0-56-4
9. If both Slave_IO_Running and Slave_SQL_Running are YES, it indicates that the slave service is running. The Using_Gtid column determines whether the GTID value is consistent.
Description:
master_host 表示master授權地址 MASTER_PORT MySQL端口 master_user 表示master授權賬號 master_password 表示密碼 master_use_gtid GTID變量值
10. Next unlock the main server database table
MariaDB [(none)]> unlock tables; //解鎖數(shù)據(jù)表 MariaDB [(none)]> show slave hosts; //查看從服務器連接狀態(tài) MariaDB [(none)]> show global status like "rpl%"; //查看客戶端
11. View all relevant parameters of relay from the server Slave
MariaDB [(none)]> show variables like '%relay%';
12. The master-slave configuration has been completed. Now, no matter what is added, modified, deleted, or checked on the master server, it will be synchronized to the slave server. You can perform relevant tests according to your own needs.
About master slave reset syntax
Reset the core syntax of master
RESET MASTER; means that executing RESET MASTER will delete all binary log files and create a blank binary log file with a numeric suffix of .000001. RESET MASTER will not affect the working status of the SLAVE server, so executing this command will cause Slave The Master's binlog cannot be found, causing synchronization to fail.
Reset slave’s core syntax
RESET SLAVE; means; RESET SLAVE will clear the synchronization position on the slave and delete all old synchronization relay log files, but the slave service must be stopped before resetting (STOP SLAVE)
The above is the detailed content of MariaDB database is installed and configured based on GTID master-slave synchronous replication. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Integrating Postman applications on CentOS can be achieved through a variety of methods. The following are the detailed steps and suggestions: Install Postman by downloading the installation package to download Postman's Linux version installation package: Visit Postman's official website and select the version suitable for Linux to download. Unzip the installation package: Use the following command to unzip the installation package to the specified directory, for example /opt: sudotar-xzfpostman-linux-x64-xx.xx.xx.tar.gz-C/opt Please note that "postman-linux-x64-xx.xx.xx.tar.gz" is replaced by the file name you actually downloaded. Create symbols

The main difference between Java and other programming languages ??is its cross-platform feature of "writing at once, running everywhere". 1. The syntax of Java is close to C, but it removes pointer operations that are prone to errors, making it suitable for large enterprise applications. 2. Compared with Python, Java has more advantages in performance and large-scale data processing. The cross-platform advantage of Java stems from the Java virtual machine (JVM), which can run the same bytecode on different platforms, simplifying development and deployment, but be careful to avoid using platform-specific APIs to maintain cross-platformity.

Setting the location of the interpreter in PyCharm can be achieved through the following steps: 1. Open PyCharm, click the "File" menu, and select "Settings" or "Preferences". 2. Find and click "Project:[Your Project Name]" and select "PythonInterpreter". 3. Click "AddInterpreter", select "SystemInterpreter", browse to the Python installation directory, select the Python executable file, and click "OK". When setting up the interpreter, you need to pay attention to path correctness, version compatibility and the use of the virtual environment to ensure the smooth operation of the project.

The steps to manually install the plug-in package in VSCode are: 1. Download the .vsix file of the plug-in; 2. Open VSCode and press Ctrl Shift P (Windows/Linux) or Cmd Shift P (Mac) to call up the command panel; 3. Enter and select Extensions:InstallfromVSIX..., then select .vsix file and install. Manually installing plug-ins provides a flexible way to install, especially when the network is restricted or the plug-in market is unavailable, but attention needs to be paid to file security and possible dependencies.

[Common Directory Description] Directory/bin stores binary executable files (ls, cat, mkdir, etc.), and common commands are generally here. /etc stores system management and configuration files/home stores all user files. The root directory of the user's home directory is the basis of the user's home directory. For example, the home directory of the user user is /home/user. You can use ~user to represent /usr to store system applications. The more important directory /usr/local Local system administrator software installation directory (install system-level applications). This is the largest directory, and almost all the applications and files to be used are in this directory. /usr/x11r6?Directory for storing x?window/usr/bin?Many

Understanding Nginx's configuration file path and initial settings is very important because it is the first step in optimizing and managing a web server. 1) The configuration file path is usually /etc/nginx/nginx.conf. The syntax can be found and tested using the nginx-t command. 2) The initial settings include global settings (such as user, worker_processes) and HTTP settings (such as include, log_format). These settings allow customization and extension according to requirements. Incorrect configuration may lead to performance issues and security vulnerabilities.

The installation and configuration of MySQL can be completed through the following steps: 1. Download the installation package suitable for the operating system from the official website. 2. Run the installer, select the "Developer Default" option and set the root user password. 3. After installation, configure environment variables to ensure that the bin directory of MySQL is in PATH. 4. When creating a user, follow the principle of minimum permissions and set a strong password. 5. Adjust the innodb_buffer_pool_size and max_connections parameters when optimizing performance. 6. Back up the database regularly and optimize query statements to improve performance.

Informix and MySQL are both popular relational database management systems. They perform well in Linux environments and are widely used. The following is a comparison and analysis of the two on the Linux platform: Installing and configuring Informix: Deploying Informix on Linux requires downloading the corresponding installation files, and then completing the installation and configuration process according to the official documentation. MySQL: The installation process of MySQL is relatively simple, and can be easily installed through system package management tools (such as apt or yum), and there are a large number of tutorials and community support on the network for reference. Performance Informix: Informix has excellent performance and
