当前位置:   article > 正文

Mysql Innodb Cluster测试

Mysql Innodb Cluster测试

本文介绍mysql 8版本下的Innodb Cluster配置与测试过程,其核心还是mysql的组复制功能,通过使用mysql shell简化了组复制的配置过程,同时使用mysql route中间件实现了故障的自动转移以及读写分离等功能。之前测试mysql组复制的时候有提出过中间件的问题,mysql-route是个不错的解决方案,前文传送门:http://blog.51cto.com/ylw6006/1976829

一、环境介绍

操作系统:centos linux 7.2 64bit
mysql社区版: 8.0.11
mysql shell版本:8.0.11
mysql route版本:8.0.11

二、下载软件包

1、mysql
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz

2、mysql-router
https://cdn.mysql.com//Downloads/MySQL-Router/mysql-router-8.0.11-linux-glibc2.12-x86-64bit.tar.gz

3、mysql-shell
https://cdn.mysql.com//Downloads/MySQL-Shell/mysql-shell-8.0.11-linux-glibc2.12-x86-64bit.tar.gz

三、安装软件包

(其他两台主机同步配置)

  1. 1、配置hosts文件
  2. # cat /etc/hosts
  3. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  4. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  5. 192.168.115.5 vm1
  6. 192.168.115.6 vm2
  7. 192.168.115.7 vm3
  8. 2、安装mysql-shell
  9. # tar -zxvpf mysql-shell-8.0.11-linux-glibc2.12-x86-64bit.tar.gz -C /usr/local/
  10. # cd /usr/local/
  11. # ln -s mysql-shell-8.0.11-linux-glibc2.12-x86-64bit/ mysql-shell
  12. 3、安装mysql-route
  13. # tar -zxvpf mysql-router-8.0.11-linux-glibc2.12-x86-64bit.tar.gz -C /usr/local/
  14. # cd /usr/local/
  15. # ln -s mysql-router-8.0.11-linux-glibc2.12-x86-64bit/ mysql-router
  16. 4、安装和初始化mysql
  17. # tar -zxvpf mysql-8.0.11-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
  18. # cd /usr/local/
  19. # ln -s mysql-8.0.11-linux-glibc2.12-x86_64/ mysql
  20. # groupadd -g 27 mysql
  21. # useradd -g mysql -u 27 -d /dev/null -s /sbin/nologin mysql
  22. # mkdir -p /mydata
  23. # chown -R mysql.mysql /mydata/
  24. # cat /usr/local/mysql/my.cnf
  25. [client]
  26. password = 123456
  27. [mysqld]
  28. innodb_buffer_pool_size = 256M
  29. socket = /tmp/mysql.sock
  30. skip-external-locking
  31. key_buffer_size = 100M
  32. max_allowed_packet = 1M
  33. table_open_cache = 256
  34. sort_buffer_size = 1M
  35. read_buffer_size = 1M
  36. read_rnd_buffer_size = 4M
  37. myisam_sort_buffer_size = 16M
  38. thread_cache_size = 4
  39. max_connections=1500
  40. character_set_server=utf8
  41. group_concat_max_len=65535
  42. log_bin_trust_function_creators=1
  43. log_queries_not_using_indexes = ON
  44. log_throttle_queries_not_using_indexes = 2
  45. log-bin=mysql-bin
  46. binlog_format=row
  47. default_authentication_plugin = mysql_native_password
  48. long_query_time=2
  49. slow_query_log=1
  50. slow_query_log_file=/mydata/slow-query.log
  51. ft_min_word_len=1
  52. innodb_ft_min_token_size=1
  53. server-id=1155
  54. lower_case_table_names = 1
  55. skip-name-resolve
  56. innodb_file_per_table=1
  57. gtid_mode = ON
  58. enforce_gtid_consistency = ON
  59. slave_parallel_workers=4
  60. master_verify_checksum = 1
  61. slave_sql_verify_checksum = 1
  62. log-slave-updates=true
  63. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  64. slave-parallel-type=LOGICAL_CLOCK
  65. slave-preserve-commit-order=ON
  66. master_info_repository = TABLE
  67. relay_log_info_repository = TABLE
  68. # /usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/mydata --initialize-insecure
  69. # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
  70. # egrep 'basedir|datadir' /etc/init.d/mysqld |head -n 5
  71. # basedir=<path-to-mysql-installation-directory>
  72. # - Add the path to the mysql-installation-directory to the basedir variable
  73. # If you change base dir, you must also change datadir. These may get
  74. basedir=/usr/local/mysql
  75. datadir=/mydata
  76. # chmod +x /etc/init.d/mysqld
  77. # chkconfig --add mysqld
  78. # mv /etc/my.cnf /etc/my.cnf.bak
  79. # ln -s /usr/local/mysql/my.cnf /etc/
  80. # service mysqld start
  81. mysql> set sql_log_bin=0;
  82. mysql> update mysql.user set host='%' where user='root';
  83. mysql> alter user 'root'@'localhost' identified with mysql_native_password by '123456';
  84. mysql> create user test@'%' identified by '123456';
  85. mysql> grant all privileges on *.* to test@'%';
  86. mysql> flush privileges;
  87. mysql> set sql_log_bin=1;

