RPM安装并构建MGR集群


本文档主要介绍如何用RPM包方式安装GreatSQL数据库,假定本次安装是在CentOS 8.x x86_64环境中安装,并且是以root用户身份执行安装操作。

在开始安装前,请根据文档 安装准备 已经完成准备工作。

1. MGR集群规划

本次计划在3台服务器上安装GreatSQL数据库并部署MGR集群:

nodeipdatadirportrole
GreatSQL-01172.16.16.10/data/GreatSQL/3306PRIMARY
GreatSQL-02172.16.16.11/data/GreatSQL/3306SECONDARY
GreatSQL-03172.16.16.12/data/GreatSQL/3306ARBITRATOR

以下安装配置工作先在三个节点都同样操作一遍。

2. 下载安装包

点击此处RPM安装并构建MGR集群 - 图1 (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%]

这就安装成功了。

提示

  1. 安装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
  11. #上述这些依赖包可以先忽略,不影响GreatSQL正常使用
  12. $ rpm -ivh --nodeps --force greatsql*rpm
  13. Preparing... ################################# [100%]
  14. Updating / installing...
  15. 1:greatsql-shared-8.0.32-24.1.el7 ################################# [ 20%]
  16. 2:greatsql-client-8.0.32-24.1.el7 ################################# [ 40%]
  17. 3:greatsql-icu-data-files-8.0.32-24################################# [ 60%]
  18. 4:greatsql-server-8.0.32-24.1.el7 ################################# [ 80%]
  19. 5:greatsql-devel-8.0.32-24.1.el7 ################################# [100%]
  1. 正式安装GreatSQL RPM包时,可能还需要依赖Perl等其他软件包,此处为快速演示,因此加上 --nodeps 参数,忽略相应的依赖关系检查。安装完毕后,如果因为依赖关系无法启动,请再行安装相应软件依赖包。

4. 启动前准备

4.1、修改 /etc/my.cnf 配置文件

