暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

InnoDBCluster安装

mysql code tracer 2021-04-25
617

InnoDB Cluster安装

3节点安装MySQL

创建所需目录与用户

  1. groupadd mysql

  2. useradd -g mysql mysql -s /sbin/nologin

  3. mkdir -p /service/logs/software/mysql_3306/

  4. mkdir -p /service/databases/mysql_3306/data/

  5. chown -R mysql. /service/logs/software/mysql_3306/

  6. chown -R mysql. /service/databases/mysql_3306/data/

  7. chown -R mysql. /service/software/mysql_3306/

配置文件

配置文件中需要注意的部分

  1. disabled_storage_engines = "MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"

  2. log_bin = /service/databases/mysql_3306/data/mysql-bin

  3. master_info_repository = table

  4. binlog_checksum = NONE

  5. relay_log_info_repository = table

  6. gtid_mode = ON

  7. enforce_gtid_consistency = ON

  8. binlog_checksum = NONE

  9. log_slave_updates = ON

  10. binlog_format = ROW

  11. transaction_write_set_extraction = XXHASH64

  12. binlog_transaction_dependency_tracking = WRITESET_SESSION

  13. slave_parallel_workers = 4

  14. slave_preserve_commit_order = 1

  15. slave_parallel_type = LOGICAL_CLOCK

