對比PXC集群與主從架構在一致性上的區別
在上一篇文章中,已經完成了三節點PXC集群的搭建,現在搭建node3的從庫node4,並且有如下測試:
搭建node3的從庫,代號node4
測試1:
先斷開node3節點,然後在node1構造數據,再連接上node3,查看同步情況。發現node1、node2、node3、node4所有節點數據一致。
測試2:
先斷開node4節點,然後在node1構造數據,再連接上node4,查看同步情況。發現node1、node2、node3數據一致,node4缺失斷開期間的數據。
結論:
pxc架構會始終在各節點間同步數據,最終使得各節點間的所有數據保持一致。主從結構,只有保持主從結構時,從庫會同步主庫的數據,斷開主從結構後,從庫忽略斷開後主庫的數據。
操作記錄
node1 |
node2 |
node3 |
node4 |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) |
mysql> create database a; |
|
|
|
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | a | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | a | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | a | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | a | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) |
|
|
# systemctl stop mysqld |
|
|
mysql> create database b; |
|
|
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | a | | b | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.00 sec) |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | a | | b | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.00 sec) |
|
mysql> show databases; +--------------------+ | Database | +--------------------+ | a | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 5 rows in set (0.00 sec) |
|
|
# systemctl start mysqld
|
|
|
|
mysql> show databases; +--------------------+ | Database | +--------------------+ | a | | b | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.00 sec) |
mysql> show databases; +--------------------+ | Database | +--------------------+ | a | | b | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.00 sec) |
|
|
#在這裏測試1,完成。發現只要節點連接到PXC集群中,就會自動與其他節點同步數據 |
|
|
|
|
# mysqladmin -uroot -p123456 shutdown |
mysql> create database c; |
|
|
|
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | a | | b | | c | | mysql | | performance_schema | | sys | +--------------------+ 7 rows in set (0.00 sec) |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | a | | b | | c | | mysql | | performance_schema | | sys | +--------------------+ 7 rows in set (0.00 sec) |
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | a | | b | | c | | mysql | | performance_schema | | sys | +--------------------+ 7 rows in set (0.00 sec) |
|
|
|
|
# nohup /mysqldb/base/bin/mysqld_safe --defaults-file=/mysqldb/config/my.cnf --user=mysql >/dev/null 2>&1 & |
|
|
|
mysql> show databases; +--------------------+ | Database | +--------------------+ | a | | b | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.01 sec) |
|
|
|
mysql> show slave status\G; Slave_IO_Running: No Slave_SQL_Running: No
#此時node4雖然啟動,但主從狀態已經斷開,需要重建主從關系, |
|
|
show master status\G; ******* 1. row ******* File: host-192-168-164-124-bin.000016 Position: 344 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: d54ad7f4-3b89-ee17-4ffd-b062a2fc55ab:1-9 |
|
|
|
|
mysql> CHANGE MASTER TO -> MASTER_HOST=‘192.168.164.124‘, -> MASTER_USER=‘repl‘, -> MASTER_PASSWORD=‘123456‘, -> MASTER_PORT=3306, -> MASTER_LOG_FILE=‘host-192-168-164-124-bin.000016‘, -> MASTER_LOG_POS=344, -> MASTER_CONNECT_RETRY=10; |
|
|
|
mysql> start slave; |
|
|
|
mysql> show slave status\G; Slave_IO_Running: Yes Slave_SQL_Running: Yes |
|
|
|
mysql> show databases; +--------------------+ | Database | +--------------------+ | a | | b | | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 6 rows in set (0.00 sec) |
|
|
|
#雖然手動完成主從重建,但依然丟失了部分數據,解決方法也簡單,去BINLOG找到對應POS點,從POS點開始重建主從,從庫就能rely這部分數據。 |
對比PXC集群與主從架構在一致性上的區別