发布网友 发布时间:2022-05-02 22:45
共2个回答
懂视网 时间:2022-05-03 03:07
如果在生产环境中可能有一个主服务器,也是读定服务器,并可能会有多个从服务器,但这个主服务器会随之从服务器的增加而变的性能下降,所以最好主服务器只有一个从,其它的从服务器再从这人从服务器进行复制,减少主服务器的压力,这样中间服务器专做复制从而最小化影响主服务器的性能
[root@centos7 ~]#yum install mariadb-server
[root@centos7 ~]#mkdir /data/{mysql,logs}
[root@centos7 ~]#chown mysql:mysql /data/{mysql,logs}
[root@master ~]#vi /etc/my.cnf
[mysqld]
log-bin=/data/logs/bin
datadir=/data/mysql
server-id=17
[root@master ~]#systemctl start mariadb
[root@master ~]#mysql < hellodb_innodb.sql
MariaDB [(none)]> grant replication slave on *.* to repluser@‘192.168.205.%‘ identified by ‘centos‘;
[root@master ~]#mysqldump -A --single-transaction --master-data=1 > /data/all.sql
[root@master ~]#scp /data/all.sql 192.168.205.27:/data
[root@middle ~]#vi /etc/my.cnf
[mysqld]
datadir=/data/mysql
log-bin=/data/logs/bin
server-id=27
read-only
log_slave_updates
[root@middle ~]#vi /data/all.sql
CHANGE MASTER TO
MASTER_HOST=‘192.168.205.17‘,
MASTER_USER=‘repluser‘,
MASTER_PASSWORD=‘centos‘,
MASTER_PORT=3306,
MariaDB [(none)]> source /data/all.sql
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave statusG
*************************** 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
[root@middle ~]#mysqldump -A --single-transaction --master-data=1 > /data/middle.sql
[root@middle ~]#scp /data/middle.sql 192.168.205.37:/data
[root@slave ~]#vi /etc/my.cnf
[mysqld]
datadir=/data/mysql
server-id=37
read_only
[root@slave ~]#vi /data/middle.sql
CHANGE MASTER TO
MASTER_HOST=‘192.168.205.27‘,
MASTER_USER=‘repluser‘,
MASTER_PASSWORD=‘centos‘,
MASTER_PORT=3306,
[root@slave ~]#mysql < /data/middle.sql
[root@slave ~]#systemctl start mariadb
MariaDB [(none)]> start salve;
MariaDB [(none)]> show slave statusG
*************************** 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
MariaDB [(none)]> create database zhaoli;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| db2 |
| hellodb |
| mysql |
| performance_schema |
| test |
| zhaoli |
+--------------------+
8 rows in set (0.00 sec)
数据库的级联复制
标签:ima serve pass tran slave ase test running host
热心网友 时间:2022-05-03 00:15
父表-子表 的 关联