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