一、MySQL Fabric高可用集群中一台数据库崩溃了,不影响数据的完整性
  1.测试前准备
  a)   查看group_id-1集群组的服务器状态
  mysqlfabric group lookup_servers group_id-1
  返回结果:
Command :
{ success = True
return = [{'status': 'PRIMARY', 'server_uuid': '7a45f71d-7934-11e4-9e8c-782bcb74823a', 'mode': 'READ_WRITE', 'weight': 1.0, 'address': '192.168.1.71:3306'}, {'status': 'SECONDARY', 'server_uuid': '9cf162ca-7934-11e4-9e8d-782bcb1b6b98', 'mode': 'READ_ONLY', 'weight': 1.0, 'address': '192.168.1.76:3306'}, {'status': 'SECONDARY', 'server_uuid': 'ae94200b-7932-11e4-9e81-a4badb30e16b', 'mode': 'READ_ONLY', 'weight': 1.0, 'address': '192.168.1.70:3306'}]
activities =
}
  此时primary机为机器:192.168.1.71:3306,group_id-1集群组正常
  b)   查看group_id-1集群组中的数据
mysql -P 3306 -h 192.168.1.76 -u root -e "select * from test.subscribers"
mysql -P 3306 -h 192.168.1.71 -u root -e "select * from test.subscribers"
mysql -P 3306 -h 192.168.1.70 -u root -e "select * from test.subscribers"
返回结果如下:
+--------+------------+-----------+
| sub_no | first_name | last_name |
+--------+------------+-----------+
| 500 | Billy | Joel |
| 1500 | Arthur | Askey |
| 5000 | Billy | Fish |
| 17542 | Bobby | Ball |
| 22 | Billy | Bob |
| 8372 | Banana | Man |
| 93846 | Bill | Ben |
| 15050 | John | Smith |
+--------+------------+-----------+
  c)   利用python接口查看数据库test的数据表subscribers分片后的全部数据
  python read_table_ha.py
  返回结果如下:
(u'Billy', u'Bob')
(u'Billy', u'Fish')
(u'Billy', u'Joel')
(u'Arthur', u'Askey')
(u'Banana', u'Man')
(u'Billy', u'Fish')
(u'Bill', u'Ben')
(u'Jimmy', u'White')
(u'John', u'Smith')
(u'Bobby', u'Ball')
  2.开始测试
  a)  激活故障自动切换
  即使Fabric选出了master角色,但当这个master角色宕机时,fanric不会自动将secondary角色切换为master角色,所以需要将HA集群组的配置改为自动切换角色
  mysqlfabric group activate group_id-1
  b)  停止group_id-1组中的master角色,即数据库实例192.168.1.71:3306,再查看fabric的状态
  mysqlfabric group lookup_servers group_id-1
  返回结果:
Command :
{ success = True
return = [{'status': 'FAULTY', 'server_uuid': '7a45f71d-7934-11e4-9e8c-782bcb74823a', 'mode': 'READ_WRITE', 'weight': 1.0, 'address': '192.168.1.71:3306'}, {'status': 'SECONDARY', 'server_uuid': '9cf162ca-7934-11e4-9e8d-782bcb1b6b98', 'mode': 'READ_ONLY', 'weight': 1.0, 'address': '192.168.1.76:3306'}, {'status': 'PRIMARY', 'server_uuid': 'ae94200b-7932-11e4-9e81-a4badb30e16b', 'mode': 'READ_WRITE', 'weight': 1.0, 'address': '192.168.1.70:3306'}]
activities =
}
  其中,数据库实例192.168.1.71:3306的状态为FAULTY,mysql fabric自动检测到了HA组的故障,并自动选举了slave角色为primary角色