完整版示例

  1. [client]

  2. port = 3306

  3. socket = /service/databases/mysql_3306/data/mysql_3306.sock


  4. [mysql]

  5. prompt="\\u@\\h \R:\m:\s [\\d]>"

  6. no-auto-rehash

  7. port = 3306

  8. socket = /service/databases/mysql_3306/data/mysql_3306.sock

  9. default_character_set = utf8mb4


  10. [mysqladmin]

  11. port = 3306

  12. socket = /service/databases/mysql_3306/data/mysql_3306.sock


  13. [mysqldump]

  14. port = 3306

  15. socket = /service/databases/mysql_3306/data/mysql_3306.sock


  16. [xtrabackup]

  17. port = 3306

  18. socket = /service/databases/mysql_3306/data/mysql_3306.sock


  19. [mysqlbackup]

  20. port = 3306

  21. socket = /service/databases/mysql_3306/data/mysql_3306.sock

  22. safe_slave_backup_timeout = 0


  23. [mysqld]

  24. # basic settings #

  25. user = mysql

  26. default_storage_engine = InnoDB

  27. server_id = 1901123306

  28. sql_mode = STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION

  29. socket = /service/databases/mysql_3306/data/mysql_3306.sock

  30. pid_file = /service/databases/mysql_3306/data/mysql_3306.pid

  31. basedir = /service/software/mysql_3306

  32. datadir = /service/databases/mysql_3306/data

  33. character_set_server = utf8mb4

  34. default_time_zone = +08:00

  35. back_log = 1024

  36. thread_stack = 512K

  37. external_locking = FALSE

  38. open_files_limit = 65535

  39. max_allowed_packet = 128M

  40. lower_case_table_names = 1

  41. explicit_defaults_for_timestamp = 1

  42. read_only = 0

  43. super_read_only = 0


  44. # connection #

  45. lock_wait_timeout = 3600

  46. skip_name_resolve = 1

  47. max_connect_errors = 1000000

  48. max_connections = 5000


  49. # table cache performance settings#

  50. table_open_cache = 4096

  51. table_open_cache_instances = 64

  52. table_definition_cache = 4096


  53. # CACHES AND LIMITS #

  54. tmp_table_size = 32M

  55. max_heap_table_size = 32M

  56. bulk_insert_buffer_size = 64M


  57. # session memory settings #

  58. sort_buffer_size = 4M

  59. join_buffer_size = 4M

  60. read_buffer_size = 8M

  61. read_rnd_buffer_size = 4M

  62. thread_cache_size = 3000


  63. # log settings #

  64. log_error_verbosity = 3

  65. min_examined_row_limit = 100

  66. log_slow_admin_statements = 1

  67. log_slow_slave_statements = 1

  68. log_error = /service/logs/software/mysql_3306/mysql-error.log

  69. log_timestamps = SYSTEM

  70. log_queries_not_using_indexes = 1

  71. slow_query_log = 1

  72. slow_query_log_file = /service/logs/software/mysql_3306/mysql-slow.log

  73. long_query_time = 0.5


  74. # innodb settings #

  75. innodb_buffer_pool_load_at_startup = 1

  76. innodb_buffer_pool_dump_at_shutdown = 1

  77. innodb_data_file_path = ibdata1:1G:autoextend

  78. innodb_log_buffer_size = 32M

  79. innodb_thread_concurrency = 0

  80. innodb_sync_spin_loops = 100

  81. innodb_spin_wait_delay = 30

  82. ##机械盘设置为500,SSD盘设置为10000-20000##

  83. innodb_io_capacity = 500

  84. ##机械盘设置为2000,SSD盘设置为10000-20000##

  85. innodb_io_capacity_max = 1000

  86. ##机械盘设置为1,SSD盘设置为0##

  87. innodb_flush_neighbors = 1

  88. innodb_write_io_threads = 16

  89. innodb_read_io_threads = 16

  90. innodb_purge_threads = 4

  91. innodb_page_cleaners = 16

  92. innodb_open_files = 65535

  93. innodb_max_dirty_pages_pct = 50

  94. innodb_lru_scan_depth = 4096

  95. innodb_lock_wait_timeout = 10

  96. innodb_checksum_algorithm = crc32

  97. innodb_rollback_on_timeout = 1

  98. innodb_print_all_deadlocks = 1

  99. innodb_online_alter_log_max_size = 4G

  100. innodb_stats_on_metadata = 0

  101. innodb_flush_method = O_DIRECT

  102. innodb_log_files_in_group = 3

  103. innodb_log_file_size = 1G

  104. innodb_flush_log_at_trx_commit = 1

  105. innodb_file_per_table = 1

  106. innodb_buffer_pool_size = 4G

  107. innodb_buffer_pool_instances = 4


  108. # undo settings #

  109. innodb_undo_directory = /service/databases/mysql_3306/data

  110. innodb_undo_tablespaces = 95

  111. innodb_undo_log_truncate = 1

  112. innodb_purge_rseg_truncate_frequency = 128

  113. innodb_max_undo_log_size = 4G


  114. innodb_status_file = 1

  115. innodb_status_output = 0

  116. innodb_status_output_locks = 0


  117. # performance_schema #

  118. performance_schema = 1

  119. performance_schema_instrument = '%=on'


  120. # innodb monitor #

  121. 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


  122. # safe #

  123. secure_file_priv = /service/databases/mysql_3306

  124. default_password_lifetime = 0


  125. # replication settings #

  126. skip_slave_start = 1

  127. relay_log = /service/databases/mysql_3306/data/relay-bin

  128. slave_pending_jobs_size_max = 128M

  129. log_slave_updates = 1

  130. log_bin = /service/databases/mysql_3306/data/mysql-bin

  131. expire_logs_days = 7

  132. sync_binlog = 1

  133. gtid_mode = ON

  134. enforce_gtid_consistency = 1

  135. binlog_cache_size = 4M

  136. max_binlog_size = 512M

  137. max_binlog_cache_size = 2G

  138. slave_preserve_commit_order= 1

  139. binlog_format = row

  140. relay_log_purge = 1

  141. slave_parallel_type = LOGICAL_CLOCK

  142. slave_parallel_workers = 16

  143. master_info_repository = TABLE

  144. relay_log_info_repository = TABLE

  145. relay_log_recovery = ON

  146. binlog_gtid_simple_recovery = 1


  147. # group replication & innodb cluster #

  148. disabled_storage_engines = "MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"

  149. master_info_repository = table

  150. binlog_checksum = NONE

  151. relay_log_info_repository = table

  152. gtid_mode = ON

  153. enforce_gtid_consistency = ON

  154. binlog_checksum = NONE

  155. log_slave_updates = ON

  156. binlog_format = ROW

  157. transaction_write_set_extraction = XXHASH64

  158. slave_parallel_workers = 4

  159. slave_preserve_commit_order = 1

  160. slave_parallel_type = LOGICAL_CLOCK

  161. binlog_transaction_dependency_tracking = WRITESET_SESSION


  162. # clone #

系统 HOSTS 配置

修改/etc/hosts

  1. vi /etc/hosts


  2. 10.101.190.112 kh-oms4-sit-innodbcluster-db01

  3. 10.101.190.13 kh-oms4-sit-innodbcluster-db02

  4. 10.101.190.179 kh-oms4-sit-innodbcluster-db03

三节点验证report-host是否设置正确

  1. root@localhost 08:25: [(none)]>SELECT coalesce(@@report_host, @@hostname) as r;

  2. +--------------------------------+

  3. | r |

  4. +--------------------------------+

  5. | kh-oms4-sit-innodbcluster-db01 |

  6. +--------------------------------+

  7. 1 row in set (0.00 sec)

三节点创建用户

  1. create user root identified by 'C******';

  2. grant all on *.* to root with grant option;

  3. create user u_autodba@'%' identified WITH mysql_native_password by 'lx*********';

  4. grant all on *.* to u_autodba@'%' with grant option;

安装mysqlshell

  1. wget https://dev.mysql.com/get/Downloads/MySQL-Shell/mysql-shell-8.0.19-linux-glibc2.12-x86-64bit.tar.gz

  2. tar xvf mysql-shell-8.0.19-linux-glibc2.12-x86-64bit.tar.gz

  3. mv mysql-shell-8.0.19-linux-glibc2.12-x86-64bit mysqlshell

  4. chown -R mysql. mysqlshell/

  5. vim /root/.bash_profile


  6. PATH=$PATH:$HOME/bin:/service/software/mysql_3306/bin:/service/software/mysqlshell/bin

mysqlshell连接一节点检查配置

连接节点

  1. [root@kh-oms4-sit-innodbcluster-db01 software]# mysqlsh root@kh-oms4-sit-innodbcluster-db01:3306

  2. ## 输入密码,提示还会问是否保存密码- -

配置检测

  • 检查node1

  1. MySQL kh-oms4-sit-innodbcluster-db01:3306 ssl JS > dba.checkInstanceConfiguration("root@kh-oms4-sit-innodbcluster-db01:3306");

  2. ##查看输出是否返回OK,如果不是修改并重启MySQL

  3. Validating local MySQL instance listening at port 3306 for use in an InnoDB cluster...


  4. This instance reports its own address as kh-oms4-sit-innodbcluster-db01: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. Checking whether existing tables comply with Group Replication requirements...

  7. No incompatible tables detected


  8. Checking instance configuration...

  9. Instance configuration is compatible with InnoDB cluster


  10. The instance 'kh-oms4-sit-innodbcluster-db01:3306' is valid to be used in an InnoDB cluster.


  11. {

  12. "status": "ok"

  13. }

  • 检查node2

  1. MySQL kh-oms4-sit-innodbcluster-db01:3306 ssl JS > dba.checkInstanceConfiguration("root@kh-oms4-sit-innodbcluster-db02:3306");

  2. Please provide the password for 'root@kh-oms4-sit-innodbcluster-db02:3306': **********

  3. Save password for 'root@kh-oms4-sit-innodbcluster-db02:3306'? [Y]es/[N]o/Ne[v]er (default No): y

  4. Validating MySQL instance at kh-oms4-sit-innodbcluster-db02:3306 for use in an InnoDB cluster...


  5. This instance reports its own address as kh-oms4-sit-innodbcluster-db02: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.


  7. Checking whether existing tables comply with Group Replication requirements...

  8. No incompatible tables detected


  9. Checking instance configuration...

  10. Instance configuration is compatible with InnoDB cluster


  11. The instance 'kh-oms4-sit-innodbcluster-db02:3306' is valid to be used in an InnoDB cluster.


  12. {

  13. "status": "ok"

  14. }

  • 检查node3

  1. MySQL kh-oms4-sit-innodbcluster-db01:3306 ssl JS > dba.checkInstanceConfiguration("root@kh-oms4-sit-innodbcluster-db03:3306");

  2. Please provide the password for 'root@kh-oms4-sit-innodbcluster-db03:3306': **********

  3. Save password for 'root@kh-oms4-sit-innodbcluster-db03:3306'? [Y]es/[N]o/Ne[v]er (default No): y

  4. Validating MySQL instance at kh-oms4-sit-innodbcluster-db03:3306 for use in an InnoDB cluster...


  5. This instance reports its own address as kh-oms4-sit-innodbcluster-db03: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.


  7. Checking whether existing tables comply with Group Replication requirements...

  8. No incompatible tables detected


  9. Checking instance configuration...

  10. Instance configuration is compatible with InnoDB cluster


  11. The instance 'kh-oms4-sit-innodbcluster-db03:3306' is valid to be used in an InnoDB cluster.


  12. {

  13. "status": "ok"

  14. }

