zookeeper集群及mycat配置搭建

时间:2024-04-11 12:28:18

第一部分 zookeeper环境

环境:3台机器

192.168.109.132-134

centos7.2

 

1 linux环境设置

#关闭防火墙

systemctl stop firewalld.service

systemctl disable firewalld.service

 

#关闭SELINUX

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

setenforce 0

 

#设置时间

timedatectl set-ntp no

timedatectl set-timezone Asia/Shanghai

#手动设置为当前时间

timedatectl set-time "2017-10-1713:52:16"

timedatectl set-local-rtc 1

timedatectl set-ntp yes

 

2 安装配置zookeeper

#安装/root/zookeeper-3.4.10.tar.gz

cd /usr/local

tar zxvf /root/zookeeper-3.4.10.tar.gz

mv zookeeper-3.4.10 zookeeper

 

cd zookeeper

mkdir -p data log

 

cd conf

cp zoo_sample.cfg zoo.cfg

vim zoo.cfg

 

# The number of milliseconds of each tick

# 心跳检查的时间 2秒

tickTime=2000

# The number of ticks that the initial

# synchronization phase can take

# 初始化时 连接到服务器端的间隔次数,总时间10*2=20秒

initLimit=10

# The number of ticks that can pass between

# sending a request and getting anacknowledgement

# ZK Leader 和follower 之间通讯的次数,总时间5*2=10秒

syncLimit=5

# the directory where the snapshot isstored.

# do not use /tmp for storage, /tmp here isjust

# example sakes.

# 存储内存中数据库快照的位置,如果不设置参数,更新事务日志将被存储到默认位置/tmp

dataDir=/usr/local/zookeeper/data

# 错误日志的存放位置

dataLogDir=/usr/local/zookeeper/log

# the port at which the clients willconnect

clientPort=2181

server.1=192.168.109.132:2888:3888

server.2=192.168.109.133:2888:3888

server.3=192.168.109.134:2888:3888

图示:

 zookeeper集群及mycat配置搭建

cd ../data

touch myid

vim myid

1

#写入1

图示:

 zookeeper集群及mycat配置搭建

#复制到其他节点

scp -r /usr/local/zookeeper/[email protected]:/usr/local/zookeeper/

scp -r /usr/local/zookeeper/ [email protected]:/usr/local/zookeeper/

 

分别修改myid

vim /usr/local/zookeeper/data/myid

改为2和3,对应IP:192.168.109.133/134

 

启动:

cd /usr/local/zookeeper/bin

./zkServer.sh start

ZooKeeper JMX enabled by default

Using config:/usr/local/zookeeper/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

图示:

 zookeeper集群及mycat配置搭建

 

查看状态,3台机器,其中一个是leader,另外两个是follower

./zkServer.sh status

ZooKeeper JMX enabled by default

Using config:/usr/local/zookeeper/bin/../conf/zoo.cfg

Mode: leader

图示:

Leader节点

zookeeper集群及mycat配置搭建

Follower节点

zookeeper集群及mycat配置搭建

 

#至此,环境搭建成功

 

##############################################################

#如果是同一台机器,需要建3个目录

#配置文件

dataDir=/usr/local/server1/data

dataLogDir=/usr/local/server1/log

# the port at which the clients willconnect

clientPort=2181                          #每个目录端口号不一样

server.1=192.168.109.132:2888:3888

server.2=192.168.109.133:2889:3889

server.3=192.168.109.134:2890:3890

 

#myid文件,修改同上

 

#复制到其他节点

cp -r /usr/local/server1//usr/local/server2/

cp -r /usr/local/server1//usr/local/server3/

#################################################################

 

第二部分 mycat配置为通过zookeeper进行配置

1 环境准备

mycat两个节点

IP 192.168.109.128/135

mycat1.6.5

 

2 配置使用zookeeper,两个节点都需要修改

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

 

loadZk=true

zkURL=192.168.109.132:2181,192.168.109.133:2181,192.168.109.134:2181     #zookeeper集群节点,逗号分隔

clusterId=mycat-cluster-1                                                                                                              #mycat集群名字

myid=mycat_fz_01                                                                                                                           #mycat节点名字,另一台是mycat_fz_02

clusterSize=2                                                                                                                                      #mycat集群规模

clusterNodes=mycat_fz_01,mycat_fz_02                                                                                 #mycat集群节点成员,逗号分隔

#clusterSize=3

#clusterNodes=mycat_fz_01,mycat_fz_02,mycat_fz_04

#server booster  ;   booster install on db same server,will resetall minCon to 2

type=server

boosterDataHosts=dataHost1

图示:

 zookeeper集群及mycat配置搭建

3 初始化zookeeper配置

#拷贝mycat初始配置,将配置好的conf目录的文件复制到同级目录zkconf下

cp /usr/local/mycat/conf/dnindex.properties/usr/local/mycat/conf/zkconf/

cp /usr/local/mycat/conf/server.xml/usr/local/mycat/conf/zkconf/

cp /usr/local/mycat/conf/schema.xml/usr/local/mycat/conf/zkconf/

cp /usr/local/mycat/conf/rule.xml/usr/local/mycat/conf/zkconf/

#主要是以上文件,也可以将其他公用的配置文件拷贝zkconf

 

#拷贝所有文件

cp /usr/local/mycat/conf/*.xml/usr/local/mycat/conf/zkconf/

cp /usr/local/mycat/conf/*.properties/usr/local/mycat/conf/zkconf/

cp /usr/local/mycat/conf/*.txt/usr/local/mycat/conf/zkconf/

cp /usr/local/mycat/conf/*.conf/usr/local/mycat/conf/zkconf/

图示:

 zookeeper集群及mycat配置搭建

#初始化zookeeper

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

 

图示:

zookeeper集群及mycat配置搭建

注:初始化zookeeper时,配置的zookeeper集群节点必须全部在线

 

#新加入的mycat不需要做初始化的动作了,直接修改myid.properties连接上zk就可以获取配置,

#mycat集群内的myid.properties需要保持一致

myid=mycat_fz_02                                                                                                                           #mycat节点名字,另一台是mycat_fz_01

clusterSize=2                                                                                                                                      #mycat集群规模

clusterNodes=mycat_fz_01,mycat_fz_02

图示:

 zookeeper集群及mycat配置搭建

4 修改zookeeper配置,更新mycat配置

#方法,使用工具ZooInspector或者自己开发程序

运行 E:\apps\ZooInspector\build\zookeeper-dev-ZooInspector.jar

图示:

 zookeeper集群及mycat配置搭建

打开以后,点击最左侧按钮,填写连接信息

Connect String 192.168.109.132:2181    #连接zookeeper集群内任意节点即可

Session Timeout 5000                                           #默认

Data Encryption Managerorg.apache.zookeeper.inspector.encryption.BasicDataEncryptionManager

图示

zookeeper集群及mycat配置搭建

然后可以在左侧目录下看到所有使用zookeeper的配置项

图示:

 zookeeper集群及mycat配置搭建

注:在右侧可直接修改配置内容,修改后1分钟内所有mycat节点即可获取更新