四、检查配置

vm1执行即可

  1. 使用JS命令,检查每台服务器的配置。三台服务的mysql都要执行检查
  2. # /usr/local/mysql-shell/bin/mysqlsh
  3. MySQL JS > dba.checkInstanceConfiguration('test@vm1:3306')
  4. Please provide the password for 'test@vm1:3306': ******
  5. Validating local MySQL instance listening at port 3306 for use in an InnoDB cluster...
  6. This instance reports its own address as vm1
  7. 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. Checking whether existing tables comply with Group Replication requirements...
  9. No incompatible tables detected
  10. Checking instance configuration...
  11. Instance configuration is compatible with InnoDB cluster
  12. The instance 'vm1:3306' is valid for InnoDB cluster usage.
  13. {
  14. "status": "ok"
  15. }
  16. 执行 dba.checkInstanceConfiguration,当输出 "status": "ok"的时候,表示该服务器检查通过

五、创建组复制

vm1执行即可

  1. # /usr/local/mysql-shell/bin/mysqlsh --uri test@vm1:3306
  2. MySQL vm1:3306 ssl JS > var cluster = dba.createCluster('main')
  3. A new InnoDB cluster will be created on instance 'root@vm1:3306'.
  4. Validating instance at vm1:3306...
  5. This instance reports its own address as vm1
  6. Instance configuration is suitable.
  7. Creating InnoDB cluster 'main' on 'root@vm1:3306'...
  8. Adding Seed Instance...
  9. Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.
  10. At least 3 instances are needed for the cluster to be able to withstand up to
  11. one server failure.
  12. JS > cluster.addInstance('root@vm2:3306')
  13. JS > cluster.addInstance('root@vm3:3306')
  14. MySQL vm1:3306 ssl JS > cluster.status()
  15. {
  16. "clusterName": "main",
  17. "defaultReplicaSet": {
  18. "name": "default",
  19. "primary": "vm1:3306",
  20. "ssl": "REQUIRED",
  21. "status": "OK",
  22. "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
  23. "topology": {
  24. "vm1:3306": {
  25. "address": "vm1:3306",
  26. "mode": "R/W",
  27. "readReplicas": {},
  28. "role": "HA",
  29. "status": "ONLINE"
  30. },
  31. "vm2:3306": {
  32. "address": "vm2:3306",
  33. "mode": "R/O",
  34. "readReplicas": {},
  35. "role": "HA",
  36. "status": "ONLINE"
  37. },
  38. "vm3:3306": {
  39. "address": "vm3:3306",
  40. "mode": "R/O",
  41. "readReplicas": {},
  42. "role": "HA",
  43. "status": "ONLINE"
  44. }
  45. }
  46. },
  47. "groupInformationSourceMember": "mysql://root@vm1:3306"
  48. }

六、配置mysql-route

