数据库主从复制(2)

2019-01-05 12:46

Last_Errno: 0 Last_Error: Skip_Counter: 0

Exec_Master_Log_Pos: 509270 Relay_Log_Space: 413 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: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error:

Replicate_Ignore_Server_Ids: Master_Server_Id: 2 1 row in set (0.00 sec)

master2状态如下:

show slave status\\G;

*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.0.29 Master_User: repl Master_Port: 3306 Connect_Retry: 60

Master_Log_File: mysql-bin.000004 Read_Master_Log_Pos: 107

Relay_Log_File: localhost-relay-bin.000002 Relay_Log_Pos: 253

Relay_Master_Log_File: mysql-bin.000004 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0

Exec_Master_Log_Pos: 107 Relay_Log_Space: 413 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: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error:

Replicate_Ignore_Server_Ids: Master_Server_Id: 1

slave1状态如下:

show slave status\\G;

*************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.0.29 Master_User: repl Master_Port: 3306 Connect_Retry: 60

Master_Log_File: mysql-bin.000004 Read_Master_Log_Pos: 107

Relay_Log_File: localhost-relay-bin.000002 Relay_Log_Pos: 253

Relay_Master_Log_File: mysql-bin.000004 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0

Exec_Master_Log_Pos: 107 Relay_Log_Space: 413 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: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error:

Replicate_Ignore_Server_Ids: Master_Server_Id: 1

当看到了两个yes,即: Slave_IO_Running: Yes Slave_SQL_Running: Yes 说明已经配置成功了

接下来看可以做一下实验,测试一下是否同步

在master1上面创建库xiaoboluo,创建表t1,并插入测试数据:

mysql > create database xiaoboluo;

mysql > create table t1 (id int unsigned not null primary key auto_increment, aa varchar(100));

mysql > insert into t1 values('','test1'); mysql > insert into t1 values('','test2');

查询t1表:

mysql> select * from t1; +----+-------+ | id | aa | +----+-------+ | 1 | test1 |

| 3 | test2 | +----+-------+

在master1上查询t1表: mysql> select * from t1; +----+-------+ | id | aa | +----+-------+ | 1 | test1 | | 3 | test2 | +----+-------+

在slave1上查询t1表:

mysql> select * from t1; +----+-------+ | id | aa | +----+-------+ | 1 | test1 | | 3 | test2 | +----+-------+

可以发现master1上创建的库,表,插入的测试数据,在master2和slave1中都已经同步了

现在到master2上插入几行测试数据:

mysql> insert into t1 values('','test3');

Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> insert into t1 values('','test4');

Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> select * from t1; +----+-------+ | id | aa | +----+-------+ | 1 | test1 | | 3 | test2 | | 4 | test3 | | 6 | test4 | +----+-------+

4 rows in set (0.00 sec)

到master1中查询t1表: mysql> select * from t1;

+----+-------+ | id | aa | +----+-------+ | 1 | test1 | | 3 | test2 | | 4 | test3 | | 6 | test4 | +----+-------+

4 rows in set (0.00 sec)

到slave1中查询t1表:

mysql> select * from t1; +----+-------+ | id | aa | +----+-------+ | 1 | test1 | | 3 | test2 | | 4 | test3 | | 6 | test4 | +----+-------+

4 rows in set (0.00 sec)

可以发现在master2中插入的数据,在master1中和slave1中都已经同步

注意:如果你只需要双主,那么把slave1的过程去掉,如果你只需要主从,那么把master2的步骤去掉。

六、现在把keepalived给添加上去: 1.安装keepalived,在两台master上安装 shell > yum install keepalived -y

2.配置keepalived: A:master1:

shell > cat /etc/keepalived/keepalived.conf vrrp_script vs_mysql_82 {

script \ interval 60 }

vrrp_instance VI_82 { state BACKUP nopreempt


数据库主从复制(2).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:通信原理习题解答WORD版6

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: