加入收藏 | 设为首页 | 会员中心 | 我要投稿 莱芜站长网 (https://www.0634zz.com/)- 云连接、建站、智能边缘云、设备管理、大数据!
当前位置: 首页 > 数据库 > MySql > 正文

MySQL InnoDB Cluster环境搭建及测验

发布时间:2023-02-20 13:19:20 所属栏目:MySql 来源:互联网
导读:记得MySQL Group Replicatioin 刚开始的时候,MySQL界很是轰动,等待了多年,终于有了官方的这个高可用解决方案。你要说还有一些方案补充,比如MySQL Cluster,MySQL Proxy,这些的使用率个人感觉还是不高,也就是经受的考验还不够,原因有很多,就不赘述了。
   记得MySQL Group Replicatioin 刚开始的时候,MySQL界很是轰动,等待了多年,终于有了官方的这个高可用解决方案。你要说还有一些方案补充,比如MySQL Cluster,MySQL Proxy,这些的使用率个人感觉还是不高,也就是经受的考验还不够,原因有很多,就不赘述了。
   
  搭建InnoDB Cluster显而易见需要多台服务器,而如果在一台服务器上练习测试,也是全然没有问题,如果想更快更方便的测试模拟,还可以使用sandbox来做,首先你得有sandbox,接着InnoDB Cluster的三大组件是MGR,MySQL Shell,MySQL Router,所以你可以从官网直接下载下来。
   
  使用MySQL Shell的命令mysqlsh开始部署,创建一个端口为3310的实例
   
  mysql-js> dba.deploySandboxInstance(3310)
  A new MySQL sandbox instance will be created on this host in
  /root/mysql-sandboxes/3310
   
  输入密码之后,一个3310端口的MySQL服务就启动了。
  Please enter a MySQL root password for the new instance:
  Deploying new MySQL instance...
  Instance localhost:3310 successfully deployed and started.
  Use shell.connect('root@localhost:3310'); to connect to the instance.
  接着创建另外两个节点 3320,3330
  dba.deploySandboxInstance(3320)
  dba.deploySandboxInstance(3330)
  我们切换到3310的MySQL实例,准备开始创建Cluster
  mysql-js>  /connect root@localhost:3310
  Creating a Session to 'root@localhost:3310'
  Enter password:
  Closing old connection...
  Classic Session successfully established. No default schema selected.
   
  这个时候,我们再配置一下MySQL Router,创建个软链接,保证能够正常调用。
   
  # ln -s /home/innodb_cluster/mysql-router-2.1.3-linux-glibc2.12-x86-64bit/bin/mysqlrouter   /usr/bin/mysqlroute
  # which mysqlroute
  /usr/bin/mysqlroute
  配置MySQL Router的启动节点为端口3310的实例
  # mysqlrouter --bootstrap root@localhost:3310 --user=mysql
   
  这个时候还是要输入密码,成功之后,这个绑定就打通了。
   
  Please enter MySQL password for root:
  Bootstrapping system MySQL Router instance...
  MySQL Router  has now been configured for the InnoDB cluster 'testCluster'.
  The following connection information can be used to connect to the cluster.
  Classic MySQL protocol connections to cluster 'testCluster':
  - Read/Write Connections: localhost:6446
  - Read/Only Connections: localhost:6447
  X protocol connections to cluster 'testCluster':
  - Read/Write Connections: localhost:64460
  - Read/Only Connections: localhost:64470
  可以从上面的日志看出来,分配的读写端口是6446,只读端口是6447,还有x协议连接的端口为64460,64470
  启动MySQL Router
  # mysqlrouter &
  [1] 2913
   
  如果对MySQL Router还有些疑问,可以看看安装目录下,会生成下面的配置文件,我们就看里面的.conf文件,里面的一部分内容如下:
  [routing:testCluster_default_rw]
  bind_address=0.0.0.0
  bind_port=6446
  destinations=metadata-cache://testCluster/default?role=PRIMARY
  mode=read-write
  protocol=classic
   
  也可以使用describe得到一些基本的信息
  mysql-js> cluster.describe();
  {
      "clusterName": "testCluster",
      "defaultReplicaSet": {
          "instances": [
              {
                  "host": "localhost:3310",
                  "label": "localhost:3310",
                  "role": "HA"
              },
              {
                  "host": "localhost:3320",
                  "label": "localhost:3320",
                  "role": "HA"
              },
              {
                  "host": "localhost:3330",
                  "label": "localhost:3330",
                  "role": "HA"
              }
          ],
          "name": "default"
      }
  }
    
  把节点2纳入到Cluster中
   
  mysql-js> cluster.rejoinInstance('root@localhost:3310')
  Rejoining the instance to the InnoDB cluster. Depending on the original
  problem that made the instance unavailable, the rejoin operation might not be
  successful and further manual steps will be needed to fix the underlying
  problem.
  Please monitor the output of the rejoin operation and take necessary action if
  the instance cannot rejoin.
  Please provide the password for 'root@localhost:3310':
  Rejoining instance to the cluster ...
  The instance 'root@localhost:3310' was successfully rejoined on the cluster.
  The instance 'localhost:3310' was successfully added to the MySQL Cluster.
  mysql-js>
   
  可以想象如果是一个生产系统,这么多的日志,这个过程真是让人纠结。
  最后来一个切换后的Cluster状态
  mysql-js> cluster.status()
  {
      "clusterName": "testCluster",
      "defaultReplicaSet": {
          "name": "default",
          "primary": "localhost:3320",
          "status": "OK",
          "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
          "topology": {
              "localhost:3310": {
                  "address": "localhost:3310",
                  "mode": "R/O",
                  "readReplicas": {},
                  "role": "HA",

(编辑:莱芜站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读