节点1创建集群

  1. MySQL kh-oms4-sit-innodbcluster-db01:3306 ssl JS > var cluster = dba.createCluster('oms4');

  • 得到如下输出

  1. A new InnoDB cluster will be created on instance 'kh-oms4-sit-innodbcluster-db01:3306'.


  2. Validating instance configuration at kh-oms4-sit-innodbcluster-db01:3306...


  3. This instance reports its own address as kh-oms4-sit-innodbcluster-db01:3306


  4. Instance configuration is suitable.

  5. NOTE: Group Replication will communicate with other members using 'kh-oms4-sit-innodbcluster-db01:33061'. Use the localAddress option to override.


  6. Creating InnoDB cluster 'oms4' on 'kh-oms4-sit-innodbcluster-db01:3306'...


  7. Adding Seed Instance...

  8. Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.

  9. At least 3 instances are needed for the cluster to be able to withstand up to

  10. one server failure.

将2、3节点加入集群

node2加入集群

  • 步骤中会问你是否克隆node1节点。

  1. cluster.addInstance('root@kh-oms4-sit-innodbcluster-db02:3306');

  • 得到如下输出

  1. WARNING: A GTID set check of the MySQL instance at 'kh-oms4-sit-innodbcluster-db02:3306' determined that it contains transactions that do not originate from the cluster, which must be discarded before it can join the cluster.


  2. kh-oms4-sit-innodbcluster-db02:3306 has the following errant GTIDs that do not exist in the cluster:

  3. 8cd6aafa-7ac1-11ea-a904-0050568c2d7d:1-4


  4. WARNING: Discarding these extra GTID events can either be done manually or by completely overwriting the state of kh-oms4-sit-innodbcluster-db02:3306 with a physical snapshot from an existing cluster member. To use this method by default, set the 'recoveryMethod' option to 'clone'.


  5. Having extra GTID events is not expected, and it is recommended to investigate this further and ensure that the data can be removed prior to choosing the clone recovery method.


  6. Please select a recovery method [C]lone/[A]bort (default Abort): C

  7. NOTE: Group Replication will communicate with other members using 'kh-oms4-sit-innodbcluster-db02:33061'. Use the localAddress option to override.


  8. Validating instance configuration at kh-oms4-sit-innodbcluster-db02:3306...


  9. This instance reports its own address as kh-oms4-sit-innodbcluster-db02:3306


  10. Instance configuration is suitable.

  11. A new instance will be added to the InnoDB cluster. Depending on the amount of

  12. data on the cluster this might take from a few seconds to several hours.


  13. Adding instance to the cluster...


  14. Monitoring recovery process of the new cluster member. Press ^C to stop monitoring and let it continue in background.

  15. Clone based state recovery is now in progress.


  16. NOTE: A server restart is expected to happen as part of the clone process. If the

  17. server does not support the RESTART command or does not come back after a

  18. while, you may need to manually start it back.


  19. * Waiting for clone to finish...

  20. NOTE: kh-oms4-sit-innodbcluster-db02:3306 is being cloned from kh-oms4-sit-innodbcluster-db01:3306

  21. ** Stage DROP DATA: Completed

  22. ** Clone Transfer

  23. FILE COPY ############################################################ 100% Completed

  24. PAGE COPY ############################################################ 100% Completed

  25. REDO COPY ############################################################ 100% Completed


  26. NOTE: kh-oms4-sit-innodbcluster-db02:3306 is shutting down...


  27. * Waiting for server restart... ready

  28. * kh-oms4-sit-innodbcluster-db02:3306 has restarted, waiting for clone to finish...

  29. ** Stage RESTART: Completed

  30. * Clone process has finished: 1.12 GB transferred in 1 min 15 sec (14.94 MB/s)


  31. State recovery already finished for 'kh-oms4-sit-innodbcluster-db02:3306'


  32. The instance 'kh-oms4-sit-innodbcluster-db02:3306' was successfully added to the cluster.

node3添加进集群

  1. cluster.addInstance('root@kh-oms4-sit-innodbcluster-db03:3306');

  • 输出与node2类似 略过