vm1执行即可

  1. # useradd mysql-router
  2. # /usr/local/mysql-router/bin/mysqlrouter --bootstrap root@vm3:3306 --user mysql-router --directory /data/mysqlrouter --user=root --conf-use-sockets --force
  3. Please enter MySQL password for root:
  4. Reconfiguring MySQL Router instance at '/data/mysqlrouter'...
  5. MySQL Router has now been configured for the InnoDB cluster 'main'.
  6. The following connection information can be used to connect to the cluster.
  7. Classic MySQL protocol connections to cluster 'main':
  8. - Read/Write Connections: localhost:6446
  9. - Read/Write Connections: /data/mysqlrouter/mysql.sock
  10. - Read/Only Connections: localhost:6447
  11. - Read/Only Connections: /data/mysqlrouter/mysqlro.sock
  12. X protocol connections to cluster 'main':
  13. - Read/Write Connections: localhost:64460
  14. - Read/Write Connections: /data/mysqlrouter/mysqlx.sock
  15. - Read/Only Connections: localhost:64470
  16. - Read/Only Connections: /data/mysqlrouter/mysqlxro.sock
  17. # /data/mysqlrouter/start.sh
  18. # netstat -anpt |grep router
  19. tcp 0 0 0.0.0.0:64460 0.0.0.0:* LISTEN 4865/mysqlrouter
  20. tcp 0 0 0.0.0.0:6446 0.0.0.0:* LISTEN 4865/mysqlrouter
  21. tcp 0 0 0.0.0.0:6447 0.0.0.0:* LISTEN 4865/mysqlrouter
  22. tcp 0 0 0.0.0.0:64470 0.0.0.0:* LISTEN 4865/mysqlrouter
  23. tcp 0 0 192.168.115.5:6446 192.168.115.1:63131 ESTABLISHED 4865/mysqlrouter
  24. tcp 0 0 192.168.115.5:36458 192.168.115.5:3306 ESTABLISHED 4865/mysqlrouter
  25. tcp 0 0 192.168.115.5:46488 192.168.115.7:3306 ESTABLISHED 4865/mysqlrouter

七、连接测试

  1. [root@vm1 ~]# /usr/local/mysql/bin/mysql -u root -h 192.168.115.5 -P 6446 -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 87
  5. Server version: 8.0.11 MySQL Community Server - GPL
  6. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> SELECT @@port;
  12. +--------+
  13. | @@port |
  14. +--------+
  15. | 3306 |
  16. +--------+
  17. 1 row in set (0.00 sec)
  18. mysql> select user,host from mysql.user;
  19. +----------------------------------+-----------+
  20. | user | host |
  21. +----------------------------------+-----------+
  22. | mysql_innodb_cluster_r0467305354 | % |
  23. | mysql_innodb_cluster_r0467308990 | % |
  24. | mysql_innodb_cluster_r0467310325 | % |
  25. | mysql_router1_2x0gxmyjbatp | % |
  26. | mysql_router1_x017h4ui76aq | % |
  27. | root | % |
  28. | test | % |
  29. | mysql.infoschema | localhost |
  30. | mysql.session | localhost |
  31. | mysql.sys | localhost |
  32. | mysql_innodb_cluster_r0467286081 | localhost |
  33. | mysql_innodb_cluster_r0467305354 | localhost |
  34. | mysql_innodb_cluster_r0467308990 | localhost |
  35. | mysql_innodb_cluster_r0467310325 | localhost |
  36. +----------------------------------+-----------+
  37. 14 rows in set (0.00 sec)
  38. [root@vm1 ~]# /usr/local/mysql/bin/mysql -u root -h 192.168.115.5 -P 6447 -p
  39. Enter password:
  40. Welcome to the MySQL monitor. Commands end with ; or \g.
  41. Your MySQL connection id is 233
  42. Server version: 8.0.11 MySQL Community Server - GPL
  43. Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
  44. Oracle is a registered trademark of Oracle Corporation and/or its
  45. affiliates. Other names may be trademarks of their respective
  46. owners.
  47. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  48. mysql> create database yang;
  49. ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement
  50. mysql> select * from performance_schema.replication_group_members;
  51. +---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
  52. | CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION |
  53. +---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
  54. | group_replication_applier | 7c8712b3-8b2c-11e8-b41f-000c2994965c | vm1 | 3306 | ONLINE | SECONDARY | 8.0.11 |
  55. | group_replication_applier | 862443de-8b2c-11e8-bf4c-000c29c9b5f9 | vm3 | 3306 | ONLINE | PRIMARY | 8.0.11 |
  56. | group_replication_applier | 8852b2af-8b2c-11e8-8487-000c2971a45f | vm2 | 3306 | ONLINE | SECONDARY | 8.0.11 |
  57. +---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+
  58. 3 rows in set (0.37 sec)
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/黑客灵魂/article/detail/1006144
推荐阅读
相关标签
  

闽ICP备14008679号