1 实现级联复制
1.1 实验环境
- 三台主机实现级联复制
- 在192.168.66.8充当master
在192.168.66.18充当级联midslave
在192.168.66.28充当slave
- 主机系统为CentOS8
- 需要干净的系统,关闭防火墙,selinux=disabled
- dnf仓库需自己创建
注意:此实验采用dnf 安装的mariadb-server
1.2 节点配置
1.2.1 主节点master配置
dnf install mariadb-server
systemctl start mariadb
mysql < /data/helldb.sql
vim /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
server-id=8
log-bin=/data/mysql/logbin/mariadb-bin
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/run/mariadb/mariadb.pid
systemctl restart mariadb
MariaDB [(none)]> grant replication slave on *.* to repluser@'192.168.66.%' identified by 'ming';
Query OK, 0 rows affected (0.013 sec)
MariaDB [(none)]> select user,host,password from mysql.user;
+
| user | host | password |
+
| root | localhost | |
| root | master | |
| root | 127.0.0.1 | |
| root | ::1 | |
| repluser | 192.168.66.% | *C6B2B8EC628390A22B99AB0609E5E70A0F962E9F |
+
5 rows in set (0.001 sec)
MariaDB [(none)]> show master logs;
+
| Log_name | File_size |
+
| mariadb-bin.000001 | 529 |
+
1 row in set (0.000 sec)
MariaDB [(none)]> show master logs;
+
| Log_name | File_size |
+
| mariadb-bin.000001 | 578 |
| mariadb-bin.000002 | 389 |
+
[root@centos8 ~]
[root@centos8 ~]
[root@centos8 ~]
1.2.2 中间级联slave配置
dnf install mariadb-server
systemctl start mariadb
[root@midslave ~]
[mysqld]
server-id=18
log-bin
log_slave_updates **
CHANGE MASTER TO
MASTER_HOST='192.168.66.8',
MASTER_USER='repluser',
MASTER_PASSWORD='ming',
MASTER_PORT=3306,
MASTER_LOG_FILE='mysql-bin.000002', MASTER_LOG_POS=389;
[root@midslave ~]
MariaDB [(none)]> set sql_log_bin=0;
MariaDB [(none)]> source /data/all.sql
MariaDB [mysql]> show master logs;
+
| Log_name | File_size |
+
| mariadb-bin.000001 | 483168 |
| mariadb-bin.000002 | 389 |
+
2 rows in set (0.000 sec)
MariaDB [(none)]> set sql_log_bin=0;
MariaDB [(none)]> start slave;
MariaDB [mysql]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.66.8
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mariadb-bin.000002
Read_Master_Log_Pos: 389
Relay_Log_File: mariadb-relay-bin.000003
Relay_Log_Pos: 557
Relay_Master_Log_File: mariadb-bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 389
Relay_Log_Space: 1179
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 8
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Replicate_Do_Domain_Ids:
Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Slave_DDL_Groups: 0
Slave_Non_Transactional_Groups: 0
Slave_Transactional_Groups: 0
1 row in set (0.001 sec)
1.2.3 在第三个节点slave配置
[root@slave ~]
[root@slave ~]
[root@slave ~]
[mysqld]
server-id=28
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mariadb/mariadb.log
pid-file=/run/mariadb/mariadb.pid
[root@centos8 ~]
[root@slave ~]
CHANGE MASTER TO
MASTER_HOST='192.168.66.18',
MASTER_USER='repluser',
MASTER_PASSWORD='ming',
MASTER_PORT=3306,
MASTER_LOG_FILE='mariadb-bin.000002', MASTER_LOG_POS=389;
[root@centos8 ~]
[root@centos8 ~]
MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 192.168.66.18
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mariadb-bin.000002
Read_Master_Log_Pos: 389
Relay_Log_File: mariadb-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mariadb-bin.000002
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 389
Relay_Log_Space: 256
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 1130
Last_IO_Error: error connecting to master '[email protected]:3306' - retry-time: 60 maximum-retries: 86400 message: Host '192.168.66.28' is not allowed to connect to this MariaDB server
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Replicate_Do_Domain_Ids:
Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Slave_DDL_Groups: 0
Slave_Non_Transactional_Groups: 0
Slave_Transactional_Groups: 0
1 row in set (0.000 sec)
**解决办法**
MariaDB [(none)]> stop slave;
Query OK, 0 rows affected (0.008 sec)
MariaDB [(none)]> reset slave all;
Query OK, 0 rows affected (0.001 sec)
**
root@midslave ~]
[root@midslave ~]
MariaDB [(none)]> show master logs;
+
| Log_name | File_size |
+
| mariadb-bin.000001 | 483168 |
| mariadb-bin.000002 | 438 |
| mariadb-bin.000003 | 412 |
| mariadb-bin.000004 | 344 |
+
4 rows in set (0.000 sec)
**
MariaDB [(none)]> stop slave;
Query OK, 0 rows affected (0.008 sec)
MariaDB [(none)]> reset slave all;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> CHANGE MASTER TO
MASTER_HOST='192.168.66.18',
MASTER_USER='repluser',
MASTER_PASSWORD='ming',
MASTER_PORT=3306,
MASTER_LOG_FILE='mariadb-bin.000004', MASTER_LOG_POS=344;
Query OK, 0 rows affected (0.013 sec)
MariaDB [(none)]> start slave;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> show slave status;
MariaDB [(none)]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.66.18
Master_User: repluser
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mariadb-bin.000004
Read_Master_Log_Pos: 344
Relay_Log_File: mariadb-relay-bin.000002
Relay_Log_Pos: 557
Relay_Master_Log_File: mariadb-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 344
Relay_Log_Space: 868
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 18
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
Replicate_Do_Domain_Ids:
Replicate_Ignore_Domain_Ids:
Parallel_Mode: conservative
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Slave_DDL_Groups: 0
Slave_Non_Transactional_Groups: 0
Slave_Transactional_Groups: 0
1 row in set (0.000 sec)
1.3 测试
MariaDB [(none)]> create database db1;
[root@master ~]
Query OK, 1 row affected (0.001 sec)
MariaDB [mysql]> show databases;
+
| Database |
+
| db1 |
| hellodb |
| information_schema |
| mysql |
| performance_schema |
+
5 rows in set (0.001 sec)
[root@midslave ~]
MariaDB [mysql]> show databases;
+
| Database |
+
| db1 |
| hellodb |
| information_schema |
| mysql |
| performance_schema |
+
5 rows in set (0.001 sec)
[root@slave ~]
MariaDB [mysql]> show databases;
+
| Database |
+
| db1 |
| hellodb |
| information_schema |
| mysql |
| performance_schema |
+
5 rows in set (0.001 sec)