参考这份文件RPM安装并构建MGR集群 - 图2 (opens new window),可根据实际情况修改,一般主要涉及数据库文件分区、目录,内存配置等少数几个选项。以下面这份为例:

  1. #my.cnf
  2. [client]
  3. user = root
  4. datadir = /data/GreatSQL/mysql.sock
  5. [mysqld]
  6. user = mysql
  7. port = 3306
  8. #主从复制或MGR集群中,server_id记得要不同
  9. #另外,实例启动时会生成 auto.cnf,里面的 server_uuid 值也要不同
  10. #server_uuid的值还可以自己手动指定,只要符合uuid的格式标准就可以
  11. server_id = 3306
  12. basedir = /usr/
  13. datadir = /data/GreatSQL
  14. socket = mysql.sock
  15. pid-file = mysql.pid
  16. character-set-server = UTF8MB4
  17. skip_name_resolve = 1
  18. #若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数
  19. default_time_zone = "+8:00"
  20. #performance setttings
  21. lock_wait_timeout = 3600
  22. open_files_limit = 65535
  23. back_log = 1024
  24. max_connections = 512
  25. max_connect_errors = 1000000
  26. table_open_cache = 1024
  27. table_definition_cache = 1024
  28. thread_stack = 512K
  29. sort_buffer_size = 4M
  30. join_buffer_size = 4M
  31. read_buffer_size = 8M
  32. read_rnd_buffer_size = 4M
  33. bulk_insert_buffer_size = 64M
  34. thread_cache_size = 768
  35. interactive_timeout = 600
  36. wait_timeout = 600
  37. tmp_table_size = 32M
  38. max_heap_table_size = 32M
  39. max_allowed_packet = 64M
  40. net_buffer_shrink_interval = 180
  41. #GIPK
  42. loose-sql_generate_invisible_primary_key = ON
  43. #log settings
  44. log_timestamps = SYSTEM
  45. log_error = error.log
  46. log_error_verbosity = 3
  47. slow_query_log = 1
  48. log_slow_extra = 1
  49. slow_query_log_file = slow.log
  50. #设置slow log文件大小1G及总文件数10
  51. max_slowlog_size = 1073741824
  52. max_slowlog_files = 10
  53. long_query_time = 0.1
  54. log_queries_not_using_indexes = 1
  55. log_throttle_queries_not_using_indexes = 60
  56. min_examined_row_limit = 100
  57. log_slow_admin_statements = 1
  58. log_slow_slave_statements = 1
  59. log_bin = binlog
  60. binlog_format = ROW
  61. sync_binlog = 1
  62. binlog_cache_size = 4M
  63. max_binlog_cache_size = 2G
  64. max_binlog_size = 1G
  65. #控制binlog总大小,避免磁盘空间被撑爆
  66. binlog_space_limit = 500G
  67. binlog_rows_query_log_events = 1
  68. binlog_expire_logs_seconds = 604800
  69. #MySQL 8.0.22前,想启用MGR的话,需要设置binlog_checksum=NONE才行
  70. binlog_checksum = CRC32
  71. gtid_mode = ON
  72. enforce_gtid_consistency = TRUE
  73. #myisam settings
  74. key_buffer_size = 32M
  75. myisam_sort_buffer_size = 128M
  76. #replication settings
  77. relay_log_recovery = 1
  78. slave_parallel_type = LOGICAL_CLOCK
  79. #可以设置为逻辑CPU数量的2倍
  80. slave_parallel_workers = 64
  81. binlog_transaction_dependency_tracking = WRITESET
  82. slave_preserve_commit_order = 1
  83. slave_checkpoint_period = 2
  84. #mgr settings
  85. loose-plugin_load_add = 'mysql_clone.so'
  86. loose-plugin_load_add = 'group_replication.so'
  87. loose-group_replication_group_name = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1"
  88. #MGR本地节点IP:PORT,请自行替换
  89. loose-group_replication_local_address = "172.16.16.10:33061"
  90. #MGR集群所有节点IP:PORT,请自行替换
  91. loose-group_replication_group_seeds = "172.16.16.10:33061,172.16.16.11:33061,172.16.16.12:33061"
  92. loose-group_replication_start_on_boot = ON
  93. loose-group_replication_bootstrap_group = OFF
  94. loose-group_replication_exit_state_action = READ_ONLY
  95. loose-group_replication_flow_control_mode = "DISABLED"
  96. loose-group_replication_single_primary_mode = ON
  97. loose-group_replication_majority_after_mode = ON
  98. loose-group_replication_communication_max_message_size = 10M
  99. loose-group_replication_arbitrator = 0
  100. loose-group_replication_single_primary_fast_mode = 1
  101. loose-group_replication_request_time_threshold = 100
  102. loose-group_replication_primary_election_mode = GTID_FIRST
  103. loose-group_replication_unreachable_majority_timeout = 0
  104. loose-group_replication_member_expel_timeout = 5
  105. loose-group_replication_autorejoin_tries = 288
  106. report_host = "172.16.16.10"
  107. #innodb settings
  108. innodb_buffer_pool_size = 64G
  109. innodb_buffer_pool_instances = 8
  110. innodb_data_file_path = ibdata1:12M:autoextend
  111. innodb_flush_log_at_trx_commit = 1
  112. innodb_log_buffer_size = 32M
  113. innodb_log_file_size = 2G
  114. innodb_log_files_in_group = 3
  115. innodb_redo_log_capacity = 6G
  116. innodb_max_undo_log_size = 4G
  117. # 根据您的服务器IOPS能力适当调整
  118. # 一般配普通SSD盘的话,可以调整到 10000 - 20000
  119. # 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
  120. innodb_io_capacity = 4000
  121. innodb_io_capacity_max = 8000
  122. innodb_open_files = 65535
  123. innodb_flush_method = O_DIRECT
  124. innodb_lru_scan_depth = 4000
  125. innodb_lock_wait_timeout = 10
  126. innodb_rollback_on_timeout = 1
  127. innodb_print_all_deadlocks = 1
  128. innodb_online_alter_log_max_size = 4G
  129. innodb_print_ddl_logs = 0
  130. innodb_status_file = 1
  131. #注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log_error文件增长较快
  132. innodb_status_output = 0
  133. innodb_status_output_locks = 1
  134. innodb_sort_buffer_size = 67108864
  135. innodb_adaptive_hash_index = 0
  136. #开启NUMA支持
  137. innodb_numa_interleave = ON
  138. innodb_print_lock_wait_timeout_info = 1
  139. #自动杀掉超过5分钟不活跃事务,避免行锁被长时间持有
  140. kill_idle_transaction = 300
  141. #innodb monitor settings
  142. #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"
  143. #innodb parallel query
  144. loose-force_parallel_execute = OFF
  145. loose-parallel_default_dop = 8
  146. loose-parallel_max_threads = 96
  147. temptable_max_ram = 8G
  148. #pfs settings
  149. performance_schema = 1
  150. #performance_schema_instrument = '%memory%=on'
  151. 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]
  5. # some limits
  6. # file size
  7. LimitFSIZE=infinity
  8. # cpu time
  9. LimitCPU=infinity
  10. # virtual memory size
  11. LimitAS=infinity
  12. # open files
  13. LimitNOFILE=65535
  14. # processes/threads
  15. LimitNPROC=65535
  16. # locked memory
  17. LimitMEMLOCK=infinity
  18. # total threads (user+kernel)
  19. TasksMax=infinity
  20. TasksAccounting=false
  21. ...

