linux mycat 集群,Mycat学习实战-Mycat的zookeeper集群模式

Mycat学习实战-Mycat的zookeeper集群模式

[TOC]

1. ZooKeeper简介

ZooKeeper 是一个面向分布式系统的构建块。当设计一个分布式系统时,一般需要设计和开发一些协调服务:

名称服务— 名称服务是将一个名称映射到与该名称有关联的一些信息的服务。电话目录是将人的名字映射到其电话号码的一个名称服务。同样,DNS 服务也是一个名称服务,它将一个域名映射到一个 IP 地址。在分布式系统中,您可能想跟踪哪些服务器或服务在运行,并通过名称查看其状态。ZooKeeper 暴露了一个简单的接口来完成此工作。也可以将名称服务扩展到组成员服务,这样就可以获得与正在查找其名称的实体有关联的组的信息。

锁定— 为了允许在分布式系统中对共享资源进行有序的访问,可能需要实现分布式互斥(distributed mutexes)。ZooKeeper 提供一种简单的方式来实现它们。

同步— 与互斥同时出现的是同步访问共享资源的需求。无论是实现一个生产者-消费者队列,还是实现一个障碍,ZooKeeper 都提供一个简单的接口来实现该操作。

配置管理— 您可以使用 ZooKeeper 集中存储和管理分布式系统的配置。这意味着,所有新加入的节点都将在加入系统后就可以立即使用来自 ZooKeeper 的最新集中式配置。这还允许您通过其中一个 ZooKeeper 客户端更改集中式配置,集中地更改分布式系统的状态。

领导者选举— 分布式系统可能必须处理节点停机的问题,您可能想实现一个自动故障转移策略。ZooKeeper 通过领导者选举对此提供现成的支持。

2dd5a350c3d4889cb8d58b92e90e3447.png

2. ZooKeeper角色和端口

225a8bef793cef19fc8d43e71d136358.png

050e00a0b45981100be1217488209221.png

3. ZooKeeper部署简介

5db1f4acd14e6d16a126dac19123d8c3.png

4543e6e2958f5c99d702dad256f7246c.png

1d535ca267156054f5b3bee3f31352d2.png

4. ZooKeeper部署管理Mycat

36371e169f570fc1300ed11790d38662.png

4.1 环境

系统:CentOS7.3

jdk版本:1.7

zookeeper版本:3.4.10

mycat版本:1.6

hostname

IP

myid

testA

192.168.33.11

1

testB

192.168.33.12

2

testC

192.168.33.13

3

4.2 环境准备

为了测试方便,这里关闭系统防火墙和禁用selinux,生产环境防火墙则需要开放zookeeper相关端口,2181、2888、3888。

# 关闭防火墙

systemctl stop firewalld.service

systemctl disable firewalld.service

# 关闭SELINUX

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux

setenforce 0

1

2

3

4

5

6

7

8

# 关闭防火墙

systemctlstopfirewalld.service

systemctldisablefirewalld.service

# 关闭SELINUX

sed-i's/SELINUX=enforcing/SELINUX=disabled/g'/etc/sysconfig/selinux

setenforce0

4.3 安装zookeeper

先在testA节点安装,再同步到其它2个节点。

4.3.1 下载解压

mkdir -p /data/packages/

cd /data/packages/

wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

cd /usr/local/

tar -zxvf /data/packages/zookeeper-3.4.10.tar.gz

ln -s zookeeper-3.4.10 zookeeper

cd zookeeper

mkdir data log

cd conf/

cp zoo_sample.cfg zoo.cfg

1

2

3

4

5

6

7

8

9

10

11

mkdir-p/data/packages/

cd/data/packages/

wgethttp://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

cd/usr/local/

tar-zxvf/data/packages/zookeeper-3.4.10.tar.gz

ln-szookeeper-3.4.10zookeeper

cdzookeeper

mkdirdatalog

cdconf/

cpzoo_sample.cfgzoo.cfg

4.3.2 修改配置文件

vim zoo.cfg

# The number of milliseconds of each tick

tickTime=2000

# The number of ticks that the initial

# synchronization phase can take

initLimit=10

# The number of ticks that can pass between

# sending a request and getting an acknowledgement

syncLimit=5

# the directory where the snapshot is stored.

# do not use /tmp for storage, /tmp here is just

# example sakes.

dataDir=/usr/local/zookeeper/data

dataLogDir=/usr/local/zookeeper/log

# the port at which the clients will connect

clientPort=2181

server.1=192.168.33.11:2888:3888

server.2=192.168.33.12:2888:3888

server.3=192.168.33.13:2888:3888

# the maximum number of client connections.

# increase this if you need to handle more clients

#maxClientCnxns=60

#

# Be sure to read the maintenance section of the

