MySQL MGR 叢集搭建(單主模式)
1.背景
MySQL Group Replication(MGR)是MySQL官方在5.7.17版本引進的一個資料庫高可用與高擴充套件的解決方案,以外掛形式提供,實現了分散式下資料的最終一致性,總結MGR特點如下:
* 高一致性:基於分散式paxos協議實現組複製,保證資料一致性;
* 高容錯性:自動檢測機制,只要不是大多數節點都當機就可以繼續工作,內建防腦裂保護機制;
* 高擴充套件性:節點的增加與移除會自動更新組成員資訊,新節點加入後,自動從其他節點同步增量資料,直到與其他節點資料一致;
* 高靈活性:提供單主模式和多主模式,單主模式在主庫當機後能夠自動選主,所有寫入都在主節點進行,多主模式支援多節點寫入。
2. 環境:
3臺伺服器搭建3節點MGR叢集,MySQL版本5.7.27,作業系統版本CentOS 7.3。
* 192.168.8.71
* 192.168.8.72
* 192.168.8.73
3.安裝步驟
3.1 安裝MySQL5.7
MySQL官方版5.7.27,採用Linux Generic安裝方式,直接下載壓縮包,解壓到目錄/usr/local/mysql。
3.2 修改配置檔案
編輯配置檔案/etc/my.cnf,3個節點除了server_id、loose-group_replication_local_address、report_host 三個引數不一樣外,其他保持一致。
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
server_id=1
gtid_mode=ON
enforce_gtid_consistency=ON
binlog_checksum=NONE
log_bin=binlog
log_slave_updates=ON
binlog_format=ROW
master_info_repository=TABLE
relay_log_info_repository=TABLE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
loose-group_replication_start_on_boot=OFF
loose-group_replication_local_address= "192.168.8.71:33061"
loose-group_replication_group_seeds= "192.168.8.71:33061,192.168.8.72:33061,192.168.8.73:33061"
loose-group_replication_bootstrap_group=OFF
report_host=192.168.8.71
report_port=3306
3.3 初始化資料庫(所有節點執行)
略
3.4 啟動資料庫,安裝MGR外掛,設定複製賬號(所有節點執行)
--安裝MGR外掛
mysql>INSTALL PLUGIN group_replication SONAME 'group_replication.so';
--設定複製賬號
mysql> SET SQL_LOG_BIN=0;
mysql> CREATE USER repl@'%' IDENTIFIED BY 'repl';
mysql> GRANT REPLICATION SLAVE ON *.* TO repl@'%';
mysql> FLUSH PRIVILEGES;
mysql> SET SQL_LOG_BIN=1;
mysql> CHANGE MASTER TO MASTER_USER='repl', MASTER_PASSWORD='repl' FOR CHANNEL 'group_replication_recovery';
3.5 啟動MGR單主模式
# 啟動MGR,在主庫(192.168.8.71)上執行
mysql> SET GLOBAL group_replication_bootstrap_group=ON;
mysql> START GROUP_REPLICATION;
mysql> SET GLOBAL group_replication_bootstrap_group=OFF;
# 檢視MGR組資訊
mysql> SELECT * FROM performance_schema.replication_group_members;
+---------------------------+--------------------------------------+--------------+-------------+--------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+--------------+-------------+--------------+
| group_replication_applier | 7777f2fe-bd6b-11e9-aad5-08002789d401 | 192.168.8.71 | 3306 | ONLINE |
+---------------------------+--------------------------------------+--------------+-------------+--------------+
1 row in set (0.00 sec)
# 其他節點加入MGR,在從庫(192.168.8.72,192.168.8.73)上執行
mysql> START GROUP_REPLICATION;
# 檢視MGR組資訊
mysql> SELECT channel_name,
-> member_id,
-> member_host,
-> member_port,
-> member_state,
-> IF(global_status.variable_name IS NOT NULL, 'PRIMARY', 'SECONDARY') AS member_role
-> FROM performance_schema.replication_group_members
-> LEFT JOIN performance_schema.global_status
-> ON global_status.variable_name = 'group_replication_primary_member'
-> AND global_status.variable_value = replication_group_members.member_id;
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+
| channel_name | member_id | member_host | member_port | member_state | member_role |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+
| group_replication_applier | 7777f2fe-bd6b-11e9-aad5-08002789d401 | 192.168.8.71 | 3306 | ONLINE | PRIMARY |
| group_replication_applier | 7777f2fe-bd6b-11e9-aad5-08002789d402 | 192.168.8.72 | 3306 | ONLINE | SECONDARY |
| group_replication_applier | 7777f2fe-bd6b-11e9-aad5-08002789d403 | 192.168.8.73 | 3306 | ONLINE | SECONDARY |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+
3 rows in set (0.00 sec)
可以看到,3個節點狀態為online,並且主節點為192.168.8.71,只有主節點可以寫入,其他節點只讀,MGR單主模式搭建成功
3.6 切換到多主模式
MGR切換模式需要重新啟動組複製,因些需要在所有節點上先關閉組複製,設定 group_replication_single_primary_mode=OFF 等引數,再啟動組複製。
# 停止組複製(所有節點執行):
mysql> stop group_replication;
mysql> set global group_replication_single_primary_mode=OFF;
mysql> set global group_replication_enforce_update_everywhere_checks=ON;
# 隨便選擇某個節點執行
mysql> SET GLOBAL group_replication_bootstrap_group=ON;
mysql> START GROUP_REPLICATION;
mysql> SET GLOBAL group_replication_bootstrap_group=OFF;
# 其他節點執行
mysql> START GROUP_REPLICATION;
# 檢視組資訊,所有節點的 MEMBER_ROLE 都為 PRIMARY
mysql> SELECT channel_name,
-> member_id,
-> member_host,
-> member_port,
-> member_state,
-> IF(global_status.variable_name IS NOT NULL, 'PRIMARY', 'SECONDARY') AS member_role
-> FROM performance_schema.replication_group_members
-> LEFT JOIN performance_schema.global_status
-> ON global_status.variable_name = 'group_replication_primary_member'
-> AND global_status.variable_value = replication_group_members.member_id;
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+
| channel_name | member_id | member_host | member_port | member_state | member_role |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+
| group_replication_applier | 7777f2fe-bd6b-11e9-aad5-08002789d401 | 192.168.8.71 | 3306 | ONLINE | PRIMARY |
| group_replication_applier | 7777f2fe-bd6b-11e9-aad5-08002789d402 | 192.168.8.72 | 3306 | ONLINE |
PRIMARY |
| group_replication_applier | 7777f2fe-bd6b-11e9-aad5-08002789d403 | 192.168.8.73 | 3306 | ONLINE |
PRIMARY |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+
3 rows in set (0.00 sec)
可以看到所有節點狀態都是online,角色都是PRIMARY,MGR多主模式搭建成功。
3.7 切回單主模式
# 所有節點執行
mysql> stop group_replication;
mysql> set global group_replication_enforce_update_everywhere_checks=OFF;
mysql> set global group_replication_single_primary_mode=ON;
# 主節點(192.168.8.71)執行
SET GLOBAL group_replication_bootstrap_group=ON;
START GROUP_REPLICATION;
SET GLOBAL group_replication_bootstrap_group=OFF;
# 從節點(192.168.8.72、192.168.8.73)執行
START GROUP_REPLICATION;
# 檢視MGR組資訊
mysql> SELECT channel_name,
-> member_id,
-> member_host,
-> member_port,
-> member_state,
-> IF(global_status.variable_name IS NOT NULL, 'PRIMARY', 'SECONDARY') AS member_role
-> FROM performance_schema.replication_group_members
-> LEFT JOIN performance_schema.global_status
-> ON global_status.variable_name = 'group_replication_primary_member'
-> AND global_status.variable_value = replication_group_members.member_id;
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+
| channel_name | member_id | member_host | member_port | member_state | member_role |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+
| group_replication_applier | 7777f2fe-bd6b-11e9-aad5-08002789d401 | 192.168.8.71 | 3306 | ONLINE | PRIMARY |
| group_replication_applier | 7777f2fe-bd6b-11e9-aad5-08002789d402 | 192.168.8.72 | 3306 | ONLINE | SECONDARY |
| group_replication_applier | 7777f2fe-bd6b-11e9-aad5-08002789d403 | 192.168.8.73 | 3306 | ONLINE | SECONDARY |
+---------------------------+--------------------------------------+--------------+-------------+--------------+-------------+
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29812844/viewspace-2658453/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL MGR 叢集搭建MySql
- MySQL MGR單主模式詳細搭建過程MySql模式
- MySQL+MGR 單主模式和多主模式的叢集環境 - 部署手冊 (Centos7.5)MySql模式CentOS
- MySQL組複製(MGR)全解析 Part 5 MGR單主模式部署指南MySql模式
- 在Docker中安裝MySQL 8.0.19之MGR(單主模式&多主模式)+新增節點DockerMySql模式
- MySQL組複製(MGR)全解析 Part 4 MGR單主模式部署前準備MySql模式
- mysql叢集搭建MySql
- docker搭建mysql叢集DockerMySql
- MySQL 5.7 叢集搭建MySql
- mysql8叢集搭建MySql
- MySQL叢集搭建方案(PXC)MySql
- 單機MGR搭建
- MySQL叢集搭建(1)-主備搭建MySql
- mysql8.0.31 mgr搭建MySql
- Linux中Mysql的叢集搭建LinuxMySql
- MySQL5.7叢集(MGR)啟動報ERROR 3092 (HY000)MySqlError
- Hadoop HA叢集簡單搭建Hadoop
- MySQL之MGR白名單MySql
- Redis叢集搭建與簡單使用Redis
- 搭建 MySQL 高可用高效能叢集MySql
- 搭建zookeeper叢集(偽叢集)
- MGR(MySQL Group Replication)部署搭建測試MySql
- swarm mode叢集搭建及簡單概念Swarm
- zookeeper叢集及kafka叢集搭建Kafka
- MySQL叢集搭建(6)-雙主+keepalived高可用MySql
- Docker Compose搭建MySQL主從複製叢集DockerMySql
- haproxy(單機)+mysql叢集負載均衡MySql負載
- Redis系列:搭建Redis叢集(叢集模式)Redis模式
- linux下搭建ZooKeeper叢集(偽叢集)Linux
- Hadoop叢集搭建Hadoop
- Zookeeper叢集搭建
- redis叢集搭建Redis
- zookeeper 叢集搭建
- 搭建 Redis 叢集Redis
- RabbitMQ叢集搭建MQ
- nacos 叢集搭建
- HBASE叢集搭建
- 搭建ELK叢集