保存退出,然后再执行命令重载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
  14. Jul 08 14:10:06 db170 systemd[1]: Starting MySQL Server...
  15. Jul 08 14:10:14 db170 systemd[1]: Started MySQL Server.
  16. $ ps -ef | grep mysqld
  17. mysql 43653 1 3 10:35 ? 00:00:02 /usr/sbin/mysqld
  18. $ ss -lntp | grep mysqld
  19. LISTEN 0 70 *:33060 *:* users:(("mysqld",pid=43653,fd=23))
  20. LISTEN 0 128 *:3306 *:* users:(("mysqld",pid=43653,fd=26))
  21. # 查看数据库文件
  22. $ ls /data/GreatSQL
  23. auto.cnf client-key.pem '#ib_16384_14.dblwr' '#ib_16384_6.dblwr' ib_logfile1 mysql.pid server-key.pem
  24. binlog.000001 error.log '#ib_16384_15.dblwr' '#ib_16384_7.dblwr' ib_logfile2 mysql.sock slow.log
  25. binlog.000002 '#ib_16384_0.dblwr' '#ib_16384_1.dblwr' '#ib_16384_8.dblwr' ibtmp1 mysql.sock.lock sys
  26. binlog.index '#ib_16384_10.dblwr' '#ib_16384_2.dblwr' '#ib_16384_9.dblwr' innodb_status.52003 performance_schema undo_001
  27. ca-key.pem '#ib_16384_11.dblwr' '#ib_16384_3.dblwr' ib_buffer_pool '#innodb_temp' private_key.pem undo_002
  28. ca.pem '#ib_16384_12.dblwr' '#ib_16384_4.dblwr' ibdata1 mysql public_key.pem
  29. 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
  6. Copyright (c) 2021-2023 GreatDB Software Co., Ltd
  7. Copyright (c) 2009-2021 Percona LLC and/or its affiliates
  8. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
  9. ...
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. greatsql> \s #<--想执行一个命令,提示要先修改密码
  12. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
  13. greatsql> alter user user() identified by 'GreatSQL@202X'; #<--修改密码
  14. Query OK, 0 rows affected (0.02 sec)
  15. greatsql> \s #<--就可以正常执行其他命令了
  16. --------------
  17. mysql Ver 8.0.32-24 for Linux on x86_64 (GreatSQL, Release 24, Revision 3714067bc8c)
  18. Connection id: 8
  19. Current database:
  20. Current user: root@localhost
  21. SSL: Not in use
  22. Current pager: stdout
  23. Using outfile: ''
  24. Using delimiter: ;
  25. Server version: 8.0.32-24 GreatSQL, Release 24, Revision 3714067bc8c
  26. Protocol version: 10
  27. Connection: Localhost via UNIX socket
  28. Server characterset: utf8mb4
  29. Db characterset: utf8mb4
  30. Client characterset: utf8mb4
  31. Conn. characterset: utf8mb4
  32. UNIX socket: /data/GreatSQL/mysql.sock
  33. Binary data as: Hexadecimal
  34. Uptime: 20 min 8 sec
  35. Threads: 2 Questions: 7 Slow queries: 0 Opens: 130 Flush tables: 3 Open tables: 46 Queries per second avg: 0.005
  36. --------------
  37. greatsql> show databases; #<--查看数据库列表
  38. +--------------------+
  39. | Database |
  40. +--------------------+
  41. | information_schema |
  42. | mysql |
  43. | performance_schema |
  44. | sys |
  45. +--------------------+
  46. 4 rows in set (0.01 sec)
  47. greatsql>

7. 关闭/重启GreatSQL

执行下面的命令关闭GreatSQL数据库。

  1. $ systemctl stop mysqld

执行下面的命令重启GreatSQL数据库。

  1. $ systemctl restart mysqld

GreatSQL数据库安装并初始化完毕。

8. 安装MySQL Shell