查看集群状态

  1. MySQL kh-oms4-sit-innodbcluster-db01:3306 ssl JS > cluster.status()

  2. {

  3. "clusterName": "oms4",

  4. "defaultReplicaSet": {

  5. "name": "default",

  6. "primary": "kh-oms4-sit-innodbcluster-db01:3306",

  7. "ssl": "REQUIRED",

  8. "status": "OK",

  9. "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",

  10. "topology": {

  11. "kh-oms4-sit-innodbcluster-db01:3306": {

  12. "address": "kh-oms4-sit-innodbcluster-db01:3306",

  13. "mode": "R/W",

  14. "readReplicas": {},

  15. "replicationLag": null,

  16. "role": "HA",

  17. "status": "ONLINE",

  18. "version": "8.0.19"

  19. },

  20. "kh-oms4-sit-innodbcluster-db02:3306": {

  21. "address": "kh-oms4-sit-innodbcluster-db02:3306",

  22. "mode": "R/O",

  23. "readReplicas": {},

  24. "replicationLag": null,

  25. "role": "HA",

  26. "status": "ONLINE",

  27. "version": "8.0.19"

  28. },

  29. "kh-oms4-sit-innodbcluster-db03:3306": {

  30. "address": "kh-oms4-sit-innodbcluster-db03:3306",

  31. "mode": "R/O",

  32. "readReplicas": {},

  33. "replicationLag": null,

  34. "role": "HA",

  35. "status": "ONLINE",

  36. "version": "8.0.19"

  37. }

  38. },

  39. "topologyMode": "Single-Primary"

  40. },

  41. "groupInformationSourceMember": "kh-oms4-sit-innodbcluster-db01:3306"

  42. }

安装mysqlrouter

  1. wget https://dev.mysql.com/get/Downloads/MySQL-Router/mysql-router-8.0.19-linux-glibc2.12-x86_64.tar.xz

  2. tar xvf mysql-router-8.0.19-linux-glibc2.12-x86_64.tar.xz

  3. mv mysql-router-8.0.19-linux-glibc2.12-x86_64 mysqlrouter

  4. chown -R mysql. mysqlrouter/

  5. vim /root/.bash_profile


  6. PATH=$PATH:$HOME/bin:/service/software/mysql_3306/bin:/service/software/mysqlshell/bin:/service/software/mysqlrouter/bin

配置mysqlrouter

  1. ## 指定目录/tmp/myrouter 自动生成配置文件与启停脚本

  2. mysqlrouter --bootstrap root@kh-oms4-sit-innodbcluster-db01:3306 --directory /tmp/myrouter --conf-use-sockets --user=mysql

查看生成配置文件内容

  1. # File automatically generated during MySQL Router bootstrap

  2. [DEFAULT]

  3. user=mysql

  4. logging_folder=/tmp/myrouter/log

  5. runtime_folder=/tmp/myrouter/run

  6. data_folder=/tmp/myrouter/data

  7. keyring_path=/tmp/myrouter/data/keyring

  8. master_key_path=/tmp/myrouter/mysqlrouter.key

  9. connect_timeout=15

  10. read_timeout=30

  11. dynamic_state=/tmp/myrouter/data/state.json


  12. [logger]

  13. level = INFO


  14. [metadata_cache:oms4]

  15. cluster_type=gr

  16. router_id=1

  17. user=mysql_router1_lf3xhs2sx1p7

  18. metadata_cluster=oms4

  19. ttl=0.5

  20. use_gr_notifications=0


  21. [routing:oms4_rw]

  22. bind_address=0.0.0.0

  23. bind_port=6446

  24. socket=/tmp/myrouter/mysql.sock

  25. destinations=metadata-cache://oms4/?role=PRIMARY

  26. routing_strategy=first-available

  27. protocol=classic


  28. [routing:oms4_ro]

  29. bind_address=0.0.0.0

  30. bind_port=6447

  31. socket=/tmp/myrouter/mysqlro.sock

  32. destinations=metadata-cache://oms4/?role=SECONDARY

  33. routing_strategy=round-robin-with-fallback

  34. protocol=classic


  35. [routing:oms4_x_rw]

  36. bind_address=0.0.0.0

  37. bind_port=64460

  38. socket=/tmp/myrouter/mysqlx.sock

  39. destinations=metadata-cache://oms4/?role=PRIMARY

  40. routing_strategy=first-available

  41. protocol=x


  42. [routing:oms4_x_ro]

  43. bind_address=0.0.0.0

  44. bind_port=64470

  45. socket=/tmp/myrouter/mysqlxro.sock

  46. destinations=metadata-cache://oms4/?role=SECONDARY

  47. routing_strategy=round-robin-with-fallback

  48. protocol=x

  • 根据配置文件写端口为6446,读端口为6447。X写端口为64460,X读端口为64470

启动mysqlrouter

  1. [root@kh-oms4-sit-innodbcluster-db01 myrouter]# /tmp/myrouter/start.sh

consul检查脚本