# administrator guide before turning on autopurge.

#

# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance

#

# The number of snapshots to retain in dataDir

#autopurge.snapRetainCount=3

# Purge task interval in hours

# Set to "0" to disable auto purge feature

#autopurge.purgeInterval=1

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

# The number of milliseconds of each tick

tickTime=2000

# The number of ticks that the initial

# synchronization phase can take

initLimit=10

# The number of ticks that can pass between

# sending a request and getting an acknowledgement

syncLimit=5

# the directory where the snapshot is stored.

# do not use /tmp for storage, /tmp here is just

# example sakes.

dataDir=/usr/local/zookeeper/data

dataLogDir=/usr/local/zookeeper/log

# the port at which the clients will connect

clientPort=2181

server.1=192.168.33.11:2888:3888

server.2=192.168.33.12:2888:3888

server.3=192.168.33.13:2888:3888

# the maximum number of client connections.

# increase this if you need to handle more clients

#maxClientCnxns=60

#

# Be sure to read the maintenance section of the

# administrator guide before turning on autopurge.

#

# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance

#

# The number of snapshots to retain in dataDir

#autopurge.snapRetainCount=3

# Purge task interval in hours

# Set to "0" to disable auto purge feature

#autopurge.purgeInterval=1

4.3.3 添加myid文件

vim /usr/local/zookeeper/data/myid写入 1

4.3.4 同步zookeeper目录到其它2个节点,修改myid

rsync -avzP /usr/local/zookeeper/ root@192.168.33.12:/usr/local/zookeeper/

rsync -avzP /usr/local/zookeeper/ root@192.168.33.13:/usr/local/zookeeper/

1

2

3

rsync-avzP/usr/local/zookeeper/root@192.168.33.12:/usr/local/zookeeper/

rsync-avzP/usr/local/zookeeper/root@192.168.33.13:/usr/local/zookeeper/

并在2个节点分别修改对应的myid

4.3.5 启动zookeeper

cd /usr/local/zookeeper/bin/

./zkServer.sh start

1

2

3

cd/usr/local/zookeeper/bin/

./zkServer.shstart

2e401f0151c8e6c62f07502f3c730861.png

dcf39434684ae409c5d7cd07a186b5d1.png

e7b65eba9cb79972af0fcdb047248b92.png

4.4 安装Mycat

同样,3个节点都需要安装mycat。

cd /data/packages/

wget http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

cd /usr/local/

tar -zxvf /data/packages/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

1

2

3

4

5

cd/data/packages/

wgethttp://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

cd/usr/local/

tar-zxvf/data/packages/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

4.6 执行mycat初始化数据

3个节点Mycat都执行如下脚本

sh /usr/local/mycat/bin/init_zk_data.sh

1

2

sh/usr/local/mycat/bin/init_zk_data.sh

4.7 配置mycat支持zookeeper

vim /usr/local/mycat/conf/myid.properties

loadZk=true

# zk集群地址,多个用","隔开

zkURL=127.0.0.1:2181

# zk集群内Mycat集群ID

clusterId=mycat-cluster-1

# Mycat集群内本实例ID,禁止重复

myid=mycat_fz_01

# Mycat集群内节点个数

clusterSize=3

clusterNodes=mycat_fz_01,mycat_fz_02,mycat_fz_03

#server booster ; booster install on db same server,will reset all minCon to 1

type=server

boosterDataHosts=dataHost1

1

2

3

4

5

6

7

8

9

10

11

12

13

14

loadZk=true

# zk集群地址,多个用","隔开

zkURL=127.0.0.1:2181

# zk集群内Mycat集群ID

clusterId=mycat-cluster-1

# Mycat集群内本实例ID,禁止重复

myid=mycat_fz_01

# Mycat集群内节点个数

clusterSize=3

clusterNodes=mycat_fz_01,mycat_fz_02,mycat_fz_03

#server  booster  ;   booster install on db same server,will reset all minCon to 1

type=server

boosterDataHosts=dataHost1

4.8 用zookeeper配置mycat

使用ZooInspector工具管理ZooKeeper,以下是连接zookeeper方法。

9980803cf36b5e30a343776b59a4036d.png

连接成功后,可看到mycat集群的配置

c17d020b77cddf14ebd274a80cd59c8f.png

修改相应配置

d3e524bb996f3d306dfeb30aa487aa07.png

启动mycat后,mycat配置文件会自动更新。

038e1eb43a147205481c66d3abbb34a3.png

注意事项:

* loadZk必须改为true才生效

* zkURL的地址是多个中间用“,”隔开

* clusterId,同一个zk内的集群ID必须唯一

* Myid:本实例的id在当前的mycat集群内ID唯一

* 配置完zk并启动mycat后,会更新本地conf下的相关配置文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值