为了支持仲裁节点特性,需要安装GreatSQL提供的MySQL Shell发行包。打开GreatSQL下载页面RPM安装并构建MGR集群 - 图3 (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
  2. ...
  3. PATH=$PATH:$HOME/bin:/usr/local/greatsql-shell-8.0.25-16-Linux-glibc2.28-x86_64/bin
  4. 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集群 | 深入浅出MGRRPM安装并构建MGR集群 - 图4 (opens new window)

利用MySQL Shell构建MGR集群比较简单,主要有几个步骤:

  1. 检查实例是否满足条件。
  2. 创建并初始化一个集群。
  3. 逐个添加实例。

接下来一步步执行。

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...
  4. This instance reports its own address as GreatSQL-01:3306
  5. 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.
  6. # 提示root账号不能运行MGR服务,需要创建新的专用账号
  7. 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.
  8. 1) Create remotely usable account for 'root' with same grants and password
  9. 2) Create a new admin account for InnoDB cluster with minimal required grants
  10. 3) Ignore and continue
  11. 4) Cancel
  12. Please select an option [1]: 2 #<-- 选择创建最小权限账号
  13. Please provide an account name (e.g: icroot@%) to have it created with the necessary
  14. privileges or leave empty and press Enter to cancel.
  15. Account Name: GreatSQL <-- 输入账号名
  16. Password for new account: ******* <-- 输入密码***
  17. Confirm password: ******* <-- 再次确认密码
  18. #节点初始化完毕
  19. The instance 'GreatSQL-01:3306' is valid to be used in an InnoDB cluster.
  20. #MGR管理账号创建完毕
  21. Cluster admin user 'GreatSQL'@'%' created.
  22. 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.
  8. # 选定GreatSQL-01节点作为PRIMARY,开始创建MGR集群
  9. # 集群命名为 GreatSQLMGR,后面mysqlrouter读取元数据时用得上
  10. MySQL 172.16.16.10:3306 ssl Py > c = dba.create_cluster('GreatSQLMGR');
  11. A new InnoDB cluster will be created on instance '172.16.16.10:3306'.
  12. Validating instance configuration at 172.16.16.10:3306...
  13. This instance reports its own address as GreatSQL-01:3306
  14. Instance configuration is suitable.
  15. NOTE: Group Replication will communicate with other members using 'GreatSQL-01:33061'. Use the localAddress option to override.
  16. Creating InnoDB cluster 'GreatSQLMGR' on 'GreatSQL-01:3306'...
  17. Adding Seed Instance...
  18. Cluster successfully created. Use Cluster.add_instance() to add MySQL instances.
  19. At least 3 instances are needed for the cluster to be able to withstand up to
  20. one server failure.
  21. 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'.
  6. 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'.
  7. # 选择恢复模式:克隆/增量恢复/忽略,默认选择克隆
  8. Please select a recovery method [C]lone/[I]ncremental recovery/[A]bort (default Clone):
  9. Validating instance configuration at 172.16.16.11:3306...
  10. This instance reports its own address as GreatSQL-02:3306
  11. Instance configuration is suitable.
  12. NOTE: Group Replication will communicate with other members using 'GreatSQL-02:33061'. Use the localAddress option to override.
  13. A new instance will be added to the InnoDB cluster. Depending on the amount of
  14. data on the cluster this might take from a few seconds to several hours.
  15. Adding instance to the cluster...
  16. Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.
  17. Clone based state recovery is now in progress.
  18. # 提示在这个过程中需要重启GreatSQL-02节点实例
  19. # 如果无法自动重启,需要手动重启
  20. NOTE: A server restart is expected to happen as part of the clone process. If the
  21. server does not support the RESTART command or does not come back after a
  22. while, you may need to manually start it back.
  23. * Waiting for clone to finish...
  24. # 从GreatSQL-01节点克隆数据
  25. NOTE: GreatSQL-02:3306 is being cloned from GreatSQL-01:3306
  26. ** Stage DROP DATA: Completed
  27. ** Clone Transfer
  28. FILE COPY ############################################################ 100% Completed
  29. PAGE COPY ############################################################ 100% Completed
  30. REDO COPY ############################################################ 100% Completed
  31. NOTE: GreatSQL-02:3306 is shutting down...
  32. * Waiting for server restart... \ <-- 重启中
  33. * Waiting for server restart... ready <-- 重启完毕,如果没有加入systemed,则需要自己手工启动
  34. * GreatSQL-02:3306 has restarted, waiting for clone to finish...
  35. ** Stage RESTART: Completed
  36. * Clone process has finished: 59.62 MB transferred in about 1 second (~59.62 MB/s)
  37. State recovery already finished for 'GreatSQL-02:3306'
  38. # 新节点 GreatSQL-02:3306 已加入集群
  39. 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实现读写分离及读可扩展,详见:读写分离

问题反馈

联系我们

扫码关注微信公众号

greatsql-wx