


MariaDB database is installed and configured based on GTID master-slave synchronous replication
Operating 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依靠操作系统将master.info文件刷新到磁盘。 sync_relay_log_info = 1 #MariaDB依靠操作系统将relay-log.info文件刷新到磁盘。 expire_logs_days = 7 #日志文件过期天数,默认是 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线程数 #replicate-do-db = renwoleblogdb#复制指定的数据库,多个写多行 replicate-ignore-db = mysql #不备份的数据库,多个写多行 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
《复制和二进制日志服务器系统变量》 https://mariadb.com/kb/en/mariadb/replication-and-binary-log-server-system-variables/ 关于系统变量的兼容性,可参阅官方 《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'; //创建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; //锁定数据库防止master值变化 MariaDB [(none)]> show master status; //获取master状态值 +-----------------+----------+------------+-----------------+ | 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; //解锁数据表 MariaDB [(none)]> show slave hosts; //查看从服务器连接状态 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!

The main uses of Linux include: 1. Server operating system, 2. Embedded system, 3. Desktop operating system, 4. Development and testing environment. Linux excels in these areas, providing stability, security and efficient development tools.

The Internet does not rely on a single operating system, but Linux plays an important role in it. Linux is widely used in servers and network devices and is popular for its stability, security and scalability.

The core of the Linux operating system is its command line interface, which can perform various operations through the command line. 1. File and directory operations use ls, cd, mkdir, rm and other commands to manage files and directories. 2. User and permission management ensures system security and resource allocation through useradd, passwd, chmod and other commands. 3. Process management uses ps, kill and other commands to monitor and control system processes. 4. Network operations include ping, ifconfig, ssh and other commands to configure and manage network connections. 5. System monitoring and maintenance use commands such as top, df, du to understand the system's operating status and resource usage.

Introduction Linux is a powerful operating system favored by developers, system administrators, and power users due to its flexibility and efficiency. However, frequently using long and complex commands can be tedious and er

Linux is suitable for servers, development environments, and embedded systems. 1. As a server operating system, Linux is stable and efficient, and is often used to deploy high-concurrency applications. 2. As a development environment, Linux provides efficient command line tools and package management systems to improve development efficiency. 3. In embedded systems, Linux is lightweight and customizable, suitable for environments with limited resources.

Introduction: Securing the Digital Frontier with Linux-Based Ethical Hacking In our increasingly interconnected world, cybersecurity is paramount. Ethical hacking and penetration testing are vital for proactively identifying and mitigating vulnerabi

The methods for basic Linux learning from scratch include: 1. Understand the file system and command line interface, 2. Master basic commands such as ls, cd, mkdir, 3. Learn file operations, such as creating and editing files, 4. Explore advanced usage such as pipelines and grep commands, 5. Master debugging skills and performance optimization, 6. Continuously improve skills through practice and exploration.

Linux is widely used in servers, embedded systems and desktop environments. 1) In the server field, Linux has become an ideal choice for hosting websites, databases and applications due to its stability and security. 2) In embedded systems, Linux is popular for its high customization and efficiency. 3) In the desktop environment, Linux provides a variety of desktop environments to meet the needs of different users.


Hot AI Tools

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

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

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Chinese version
Chinese version, very easy to use

Atom editor mac version download
The most popular open source editor