Zookeeper-3.4.13集群配置

一、下载Zookeeper-3.4.13

官网下载地址
Zookeeper-3.4.13集群配置_第1张图片

二、解压Zookeeper-3.4.13到/usr/local/,并该名为zookeeper

三、配置Zookeeper

1.复制模版文件zoo_sample.cfg为zoo.cfg

cp /usr/local/zookeeper/conf/zoo_sample.cfg  /usr/local/zookeeper/conf/zoo.cfg

将zoo_sample.cfg 复制一份为zoo.cfg

2.修改配置文件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/datalog
# the port at which the clients will connect
clientPort=2181
# 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
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888

Zookeeper-3.4.13集群配置_第2张图片

四、创建所需目录和新建的myid文件

创建/usr/local/zookeeper/data与/usr/local/zookeeper/datalog目录

sudo mkdir /usr/local/zookeeper/data
sudo mkdir /usr/local/zookeeper/datalog
sudo vim /usr/local/zookeeper/data/myid

将myid内容设置为1
设置为1是由于配置文件zoo.cfg中“server.id=host:port:port”,配置项master机器对应的“id”为"1"
在这里插入图片描述

五、同步zookeeper文件到salve1、slave2

su root
scp -r /usr/local/zookeeper root@slave1:/usr/local/zookeeper
scp -r /usr/local/zookeeper root@slave2:/usr/local/zookeeper

Zookeeper-3.4.13集群配置_第3张图片

六、设置$ZOOKEEPER_HOME的目录属主

为了在普通用户下使用Zookeeper集群,依次将master、slave1、slave2三台机器上的zookeeper目录设置为linux普通用户

chown -R 用户名 /usr/local/zookeeper

七、修改slave1、slave2的myid内容

在slave1、slave2中执行

sudo vim /usr/local/zookeeper/data/myid

在这里插入图片描述
在这里插入图片描述

八、在用户主目录中添加环境变量

在这里插入图片描述

export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=$ZOOKEEPER_HOME/bin:$PATH

在这里插入图片描述

source ~/.bashrc

配置好后三台机器都执行zkServer.sh start

zkServer.sh start

九、验证zookeeper集群

zkServer.sh status
jps

leader角色按照内部算法分配 这次slave1为leader, master与slave2为follower
Zookeeper-3.4.13集群配置_第4张图片
Zookeeper-3.4.13集群配置_第5张图片
master、slave1、slave2 三机器jps出现上图QuorumPeerMain 说明zookeeper集群配置成功

你可能感兴趣的:(zookeeper,分布式)