Zookeeper集群搭建

  1. apache官网下载合适的Zookeeper版本 地址,Zookeeper依赖jdk,提前安好jdk版本,建议使用oracle的jdk,建议不要使用openjdk
  2. 至少准备好三台Linux虚拟机,将下载的Zookeeper包上传到随意一个目录下在这里插入图片描述
  3. 使用解压命令tar -xf zookeeper-3.4.6.tar.gz,解压好后如下在这里插入图片描述
  4. 为了方便执行Zookeeper命令,配置下环境变量 vi /etc/profile,添加如下
    export ZOOKEEPER_HOME=/data/zookeeper-3.4.6
    export PATH=$PATH:$ZOOKEEPER_HOME/bin
    在这里插入图片描述
  5. 执行 source /etc/profile 让环境变量生效
  6. 在任何位置输入 zk,再按tab就会有对应指令的提示,就说明我们环境变量配置成功了在这里插入图片描述
  7. 其他三台也做同样的处理
  8. 修改Zookeeper的配置文件,在Zookeeper的conf目录下有一个zoo_sample.cfg的配置文件,这个是官方给的模板配置文件,拷贝一份同时命名为zoo.cfg,cp zoo_sample.cfg zoo.cfg,在此文件基础上进行修改
# The number of milliseconds of each tick
# 心跳间隔
tickTime=2000
# The number of ticks that the initial 
# synchronization phase can take
# 初始化期间follower与leader最大容忍心跳次数
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.
# zookeeper 数据存放位置
dataDir=/usr/local/zookeeper
# 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.[myid]=[服务器IP/域名]:[Follower和Leader的通信端口]:[选举端口]
server.1=axs2:2888:3888
server.2=axs6:2888:3888
server.3=axs8:2888:3888
  1. 将 zookeeper-3.4.6 文件夹拷贝到其他两台虚拟机上
    scp -r ./zookeeper-3.4.6/ axs6:/data/
    scp -r ./zookeeper-3.4.6/ axs8:/data/
  2. 三台虚拟机分别创建目录 mkdir /usr/local/zookeeper
  3. 三台虚拟机分别添加myid文件 myid 要和配置文件中的myid一致
    echo 1 > /usr/local/zookeeper/myid
    echo 2 > /usr/local/zookeeper/myid
    echo 3 > /usr/local/zookeeper/myid
  4. 按照 1 2 3的顺序启动Zookeeper,如下就启动成功
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值