写端口6446

  • 写json配置文件

  1. [root@kh-oms4-sit-innodbcluster-db01 consul.d]# cat w-kh-oms4-sit-innodbcluster.json

  2. {

  3. "services": [

  4. {

  5. "name": "w-kh-oms4-sit-innodbcluster",

  6. "tags": [

  7. "master,sit,mysql"

  8. ],

  9. "address": "10.101.190.112",

  10. "port": 6446,

  11. "checks": [

  12. {

  13. "args":["sh","-c","/service/databases/consul/data/shell/check_mysql_master_3306.sh 6446 "],

  14. "interval": "5s"

  15. }

  16. ]

  17. }

  18. ]

  19. }

  • check脚本仍然抄用大师兄的shell脚本

  1. [root@kh-oms4-sit-innodbcluster-db01 consul.d]# cat /service/databases/consul/data/shell/check_mysql_master_3306.sh

  2. #!/bin/bash

  3. port=$1

  4. user="******"

  5. passwod="******"


  6. comm="/service/software/mysql_3306/bin/mysql -u$user -h 127.0.0.1 -P $port -p$passwod"

  7. slave_info=`$comm -e "show slave status" |wc -l`

  8. value=`$comm -Nse "select 1"`

  9. get_read_only=`$comm -e "show variables like 'read_only'\G"| grep -w "Value" |awk '{print $NF}'`


  10. if [ $slave_info -ne 0 ]

  11. then

  12. echo "MySQL $port Instance is Slave........"

  13. $comm -e "show slave status\G" | egrep -w "Master_Host|Master_User|Master_Port|Master_Log_File|Read_Master_Log_Pos|Relay_Log_File|Relay_Log_Pos|Relay_Master_Log_File|Slave_IO_Running|Slave_SQL_Running|Exec_Master_Log_Pos|Relay_Log_Space|Seconds_Behind_Master"

  14. exit 2

  15. fi


  16. if [ -z $value ]

  17. then

  18. exit 2

  19. fi


  20. if [ $get_read_only = "ON" ]

  21. then

  22. echo "MySQL $port Instance is read only........"

  23. exit 2

  24. fi


  25. if [ -n$value -a $get_read_only = "OFF" ]

  26. then

  27. echo "MySQL $port Instance is Master........"

  28. exit 0

  29. fi


  30. exit 2

读端口6447

  • 读配置文件

  1. [root@kh-oms4-sit-innodbcluster-db01 consul.d]# cat r-kh-oms4-sit-innodbcluster.json

  2. {

  3. "services": [

  4. {

  5. "name": "r-kh-oms4-sit-innodbcluster",

  6. "tags": [

  7. "sit,slave,mysql"

  8. ],

  9. "address": "10.101.190.112",

  10. "port": 6447,

  11. "checks": [

  12. {

  13. "args":["sh","-c","/service/databases/consul/data/shell/check_mysql_slave_3306.sh 6447 "],

  14. "interval": "5s"

  15. }

  16. ]

  17. }

  18. ]

  19. }

  • check脚本,因为mysqlrouter无法展示 show slave status
    输出,可以在组复制一致性设置为After, group_replication_consistency='AFTER'
    ,保证数据落地,用 read_only=on
    作为从节点判断

  1. #!/bin/bash

  2. port=$1

  3. user="***"***

  4. passwod="******"


  5. max_delay=60

  6. comm="/service/software/mysql_3306/bin/mysql -u$user -h 127.0.0.1 -P $port -p$passwod"

  7. value=`$comm -Nse "select 1"`

  8. get_read_only=`$comm -e "show variables like 'read_only'\G"| grep -w "Value" |awk '{print $NF}'`



  9. if [ -z $value ]

  10. then

  11. exit 2

  12. fi


  13. if [ $get_read_only = "OFF" ]

  14. then

  15. echo "MySQL $port Instance is read write........"

  16. exit 2

  17. fi



  18. if [ $get_read_only = "ON" ]

  19. then

  20. echo "MySQL $port Instance is Slave........"

  21. exit 0

  22. fi


  23. exit 2

总结

  • 看到这里的都是真爱拉!总体难点在于配置文件 my.cnf
     ,5.7的配置文件与8.0的配置文件相差很多,剩下的就是几条命令的事情了,总体比MGR初始化简单很多。

  • 看了官档,限制还是蛮多的,比如隔离级别,间隙锁之类。还需要继续深入理解。

  • 感谢爱可生开源社区之前的innodbcluster扫盲公众推文与大师兄的consul blog

  • 后面就是破坏性测试和压测了,一起来玩鸭!


文章转载自mysql code tracer,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论