RPM安装并构建MGR集群
本文档主要介绍如何用RPM包方式安装GreatSQL数据库,假定本次安装是在CentOS 8.x x86_64环境中安装,并且是以root用户身份执行安装操作。
在开始安装前,请根据文档 安装准备 已经完成准备工作。
1. MGR集群规划
本次计划在3台服务器上安装GreatSQL数据库并部署MGR集群:
| node | ip | datadir | port | role |
|---|---|---|---|---|
| GreatSQL-01 | 172.16.16.10 | /data/GreatSQL/ | 3306 | PRIMARY |
| GreatSQL-02 | 172.16.16.11 | /data/GreatSQL/ | 3306 | SECONDARY |
| GreatSQL-03 | 172.16.16.12 | /data/GreatSQL/ | 3306 | ARBITRATOR |
以下安装配置工作先在三个节点都同样操作一遍。
2. 下载安装包
点击此处
(opens new window)下载最新的安装包,下载以下几个就可以:
- greatsql-client-8.0.32-24.1.el8.x86_64.rpm
- greatsql-devel-8.0.32-24.1.el8.x86_64.rpm
- greatsql-icu-data-files-8.0.32-24.1.el8.x86_64.rpm
- greatsql-shared-8.0.32-24.1.el8.x86_64.rpm
- greatsql-server-8.0.32-24.1.el8.x86_64.rpm
3. 安装GreatSQL RPM包
执行下面的命令安装PRM包,如果一切顺利的话,相应的过程如下所示:
1. $ rpm -ivh greatsql*rpm
2. Verifying... ################################# [100%]
3. Preparing... ################################# [100%]
4. Updating / installing...
5. 1:greatsql-shared-8.0.32-24.1.el8 ################################# [ 20%]
6. 2:greatsql-client-8.0.32-24.1.el8 ################################# [ 40%]
7. 3:greatsql-icu-data-files-8.0.32-24################################# [ 60%]
8. 4:greatsql-server-8.0.32-24.1.el8 ################################# [ 80%]
9. 5:greatsql-devel-8.0.32-24.1.el8 ################################# [100%]
这就安装成功了。
提示:
- 安装GreatSQL RPM包需要先安装其他依赖包,可执行下面命令完成:
yum install -y pkg-config perl libaio-devel numactl-devel numactl-libs net-tools openssl openssl-devel jemalloc jemalloc-devel perl-Data-Dumper perl-Digest-MD5更详细的请参考:安装准备。
其他部分依赖包,如果通过YUM还是无法安装,则加上 --nodeps --force 强制忽略即可,例如:
1. $ rpm -ivh greatsql*rpm
2. error: Failed dependencies:
3. perl(Lmo) is needed by greatsql-server-8.0.32-24.1.el8.x86_64
4. perl(Lmo::Meta) is needed by greatsql-server-8.0.32-24.1.el8.x86_64
5. perl(Lmo::Object) is needed by greatsql-server-8.0.32-24.1.el8.x86_64
6. perl(Lmo::Types) is needed by greatsql-server-8.0.32-24.1.el8.x86_64
7. perl(Lmo::Utils) is needed by greatsql-server-8.0.32-24.1.el8.x86_64
8. perl(Percona::Toolkit) is needed by greatsql-server-8.0.32-24.1.el8.x86_64
9. perl(Quoter) is needed by greatsql-server-8.0.32-24.1.el8.x86_64
10. perl(Transformers) is needed by greatsql-server-8.0.32-24.1.el8.x86_64
12. #上述这些依赖包可以先忽略,不影响GreatSQL正常使用
14. $ rpm -ivh --nodeps --force greatsql*rpm
15. Preparing... ################################# [100%]
16. Updating / installing...
17. 1:greatsql-shared-8.0.32-24.1.el7 ################################# [ 20%]
18. 2:greatsql-client-8.0.32-24.1.el7 ################################# [ 40%]
19. 3:greatsql-icu-data-files-8.0.32-24################################# [ 60%]
20. 4:greatsql-server-8.0.32-24.1.el7 ################################# [ 80%]
21. 5:greatsql-devel-8.0.32-24.1.el7 ################################# [100%]
- 正式安装GreatSQL RPM包时,可能还需要依赖Perl等其他软件包,此处为快速演示,因此加上
--nodeps参数,忽略相应的依赖关系检查。安装完毕后,如果因为依赖关系无法启动,请再行安装相应软件依赖包。
4. 启动前准备
4.1、修改 /etc/my.cnf 配置文件
参考这份文件
(opens new window),可根据实际情况修改,一般主要涉及数据库文件分区、目录,内存配置等少数几个选项。以下面这份为例:
1. #my.cnf
2. [client]
3. user = root
4. datadir = /data/GreatSQL/mysql.sock
6. [mysqld]
7. user = mysql
8. port = 3306
9. #主从复制或MGR集群中,server_id记得要不同
10. #另外,实例启动时会生成 auto.cnf,里面的 server_uuid 值也要不同
11. #server_uuid的值还可以自己手动指定,只要符合uuid的格式标准就可以
12. server_id = 3306
13. basedir = /usr/
14. datadir = /data/GreatSQL
15. socket = mysql.sock
16. pid-file = mysql.pid
17. character-set-server = UTF8MB4
18. skip_name_resolve = 1
19. #若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数
20. default_time_zone = "+8:00"
22. #performance setttings
23. lock_wait_timeout = 3600
24. open_files_limit = 65535
25. back_log = 1024
26. max_connections = 512
27. max_connect_errors = 1000000
28. table_open_cache = 1024
29. table_definition_cache = 1024
30. thread_stack = 512K
31. sort_buffer_size = 4M
32. join_buffer_size = 4M
33. read_buffer_size = 8M
34. read_rnd_buffer_size = 4M
35. bulk_insert_buffer_size = 64M
36. thread_cache_size = 768
37. interactive_timeout = 600
38. wait_timeout = 600
39. tmp_table_size = 32M
40. max_heap_table_size = 32M
41. max_allowed_packet = 64M
42. net_buffer_shrink_interval = 180
43. #GIPK
44. loose-sql_generate_invisible_primary_key = ON
46. #log settings
47. log_timestamps = SYSTEM
48. log_error = error.log
49. log_error_verbosity = 3
50. slow_query_log = 1
51. log_slow_extra = 1
52. slow_query_log_file = slow.log
53. #设置slow log文件大小1G及总文件数10
54. max_slowlog_size = 1073741824
55. max_slowlog_files = 10
56. long_query_time = 0.1
57. log_queries_not_using_indexes = 1
58. log_throttle_queries_not_using_indexes = 60
59. min_examined_row_limit = 100
60. log_slow_admin_statements = 1
61. log_slow_slave_statements = 1
62. log_bin = binlog
63. binlog_format = ROW
64. sync_binlog = 1
65. binlog_cache_size = 4M
66. max_binlog_cache_size = 2G
67. max_binlog_size = 1G
68. #控制binlog总大小,避免磁盘空间被撑爆
69. binlog_space_limit = 500G
70. binlog_rows_query_log_events = 1
71. binlog_expire_logs_seconds = 604800
72. #MySQL 8.0.22前,想启用MGR的话,需要设置binlog_checksum=NONE才行
73. binlog_checksum = CRC32
74. gtid_mode = ON
75. enforce_gtid_consistency = TRUE
77. #myisam settings
78. key_buffer_size = 32M
79. myisam_sort_buffer_size = 128M
81. #replication settings
82. relay_log_recovery = 1
83. slave_parallel_type = LOGICAL_CLOCK
84. #可以设置为逻辑CPU数量的2倍
85. slave_parallel_workers = 64
86. binlog_transaction_dependency_tracking = WRITESET
87. slave_preserve_commit_order = 1
88. slave_checkpoint_period = 2
90. #mgr settings
91. loose-plugin_load_add = 'mysql_clone.so'
92. loose-plugin_load_add = 'group_replication.so'
93. loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"
94. #MGR本地节点IP:PORT,请自行替换
95. loose-group_replication_local_address = "172.16.16.10:33061"
96. #MGR集群所有节点IP:PORT,请自行替换
97. loose-group_replication_group_seeds = "172.16.16.10:33061,172.16.16.11:33061,172.16.16.12:33061"
98. loose-group_replication_start_on_boot = ON
99. loose-group_replication_bootstrap_group = OFF
100. loose-group_replication_exit_state_action = READ_ONLY
101. loose-group_replication_flow_control_mode = "DISABLED"
102. loose-group_replication_single_primary_mode = ON
103. loose-group_replication_majority_after_mode = ON
104. loose-group_replication_communication_max_message_size = 10M
105. loose-group_replication_arbitrator = 0
106. loose-group_replication_single_primary_fast_mode = 1
107. loose-group_replication_request_time_threshold = 100
108. loose-group_replication_primary_election_mode = GTID_FIRST
109. loose-group_replication_unreachable_majority_timeout = 0
110. loose-group_replication_member_expel_timeout = 5
111. loose-group_replication_autorejoin_tries = 288
112. report_host = "172.16.16.10"
114. #innodb settings
115. innodb_buffer_pool_size = 64G
116. innodb_buffer_pool_instances = 8
117. innodb_data_file_path = ibdata1:12M:autoextend
118. innodb_flush_log_at_trx_commit = 1
119. innodb_log_buffer_size = 32M
120. innodb_log_file_size = 2G
121. innodb_log_files_in_group = 3
122. innodb_redo_log_capacity = 6G
123. innodb_max_undo_log_size = 4G
124. # 根据您的服务器IOPS能力适当调整
125. # 一般配普通SSD盘的话,可以调整到 10000 - 20000
126. # 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
127. innodb_io_capacity = 4000
128. innodb_io_capacity_max = 8000
129. innodb_open_files = 65535
130. innodb_flush_method = O_DIRECT
131. innodb_lru_scan_depth = 4000
132. innodb_lock_wait_timeout = 10
133. innodb_rollback_on_timeout = 1
134. innodb_print_all_deadlocks = 1
135. innodb_online_alter_log_max_size = 4G
136. innodb_print_ddl_logs = 0
137. innodb_status_file = 1
138. #注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log_error文件增长较快
139. innodb_status_output = 0
140. innodb_status_output_locks = 1
141. innodb_sort_buffer_size = 67108864
142. innodb_adaptive_hash_index = 0
143. #开启NUMA支持
144. innodb_numa_interleave = ON
145. innodb_print_lock_wait_timeout_info = 1
146. #自动杀掉超过5分钟不活跃事务,避免行锁被长时间持有
147. kill_idle_transaction = 300
149. #innodb monitor settings
150. #innodb_monitor_enable = "module_innodb,module_server,module_dml,module_ddl,module_trx,module_os,module_purge,module_log,module_lock,module_buffer,module_index,module_ibuf_system,module_buffer_page,module_adaptive_hash"
152. #innodb parallel query
153. loose-force_parallel_execute = OFF
154. loose-parallel_default_dop = 8
155. loose-parallel_max_threads = 96
156. temptable_max_ram = 8G
158. #pfs settings
159. performance_schema = 1
160. #performance_schema_instrument = '%memory%=on'
161. performance_schema_instrument = '%lock%=on'
4.2、新建数据库主目录,并修改权限模式及属主
1. $ mkdir -p /data/GreatSQL
2. $ chown -R mysql:mysql /data/GreatSQL
3. $ chmod -R 700 /data/GreatSQL
5. 启动GreatSQL
启动GreatSQL服务前,先修改systemd文件,调高一些limit上限,避免出现文件数、线程数不够用的告警。
1. # 在[Server]区间增加下面几行内容
2. $ vim /lib/systemd/system/mysqld.service
3. ...
4. [Service]
6. # some limits
7. # file size
8. LimitFSIZE=infinity
9. # cpu time
10. LimitCPU=infinity
11. # virtual memory size
12. LimitAS=infinity
13. # open files
14. LimitNOFILE=65535
15. # processes/threads
16. LimitNPROC=65535
17. # locked memory
18. LimitMEMLOCK=infinity
19. # total threads (user+kernel)
20. TasksMax=infinity
21. TasksAccounting=false
22. ...
保存退出,然后再执行命令重载systemd,如果没问题就不会报错:
1. $ systemctl daemon-reload
执行下面的命令启动GreatSQL服务
1. $ systemctl start mysqld
检查服务是否已启动,以及进程状态:
1. $ systemctl status mysqld
2. ● mysqld.service - MySQL Server
3. Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
4. Active: active (running) since Fri 2022-07-08 14:10:14 CST; 5min ago
5. Docs: man:mysqld(8)
6. http://dev.mysql.com/doc/refman/en/using-systemd.html
7. Process: 51902 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
8. Main PID: 52003 (mysqld)
9. Status: "Server is operational"
10. Tasks: 48 (limit: 149064)
11. Memory: 5.5G
12. CGroup: /system.slice/mysqld.service
13. └─52003 /usr/sbin/mysqld
15. Jul 08 14:10:06 db170 systemd[1]: Starting MySQL Server...
16. Jul 08 14:10:14 db170 systemd[1]: Started MySQL Server.
18. $ ps -ef | grep mysqld
19. mysql 43653 1 3 10:35 ? 00:00:02 /usr/sbin/mysqld
21. $ ss -lntp | grep mysqld
22. LISTEN 0 70 *:33060 *:* users:(("mysqld",pid=43653,fd=23))
23. LISTEN 0 128 *:3306 *:* users:(("mysqld",pid=43653,fd=26))
25. # 查看数据库文件
26. $ ls /data/GreatSQL
27. auto.cnf client-key.pem '#ib_16384_14.dblwr' '#ib_16384_6.dblwr' ib_logfile1 mysql.pid server-key.pem
28. binlog.000001 error.log '#ib_16384_15.dblwr' '#ib_16384_7.dblwr' ib_logfile2 mysql.sock slow.log
29. binlog.000002 '#ib_16384_0.dblwr' '#ib_16384_1.dblwr' '#ib_16384_8.dblwr' ibtmp1 mysql.sock.lock sys
30. binlog.index '#ib_16384_10.dblwr' '#ib_16384_2.dblwr' '#ib_16384_9.dblwr' innodb_status.52003 performance_schema undo_001
31. ca-key.pem '#ib_16384_11.dblwr' '#ib_16384_3.dblwr' ib_buffer_pool '#innodb_temp' private_key.pem undo_002
32. ca.pem '#ib_16384_12.dblwr' '#ib_16384_4.dblwr' ibdata1 mysql public_key.pem
33. client-cert.pem '#ib_16384_13.dblwr' '#ib_16384_5.dblwr' ib_logfile0 mysql.ibd server-cert.pem
可以看到,GreatSQL服务已经正常启动了。
顺便确认动态库 jemalloc 成功加载:
1. $ lsof -p 43653 | grep -i jema
2. mysqld 52003 mysql mem REG 253,0 608096 68994440 /usr/lib64/libjemalloc.so.2
6. 连接登入GreatSQL
RPM方式安装GreatSQL后,会随机生成管理员root的密码,通过搜索日志文件获取:
1. $ grep -i root /var/log/mysqld.log
2. 2022-07-08T14:10:09.670473+08:00 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ahaA(ACmw8wy
可以看到,root账户的密码是:”ahaA(ACmw8wy” (不包含双引号),复制到粘贴板里。
首次登入GreatSQL后,要立即修改root密码,否则无法执行其他操作,并且新密码要符合一定安全规则:
1. $ mysql -uroot -p
2. Enter password: #<--这个地方粘贴上面复制的随机密码
3. Welcome to the MySQL monitor. Commands end with ; or \g.
4. Your MySQL connection id is 8
5. Server version: 8.0.32-24 GreatSQL, Release 24, Revision 3714067bc8c
7. Copyright (c) 2021-2023 GreatDB Software Co., Ltd
8. Copyright (c) 2009-2021 Percona LLC and/or its affiliates
9. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
10. ...
11. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
13. greatsql> \s #<--想执行一个命令,提示要先修改密码
14. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
16. greatsql> alter user user() identified by 'GreatSQL@202X'; #<--修改密码
17. Query OK, 0 rows affected (0.02 sec)
19. greatsql> \s #<--就可以正常执行其他命令了
20. --------------
21. mysql Ver 8.0.32-24 for Linux on x86_64 (GreatSQL, Release 24, Revision 3714067bc8c)
23. Connection id: 8
24. Current database:
25. Current user: root@localhost
26. SSL: Not in use
27. Current pager: stdout
28. Using outfile: ''
29. Using delimiter: ;
30. Server version: 8.0.32-24 GreatSQL, Release 24, Revision 3714067bc8c
31. Protocol version: 10
32. Connection: Localhost via UNIX socket
33. Server characterset: utf8mb4
34. Db characterset: utf8mb4
35. Client characterset: utf8mb4
36. Conn. characterset: utf8mb4
37. UNIX socket: /data/GreatSQL/mysql.sock
38. Binary data as: Hexadecimal
39. Uptime: 20 min 8 sec
41. Threads: 2 Questions: 7 Slow queries: 0 Opens: 130 Flush tables: 3 Open tables: 46 Queries per second avg: 0.005
42. --------------
44. greatsql> show databases; #<--查看数据库列表
45. +--------------------+
46. | Database |
47. +--------------------+
48. | information_schema |
49. | mysql |
50. | performance_schema |
51. | sys |
52. +--------------------+
53. 4 rows in set (0.01 sec)
55. greatsql>
7. 关闭/重启GreatSQL
执行下面的命令关闭GreatSQL数据库。
1. $ systemctl stop mysqld
执行下面的命令重启GreatSQL数据库。
1. $ systemctl restart mysqld
GreatSQL数据库安装并初始化完毕。
8. 安装MySQL Shell
为了支持仲裁节点特性,需要安装GreatSQL提供的MySQL Shell发行包。打开GreatSQL下载页面
(opens new window),找到 7. GreateSQL MySQL Shell,下载相应的MySQL Shell安装包(目前只提供二进制安装包)。
P.S,如果暂时不想使用仲裁节点特性的话,则可以继续使用相同版本的官方MySQL Shell安装包,可以直接用YUM方式安装,此处略过。
本文场景中,选择下面的二进制包:
- greatsql-shell-8.0.25-16-Linux-glibc2.28-x86_64.tar.xz
将二进制文件包放在 /usr/local 目录下,解压缩:
1. $ cd /usr/local/
2. $ tar xf greatsql-shell-8.0.25-16-Linux-glibc2.28-x86_64.tar.xz
修改家目录下的profile文件,加入PATH:
1. $ vim ~/.bash_profile
3. ...
4. PATH=$PATH:$HOME/bin:/usr/local/greatsql-shell-8.0.25-16-Linux-glibc2.28-x86_64/bin
6. export PATH
加载一下
1. $ source ~/.bash_profile
这样就可以直接执行 mysqlsh,而无需每次都加上全路径了。
第一次启动mysqlsh时,可能会有类似下面的提示:
1. WARNING: Found errors loading plugins, for more details look at the log at: /root/.mysqlsh/mysqlsh.log
执行下面的指令安装certifi这个Python模块即可:
1. $ pip3.6 install --user certifi
9. 准备构建MGR集群
在这里建议用MySQL Shell来构建MGR集群,相对于手工构建方便快捷很多,如果想要体验手工构建的同学可以参考这篇文档:3. 安装部署MGR集群 | 深入浅出MGR
(opens new window)。
利用MySQL Shell构建MGR集群比较简单,主要有几个步骤:
- 检查实例是否满足条件。
- 创建并初始化一个集群。
- 逐个添加实例。
接下来一步步执行。
9.1、MGR节点预检查
用管理员账号 root 连接到第一个节点:
1. #在本地通过socket方式登入
2. $ mysqlsh -S/data/GreatSQL/mysql.sock root@localhost
3. Please provide the password for 'root@.%2Fmysql.sock': ******** <-- 输入root密码
4. Save password for 'root@.%2Fmysql.sock'? [Y]es/[N]o/Ne[v]er (default No): yes <-- 提示是否存储密码(视各公司安全规则而定,这里为了方便选择了存储密码)
5. MySQL Shell 8.0.25
6. ...
7. Server version: 8.0.32-24 GreatSQL, Release 24, Revision 3714067bc8c
8. No default schema selected; type \use <schema> to set one.
9. WARNING: Found errors loading plugins, for more details look at the log at: /root/.mysqlsh/mysqlsh.log
10. MySQL localhost Py >
接下来,执行 dba.configure_instance命令开始检查当前实例是否准备好了,可以作为MGR集群的一个节点:
1. # 开始配置MGR节点
2. MySQL 172.16.16.10:3306 ssl Py > dba.configure_instance();
3. Configuring local MySQL instance listening at port 3306 for use in an InnoDB cluster...
5. This instance reports its own address as GreatSQL-01:3306
6. Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.
8. # 提示root账号不能运行MGR服务,需要创建新的专用账号
9. ERROR: User 'root' can only connect from 'localhost'. New account(s) with proper source address specification to allow remote connection from all instances must be created to manage the cluster.
11. 1) Create remotely usable account for 'root' with same grants and password
12. 2) Create a new admin account for InnoDB cluster with minimal required grants
13. 3) Ignore and continue
14. 4) Cancel
16. Please select an option [1]: 2 #<-- 选择创建最小权限账号
17. Please provide an account name (e.g: icroot@%) to have it created with the necessary
18. privileges or leave empty and press Enter to cancel.
19. Account Name: GreatSQL <-- 输入账号名
20. Password for new account: ******* <-- 输入密码***
21. Confirm password: ******* <-- 再次确认密码
23. #节点初始化完毕
24. The instance 'GreatSQL-01:3306' is valid to be used in an InnoDB cluster.
26. #MGR管理账号创建完毕
27. Cluster admin user 'GreatSQL'@'%' created.
28. The instance 'GreatSQL-01:3306' is already ready to be used in an InnoDB cluster.
这里切换到MySQL Shell的Python风格下了,如果是Javascript风格的话,则函数名是 dba.configureInstance()。
GreatSQL提供的MySQL Shell二进制包不支持Javascript语法,因为编译时没有libv8库,所以只能支持Python/SQL语法。
截止到这里,以上所有步骤在另外两个节点 GreatSQL-02、GreatSQL-03 也同样执行一遍。
9.2、创建并初始化一个集群
在正式初始化MGR集群前,再次提醒要先再其他节点完成上述初始化工作。
上述另外两个节点也初始化完毕后,利用mysqlsh客户端,指定新建MGR的管理账号GreatSQL登入PRIMARY节点,准备创建MGR集群:
1. $ mysqlsh --uri GreatSQL@172.16.16.10:3306
2. Please provide the password for 'GreatSQL@172.16.16.10:3306': *************
3. Save password for 'GreatSQL@172.16.16.10:3306'? [Y]es/[N]o/Ne[v]er (default No): yes
4. MySQL Shell 8.0.25
5. ...
6. Server version: 8.0.32-24 GreatSQL, Release 24, Revision 3714067bc8c
7. No default schema selected; type \use <schema> to set one.
9. # 选定GreatSQL-01节点作为PRIMARY,开始创建MGR集群
10. # 集群命名为 GreatSQLMGR,后面mysqlrouter读取元数据时用得上
11. MySQL 172.16.16.10:3306 ssl Py > c = dba.create_cluster('GreatSQLMGR');
12. A new InnoDB cluster will be created on instance '172.16.16.10:3306'.
14. Validating instance configuration at 172.16.16.10:3306...
16. This instance reports its own address as GreatSQL-01:3306
18. Instance configuration is suitable.
19. NOTE: Group Replication will communicate with other members using 'GreatSQL-01:33061'. Use the localAddress option to override.
21. Creating InnoDB cluster 'GreatSQLMGR' on 'GreatSQL-01:3306'...
23. Adding Seed Instance...
24. Cluster successfully created. Use Cluster.add_instance() to add MySQL instances.
25. At least 3 instances are needed for the cluster to be able to withstand up to
26. one server failure.
27. MySQL 172.16.16.10:3306 ssl Py >
集群已经创建并初始化完毕,接下来就是继续添加其他节点了。
9.3、逐个添加实例
可以在GreatSQL-01(PRIMARY)节点上直接添加其他节点,也可以用mysqlsh客户端登入其他节点执行添加节点操作。这里采用前者:
1. # 此时mysqlsh客户端还保持连接到GreatSQL-01节点
2. # 可以直接添加GreatSQL-02节点
3. MySQL 172.16.16.10:3306 ssl Py > c.add_instance('GreatSQL@172.16.16.11:3306'); <-- 添加GreatSQL-02节点
4. NOTE: The target instance 'GreatSQL-02:3306' has not been pre-provisioned (GTID set is empty). The Shell is unable to decide whether incremental state recovery can correctly provision it.
5. The safest and most convenient way to provision a new instance is through automatic clone provisioning, which will completely overwrite the state of 'GreatSQL-02:3306' with a physical snapshot from an existing cluster member. To use this method by default, set the 'recoveryMethod' option to 'clone'.
7. The incremental state recovery may be safely used if you are sure all updates ever executed in the cluster were done with GTIDs enabled, there are no purged transactions and the new instance contains the same GTID set as the cluster or a subset of it. To use this method by default, set the 'recoveryMethod' option to 'incremental'.
9. # 选择恢复模式:克隆/增量恢复/忽略,默认选择克隆
10. Please select a recovery method [C]lone/[I]ncremental recovery/[A]bort (default Clone):
11. Validating instance configuration at 172.16.16.11:3306...
13. This instance reports its own address as GreatSQL-02:3306
15. Instance configuration is suitable.
16. NOTE: Group Replication will communicate with other members using 'GreatSQL-02:33061'. Use the localAddress option to override.
18. A new instance will be added to the InnoDB cluster. Depending on the amount of
19. data on the cluster this might take from a few seconds to several hours.
21. Adding instance to the cluster...
23. Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.
24. Clone based state recovery is now in progress.
26. # 提示在这个过程中需要重启GreatSQL-02节点实例
27. # 如果无法自动重启,需要手动重启
28. NOTE: A server restart is expected to happen as part of the clone process. If the
29. server does not support the RESTART command or does not come back after a
30. while, you may need to manually start it back.
32. * Waiting for clone to finish...
33. # 从GreatSQL-01节点克隆数据
34. NOTE: GreatSQL-02:3306 is being cloned from GreatSQL-01:3306
35. ** Stage DROP DATA: Completed
36. ** Clone Transfer
37. FILE COPY ############################################################ 100% Completed
38. PAGE COPY ############################################################ 100% Completed
39. REDO COPY ############################################################ 100% Completed
40. NOTE: GreatSQL-02:3306 is shutting down...
42. * Waiting for server restart... \ <-- 重启中
43. * Waiting for server restart... ready <-- 重启完毕,如果没有加入systemed,则需要自己手工启动
44. * GreatSQL-02:3306 has restarted, waiting for clone to finish...
45. ** Stage RESTART: Completed
46. * Clone process has finished: 59.62 MB transferred in about 1 second (~59.62 MB/s)
48. State recovery already finished for 'GreatSQL-02:3306'
50. # 新节点 GreatSQL-02:3306 已加入集群
51. The instance 'GreatSQL-02:3306' was successfully added to the cluster.
这就将 GreatSQL-02 节点加入MGRT集群中了,此时可以先查看下集群状态。
1. MySQL 172.16.16.10:3306 ssl Py > c.status()
2. {
3. "clusterName": "GreatSQLMGR",
4. "defaultReplicaSet": {
5. "name": "default",
6. "primary": "172.16.16.10:3306",
7. "ssl": "REQUIRED",
8. "status": "OK_NO_TOLERANCE",
9. "statusText": "Cluster is NOT tolerant to any failures.",
10. "topology": {
11. "172.16.16.10:3306": {
12. "address": "172.16.16.10:3306",
13. "memberRole": "PRIMARY",
14. "mode": "R/W",
15. "readReplicas": {},
16. "replicationLag": null,
17. "role": "HA",
18. "status": "ONLINE",
19. "version": "8.0.32"
20. },
21. "172.16.16.11:3306": {
22. "address": "172.16.16.11:3306",
23. "memberRole": "SECONDARY",
24. "mode": "R/O",
25. "readReplicas": {},
26. "replicationLag": null,
27. "role": "HA",
28. "status": "ONLINE",
29. "version": "8.0.32"
30. }
31. },
32. "topologyMode": "Single-Primary"
33. },
34. "groupInformationSourceMember": "172.16.16.10:3306"
35. }
可以看到,一个包含两节点的MGR集群已经构建好了,Primary节点是 172.16.16.10:3306,接下来还要加入另一个节点:仲裁节点。
如果不想体验仲裁节点特性的话,可以照着上面操作再次正常加入 GreatSQL-03 节点作为 Secondary 节点即可,到这里就可以结束MGR集群构建工作了。
9.4、添加仲裁节点
编辑 GreatSQL-03 节点上的 /etc/my.cnf 配置文件,加入/修改下面这行内容:
1. loose-group_replication_arbitrator = 1
其作用就是指定该节点作为仲裁节点,保存退出,重启该节点GreatSQL数据库。
然后照着第三步的操作,调用 dba.add_instance() 添加新节点,就可以直接将仲裁节点加入MGR集群了,再次查看集群状态:
1. MySQL 172.16.16.10:3306 ssl Py > c.status()
2. {
3. "clusterName": "GreatSQLMGR",
4. "defaultReplicaSet": {
5. "name": "default",
6. "primary": "172.16.16.10:3306",
7. "ssl": "REQUIRED",
8. "status": "OK",
9. "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
10. "topology": {
11. "172.16.16.10:3306": {
12. "address": "172.16.16.10:3306",
13. "memberRole": "PRIMARY",
14. "mode": "R/W",
15. "readReplicas": {},
16. "replicationLag": null,
17. "role": "HA",
18. "status": "ONLINE",
19. "version": "8.0.32"
20. },
21. "172.16.16.11:3306": {
22. "address": "172.16.16.11:3306",
23. "memberRole": "SECONDARY",
24. "mode": "R/O",
25. "readReplicas": {},
26. "replicationLag": null,
27. "role": "HA",
28. "status": "ONLINE",
29. "version": "8.0.32"
30. },
31. "172.16.16.12:3306": {
32. "address": "172.16.16.12:3306",
33. "memberRole": "ARBITRATOR",
34. "mode": "R/O",
35. "readReplicas": {},
36. "replicationLag": null,
37. "role": "HA",
38. "status": "ONLINE",
39. "version": "8.0.32"
40. }
41. },
42. "topologyMode": "Single-Primary"
43. },
44. "groupInformationSourceMember": "172.16.16.10:3306"
45. }
可以看到一个包含仲裁节点的三节点MGR集群已经构建完毕。
在后面的内容中,我们再介绍如何手工方式部署MGR集群,以及利用MySQL Router实现读写分离及读可扩展,详见:读写分离。
问题反馈
联系我们
扫码关注微信公众号

