Introduction:
The master-slave cascade is to reduce the pressure of the master database, which is more conducive to load balancing. If we don't have a cascade server, we can also achieve the effect of master-slave synchronization, but we don't recommend using it. On the one hand, the pressure of the master database is too high, on the other hand, the efficiency is too low. When we have cascading, our primary server only needs to synchronize its own data to the cascading server, and the rest of the secondary servers are synchronized by the cascading server, which can improve efficiency and reduce the pressure of the primary database.
ip configuration is as follows:
master server: 172.18.254.223
cascade Server: 172.18.254.227
slave1 (slave) server: 172.18.254.228
Implementation ideas:
First treat cascade as a slave, and then synchronize master with it. Remember: cascade has users (the directory created by master and slave synchronization), and then synchronize slave1 as master.
Profile of master:
vim /etc/my.cnf server_id=1 #It doesn't make sense to distinguish IDS, but they have to be different datadir=/mysql/data #Specify where to store data files log_bin=/mysql/logbin/log #Specify where to store binaries innodb_file_per_table #Separate binaries
cascade profile:
vim /etc/my.cnf server_id=2 #It doesn't make sense to distinguish IDS, but they have to be different innodb_file_per_table datadir=/mysql/data log_bin=/mysql/logbin/log #With the following log_slave_updates #This must be written because cascade has binary files
slave1 profile:
vim /etc/my.cnf server_id=3 #It doesn't make sense to distinguish IDS, but they have to be different datadir=/mysql/data log_bin=/mysql/logbin/log innodb_file_per_table
The database display of master:
MariaDB [(none)]> show master status; +-------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------+----------+--------------+------------------+ | log.000004 | 245 | | | +-------------------+----------+--------------+------------------+ 1 row in set (0.00 sec) MariaDB [(none)]> grant replication slave on *.* to zhang@'172.18.254.%' identified by 'centos'; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> select user from mysql.user; +-------+ | user | +-------+ | root | | zhang | | root | | | | root | | | | root | +-------+ 7 rows in set (0.00 sec)
Display of cascade database:
MariaDB [(none)]> CHANGE MASTER TO -> MASTER_HOST='192.168.254.223', -> MASTER_USER='zhang', -> MASTER_PASSWORD='centos', -> MASTER_PORT=3306, -> MASTER_LOG_FILE='log.000004', -> MASTER_LOG_POS=245, -> MASTER_CONNECT_RETRY=10; Query OK, 0 rows affected (0.07 sec) MariaDB [(none)]> start slave; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show master status; +------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------+----------+--------------+------------------+ | log.000003 | 478 | | | +------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
The slave1 database displays:
MariaDB [(none)]> CHANGE MASTER TO -> MASTER_HOST='192.168.254.227', -> MASTER_USER='zhang', -> MASTER_PASSWORD='centos', -> MASTER_PORT=3306, -> MASTER_LOG_FILE='log.000003', -> MASTER_LOG_POS=478, -> MASTER_CONNECT_RETRY=10; Query OK, 0 rows affected (0.07 sec) MariaDB [(none)]> start slave;
Add: remove settings from:
MariaDB [(none)]> stop slave; Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> reset slave all; Query OK, 0 rows affected (0.17 sec)