Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Complete implementation of cascade replication of database cluster

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Note before the experiment:

If you want to enable cascading replication, you need to enable the following configuration on the slave server; the role of [mysqld] log_binlog_slave_updateslog_slave_updates: because the default binary log from the master server is saved in the relay log of the slave server; and applied to the local database But the middle slave server does not record the local binary log even if the binary log recording function is enabled, so the operation on the database cannot be transferred to the slave server. When log_slave_updates is enabled, the slave server can also record the binary logs to the master server in its own binary log after local execution; delete the database and do a clean experiment; [root@master ~] $systemctl stop mariadb [root@master ~] $rm-fr / var/lib/mysql/* [root@master ~] $systemctl start mariadb

Configuration of master, slave and secondary slave servers:

[root@master ~] $cat / etc/my.cnf [mysqld] datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0innodb_file_per_tablelog_binserver-id=1 [root@slave ~] $cat / etc/my.cnf [mysqld] datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0# Settings user and group are ignored when systemd is used.innodb_file_ Per_tableserver_id=2read_onlylog_binlog_slave_ updates [root @ slave2 ~] $cat / etc/my.cnf [mysqld] datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sock# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0server_id=3

Master server and slave server implement master-slave replication, configuration and authorization:

Master server: MariaDB [(none)] > grant replication slave on *. * to repluser@'192.168.27.%' identified by 'centos';Query OK, 0 rows affected (0.00 sec) MariaDB [(none)] > show master logs +-+-+ | Log_name | File_size | +-+-+ | mariadb-bin.000001 | 264 | mariadb-bin.000002 | 401 | +- The slave server in the middle of +-+ 2 rows in set (0.00 sec): CHANGE MASTER TOMASTER_HOST='192.168.27.7' MASTER_USER='repluser',MASTER_PASSWORD='centos',MASTER_LOG_FILE='mariadb-bin.000001',MASTER_LOG_POS=245 MariaDB [(none)] > CHANGE MASTER TO-> MASTER_HOST='192.168.27.7',-> MASTER_USER='repluser',-> MASTER_PASSWORD='centos',-> MASTER_LOG_FILE='mariadb-bin.000001',-> MASTER_LOG_POS=245;Query OK, 0 rows affected (0.02 sec) MariaDB [(none)] > start slave Query OK 0 rows affected (0.00 sec) MariaDB [(none)] > show slave status\ gateway * 1. Row * * Slave_IO_State: Waiting for master to send event Master_Host: 192.168.27.7 Master_User: repluser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mariadb-bin.000002 Read_Master_Log_Pos: 401 Relay_Log_File: mariadb-relay-bin.000003 Relay_Log_Pos: 687 Relay_Master_Log_File: mariadb-bin.000002 Slave_IO_Running: Yes Slave_SQL_Running: Yes Exec_Master_Log_Pos: 401 Relay_Log_Space: 1269 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: 0MariaDB [(none)] > select user from mysql.user +-+ | user | +-+ | root | | repluser | | root | | root | root | +-+ 7 rows in set (0.00 sec) MariaDB [(none)] > show master logs +-+-+ | Log_name | File_size | +-+-+ | mariadb-bin.000001 | 401 | +- -+ 1 row in set (0.00 sec)

Secondary slave configuration on the server:

Execute on the slave server: [mysqld] innodb_file_per_tableread-onlyserver-id=3CHANGE MASTER TOMASTER_HOST='192.168.27.17',MASTER_USER='repluser',MASTER_PASSWORD='centos',MASTER_LOG_FILE='mariadb-bin.000001',MASTER_LOG_POS=401

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 272

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report