author:彭程


介绍

利用dble和zookeeper搭配,搭建集群,能够为 MySQL 集群提供稳定的分布式协调环境,进一步实现服务高可用。

安装说明

本机linux版本:CentOS 7.9
Mysql版本:5.7.16
dble版本:3.21.02.1
zookeeper版本:3.4.12
Mysql需要被授予授权远程登陆权限

zookeeper安装配置

  • 下载并解压安装包

下载地址:http://archive.apache.org/dist/zookeeper/

  1. tar -xvf zookeeper-3.4.12.tar.gz
  • 改配置文件 zoo.cfg

将 zoo_sample.cfg 文件复制并重命名为 zoo.cfg 文件

  1. cd conf
  2. cp zoo_sample.cfg zoo.cfg
  • 用vim命令修改配置文件,实例如下

    1. # The number of milliseconds of each tick
    2. tickTime=2000
    3. # The number of ticks that the initial
    4. # synchronization phase can take
    5. initLimit=10
    6. # The number of ticks that can pass between
    7. # sending a request and getting an acknowledgement
    8. syncLimit=5
    9. dataDir=/tmp/zookeeper
    10. # the port at which the clients will connect
    11. clientPort=2181

    其中:

    1. tickTime:基本事件单元,这个时间是作为Zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔,每隔tickTime时间就会发送一个心跳;最小的session过期时间为2倍tickTime;
    2. initLimit:允许follower连接并同步到Leader的初始化连接时间,以tickTime为单位。当初始化连接时间超过该值,则表示连接失败;
    3. syncLimit:表示Leader与Follower之间发送消息时,请求和应答时间长度。如果follower在设置时间内不能与leader通信,那么此follower将会被丢弃;
    4. dataDir:存储内存中数据库快照的位置,除非另有说明,否则指向数据库更新的事务日志;
    5. client:监听客户端连接的端口。
  • 启动zookeeper服务

cd zookeeper-3.4.12/bin && ./zkServer.sh start启动zookkeeper

  1. [root@localhost bin]# ./zkServer.sh start
  2. ZooKeeper JMX enabled by default
  3. Using config: /usr/local/zookeeper-3.4.12/bin/../conf/zoo.cfg
  4. Starting zookeeper ... STARTED

部署 DBLE 集群

  • 开启多个dble客户端

    1. 复制一个dble

      1. cp -r dble dble2
    2. 修改配置文件bootstrap.cnf,修改端口号避免与其他dble冲突,示例如下: ```

      encoding=UTF-8

      -agentlib:jdwp=transport=dtsocket,server=y,address=8188,suspend=n -server -XX:+AggressiveOpts -Dfile.encoding=UTF-8 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1985 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.host=127.0.0.1 -Xmx4G -Xms1G -XX:MaxDirectMemorySize=2G -XX:+PrintHeapAtGC -XX:+PrintGCDateStamps -Xloggc:./logs/gc%WRAPPERTIME_YYYYMMDDHHIISS%%p.log -XX:+PrintGCTimeStamps -XX:+PrintGCDetails

      base config

      -DhomePath=. -DinstanceName=2 -DinstanceId=2 -DserverId=xxx2

      -DbindIp=0.0.0.0

      -DserverPort=8166 -DmanagerPort=9166

      -DmaxCon=1024

      -Dprocessors=4

      -DbackendProcessors=12

      -DprocessorExecutor=4

      -DbackendProcessorExecutor=12

      -DcomplexExecutor=8

      -DwriteToBackendExecutor=4

bootstrap.cnf后面的内容不需要修改

  1. 注意DinstanceName也要修改,否则dble启动会报如下错误:

INFO | jvm 1 | 2021/08/04 20:12:16 | Server execute ShutdownHook. INFO | jvm 1 | 2021/08/04 20:12:16 | You use OuterHa or Cluster, no need to clean up ha process INFO | jvm 1 | 2021/08/04 20:12:16 | 2021-08-04 20:12:16,754 Thread-1 WARN Unable to register Log4j shutdown hook because JVM is shutting down. Using SimpleLogger STATUS | wrapper | 2021/08/04 20:12:19 | <— Wrapper Stopped

  1. - 配置zookeeper端口
  2. 修改cluster.cnf,实例如下

clusterEnable=true

cluster ucore/zk

clusterMode=zk

zk: clusterIP=10.186.19.aa:2281,10.186.60.bb:2281

clusterIP=192.168.128.139:2181

zk not need cluster.port

clusterPort=5700 rootPath=/dble

cluster namespace, please use the same one in one cluster

clusterId=cluster-1

if HA need sync by cluster, only useful when useOuterHa=true

needSyncHa=false

unit is millisecond

showBinlogStatusTimeout=60000 sequenceHandlerType=2

valid for sequenceHandlerType=2 or 3

sequenceStartTime=2010-11-04 09:42:54

valid for sequenceHandlerType=3 and clusterMode is zk, default true

sequenceInstanceByZk=true

  1. 其中clusterIP=zkIP:zk的端口号,且注意clusterEnable一项要为true,否则会无法找到node

[zk: localhost:2181(CONNECTED) 1] ls /dble/cluster-1/online Node does not exist: /dble/cluster-1/online

  1. - 对其余dble也做如上配置
  2. - 启动所有dble

[root@localhost dble]# bin/dble start

  1. - zk客户端,查看所有dble状态

[root@localhost bin]# ./zkCli.sh [zk: localhost:2181(CONNECTED) 0] ls /dble/cluster-1/online [1,2] ```

  • 集群配置完成