Cascading replication database

Cascading replication database

surroundings:

  • 192.168.205.17: as master server
  • 192.168.205.27: as middle server
  • 192.168.205.37: as slave server

version:

  • OS: centos 7 1810 with mini install
  • mariadb-5.5.60

Joint:

If possible have a master server, also read a given server, and there may be multiple performance degradation from the server, but the server will follow from the primary server to increase and become, in a production environment it is best to have only one master server from other then this pressure person copied from the server, the master server reduced, so that the intermediate server specializing copied from the server to minimize the performance impact of the master

step:

  1. Configure the primary server
  2. Intermediate server backup
  3. Configuring from the server
  4. test

Configure the primary server

  1. Installed three servers
    [root@centos7 ~]#yum install mariadb-server
    [root@centos7 ~]#mkdir /data/{mysql,logs}
    [root@centos7 ~]#chown mysql:mysql /data/{mysql,logs}  
  2. Modify the configuration file of the master server
    [root@master ~]#vi /etc/my.cnf
    [mysqld]
    log-bin=/data/logs/bin
    datadir=/data/mysql
    server-id=17     
  3. Restart Service
    [root@master ~]#systemctl start mariadb
  4. Load a test database
    [root@master ~]#mysql < hellodb_innodb.sql 
  5. Creating complex cap Account
    MariaDB [(none)]> grant replication slave on *.* to repluser@'192.168.205.%' identified by 'centos';
  6. Backup copies and database to the intermediate nodes
    [root@master ~]#mysqldump -A --single-transaction --master-data=1 > /data/all.sql
    [root@master ~]#scp /data/all.sql 192.168.205.27:/data 

    Cascade Server Configuration middle

  7. An intermediate server
    [root@middle ~]#vi /etc/my.cnf           
    [mysqld]
    datadir=/data/mysql
    log-bin=/data/logs/bin
    server-id=27
    read-only
    log_slave_updates
  8. Modification of data backup
    [root@middle ~]#vi /data/all.sql 
    CHANGE MASTER TO
    MASTER_HOST='192.168.205.17',
    MASTER_USER='repluser',
    MASTER_PASSWORD='centos',                   
    MASTER_PORT=3306,
  9. Import Data
    MariaDB [(none)]> source /data/all.sql
  10. Start a thread
    MariaDB [(none)]> start slave;
    MariaDB [(none)]> show slave status\G
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 192.168.205.17
                      Master_User: repluser
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: bin.000003
              Read_Master_Log_Pos: 7973
                   Relay_Log_File: mariadb-relay-bin.000004
                    Relay_Log_Pos: 604
            Relay_Master_Log_File: bin.000003
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes
  11. Intermediate data backup server, and copying from the server
    [root@middle ~]#mysqldump -A --single-transaction --master-data=1 > /data/middle.sql
    [root@middle ~]#scp /data/middle.sql 192.168.205.37:/data

    Modify from the server

  12. Modify the configuration file from the server
    [root@slave ~]#vi /etc/my.cnf
    [mysqld]
    datadir=/data/mysql
    server-id=37
    read_only
  13. Modify the backup file middle.sql
    [root@slave ~]#vi /data/middle.sql 
    CHANGE MASTER TO 
    MASTER_HOST='192.168.205.27', 
    MASTER_USER='repluser', 
    MASTER_PASSWORD='centos', 
    MASTER_PORT=3306,
  14. Import data and start the service
    [root@slave ~]#mysql < /data/middle.sql   
    [root@slave ~]#systemctl start mariadb
  15. Start a thread
    MariaDB [(none)]> start salve; 
    MariaDB [(none)]> show slave status\G
    *************************** 1. row ***************************
                   Slave_IO_State: Waiting for master to send event
                      Master_Host: 192.168.205.27
                      Master_User: repluser
                      Master_Port: 3306
                    Connect_Retry: 60
                  Master_Log_File: bin.000005
              Read_Master_Log_Pos: 326
                   Relay_Log_File: mariadb-relay-bin.000003
                    Relay_Log_Pos: 604
            Relay_Master_Log_File: bin.000005
                 Slave_IO_Running: Yes
                Slave_SQL_Running: Yes

test

  1. Testing building a database on the primary server
    MariaDB [(none)]> create database zhaoli;
    Query OK, 1 row affected (0.00 sec)
  1. View each database in the middle and from the node, the synchronization is successful
    MariaDB [(none)]> show databases;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | db1                |
    | db2                |
    | hellodb            |
    | mysql              |
    | performance_schema |
    | test               |
    | zhaoli             |
    +--------------------+
    8 rows in set (0.00 sec)

Guess you like

Origin blog.51cto.com/127601/2426823