mysql主从级联复制

文章目录

    • msyql 主服务器配置
    • cascade 服务器配置
    • slave 服务器的配置

msyql 主服务器配置

[master]# yum install maraidb-server -y
[master]# vim /etc/my.cnf
server_id=7
log_bin=/data/logbin/mariadb-bin

[master]# mkdir /data/logbin
[master]# chown -R mysql.mysql /data/logbin
[master]# systemctl start mariadb
[master]# mysql < hellodb_innodb.sql
[master]# mysql
MariaDB [(none)]> grant replication slave on *.* to repl@'192.168.43.%' identified by 'centos';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> \q
[master]# mysqldump -A -F --single-transaction --master-data=1 -q > /data/all.sql
[master]# scp /data/all.sql 192.168.43.17:/data/

cascade 服务器配置

[cascade]# vim /etc/my.cnf
[mysqld]
server_id=17
read_only
log_slave_updates
log_bin=/data/logbin/mariadb-bin

[cascade]# vim /data/all.sql
CHANGE MASTER TO 
MASTER_HOST='192.168.43.7',
MASTER_USER='repl',
MASTER_PASSWORD='centos',
MASTER_PORT=3306,
MASTER_LOG_FILE='mariadb-bin.000004', MASTER_LOG_POS=245;

[cascade]# mkdir /data/logbin/
[cascade]# chown -R mysql.mysql /data/logbin/

[cascade]# systemctl start mariadb
[cascade]# mysql < /data/all.sql
[cascade]# mysql
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> show slave status\G
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G

[cascade]# mysqldump -A -F --single-transaction --master-data=1 -q > /data/all.sql
[cascade]# scp /data/all.sql 192.168.43.27:/data

slave 服务器的配置

[slave]# vim /etc/my.cnf
[mysqld]
server_id=27

[slave]# vim /data/all.sql
CHANGE MASTER TO 
MASTER_HOST='192.168.43.17',
MASTER_USER='repl',
MASTER_PASSWORD='centos',
MASTER_PORT=3306,
MASTER_LOG_FILE='mariadb-bin.000004', MASTER_LOG_POS=245;

[slave]# systemctl start mariadb
[slave]# mysql < /data/all.sql
[slave]# mysql
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status\G

你可能感兴趣的:(MYSQL)