


MySQL database Group Replication builds the pitfall of stepping on the IP address
Introduction
The replication function of MySQL version 5.7.17 has ushered in a new feature, the shining star function Group Replicatioin. Naturally, it is indispensable to have some experience in building and testing, but during the building process, we encountered pitfalls related to the host name. The following will explain how to build it and the process of encountering this pitfall.
2
Expected
Two instances 3306 and 3307 will be built on the virtual machine 192.168.56.102, and one instance 3308 will be built on 192.168.56.105. According to the characteristics, you need to select a node as the node to start Group Replication. This article selects 3306 as the startup node.
3
Build
Instance 192.168.56.102:3306
my.cnf Key content:
[mysqld3306] gtid-mode=on enforce-gtid-consistency=on master-info-repository=table relay-log-info-repository=table binlog-checksum=none log-slave-updates=on binlog-format=row transaction_write_set_extraction=XXHASH64 loose-group_replication_group_name="2dc52aec-cfea-11e6-95f3-080027264cfa" loose-group_replication_start_on_boot=off # 开机启动OFF loose-group_replication_local_address="192.168.56.102:33061" loose-group_replication_group_seeds="192.168.56.102:33061,192.168.56.102:33071,192.168.56.105:33081" loose-group_replication_bootstrap_group=off # 作为首个启动OFF
Note:
1. The ports listed in the configuration are required and not used.
2. The format of group_name is UUID, you can execute select uuid(); in MySQL to obtain one.
Create a copy account:
mysql> set sql_log_bin=0; mysql> create user 'group_repl'@'%' identified by 'group_repl'; mysql> grant replication slave on *.* to 'group_repl'@'%'; mysql> flush privileges; mysql> set sql_log_bin=1;
Create a copy channel:
mysql> change master to master_user='group_repl',master_password='group_repl' for channel 'group_replication_recovery';
Load Plug-in:
mysql> install plugin group_replication soname 'group_replication.so';
Start Group Replication as the first node:
mysql> set @@global.group_replication_bootstrap_group=1; mysql> start group_replication; mysql> set @@global.group_replication_bootstrap_group=0; mysql> select * from performance_schema.replication_group_members\G *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 4f987d01-cff0-11e6-9afa-080027264cfa MEMBER_HOST: localhost MEMBER_PORT: 3306 MEMBER_STATE: ONLINE
Instances 192.168.56.102:3307 and 192.168.56.105:3308
The operations of the remaining instances are large The parts are the same as 102:3306. Only the different parts are listed below:
1. In my.cnf, the parameters of 102:3307:
loose-group_replication_local_address="192.168.56.102:33071",105:3308的参数:loose-group_replication_local_address="192.168.56.105:33081";
2. When creating a copy account, After copying the channel and loading the plug-in, both 102:3307 and 105:3308 only need to execute: start group_replication;.
4
Check
To check whether to join Group Replication, just query the table performance_schema.replication_group_members. The following is the situation of 102:3307 joining the group:
mysql> select * from performance_schema.replication_group_members\G *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 4f987d01-cff0-11e6-9afa-080027264cfa MEMBER_HOST: localhost MEMBER_PORT: 3306 MEMBER_STATE: ONLINE *************************** 2. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: d8f7405d-cff1-11e6-b449-080027264cfa MEMBER_HOST: localhost MEMBER_PORT: 3307 MEMBER_STATE: ONLINE
You can see that there are already two nodes forming the group, namely 102:3306 and 102:3307.
5
Problem
When I started to join 105:3308, something went wrong. It can be found that 3308 has been unable to join the group:
mysql> select * from performance_schema.replication_group_members; *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 4f987d01-cff0-11e6-9afa-080027264cfa MEMBER_HOST: localhost MEMBER_PORT: 3306 MEMBER_STATE: ONLINE *************************** 2. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 645aef9a-d000-11e6-a756-080027d54077 MEMBER_HOST: localhost MEMBER_PORT: 3308 MEMBER_STATE: RECOVERING *************************** 3. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: d8f7405d-cff1-11e6-b449-080027264cfa MEMBER_HOST: localhost MEMBER_PORT: 3307 MEMBER_STATE: ONLINE
Through the error log:
... 2017-01-02T17:35:02.123501Z 32 [Note] 'CHANGE MASTER TO FOR CHANNEL 'group_replication_recovery' executed'. Previous state master_host='<NULL>', master_port= 0, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='localhost', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. ... 2017-01-02T17:35:02.133661Z 34 [ERROR] Slave I/O for channel 'group_replication_recovery': error connecting to master 'group_repl@localhost:3306' - retry-time: 60 retries: 1, Error_code: 2003 ...
It can be guessed that the problem is with MEMBER_HOST, so change the host name to the IP address. After testing, it was found to be feasible:
mysql> select * from performance_schema.replication_group_members\G *************************** 1. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 4f987d01-cff0-11e6-9afa-080027264cfa MEMBER_HOST: 192.168.56.102 MEMBER_PORT: 3306 MEMBER_STATE: ONLINE *************************** 2. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 645aef9a-d000-11e6-a756-080027d54077 MEMBER_HOST: 192.168.56.105 MEMBER_PORT: 3308 MEMBER_STATE: ONLINE *************************** 3. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: d8f7405d-cff1-11e6-b449-080027264cfa MEMBER_HOST: 192.168.56.102 MEMBER_PORT: 3307 MEMBER_STATE: ONLINE
But in actual circumstances it is impossible to set the host name to IP. So after many attempts, I found that this problem can be solved in the following ways:
1. Set different host names for different physical machines (virtual machines);
2. Modify /etc/ hosts enables ping between physical machines (virtual machines) through host names.
After completing the above work, finally check the group members:
mysql> select * from performance_schema.replication_group_members \G*************************** 1. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 4f987d01-cff0-11e6-9afa-080027264cfa MEMBER_HOST: local-102 MEMBER_PORT: 3306 MEMBER_STATE: ONLINE *************************** 2. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: 645aef9a-d000-11e6-a756-080027d54077 MEMBER_HOST: local-105 MEMBER_PORT: 3308 MEMBER_STATE: ONLINE *************************** 3. row *************************** CHANNEL_NAME: group_replication_applier MEMBER_ID: d8f7405d-cff1-11e6-b449-080027264cfa MEMBER_HOST: local-102 MEMBER_PORT: 3307 MEMBER_STATE: ONLINE
The problem is solved. Another thing to note is that even instances under a physical machine (virtual machine) need to have a mapping relationship between host name and IP to form a group. The reason why groups can be formed under the same physical machine in the localhost situation above is because the system has a mapping relationship from 127.0.0.1 to localhost by default.
6
Summary
The above problem occurs because MySQL directly uses the hostname of the operating system instead of the IP address commonly used when configuring replication. This should It is a bug, and someone has submitted a bug request to the official website a few days earlier than me. It is recommended that when configuring Group Replication and before the bug is fixed, it is best to check whether the mapping relationship between the host name and the IP address is set.
The above is the content of the MySQL database Group Replication building that steps on the IP address. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

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

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











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.
