Zookeeper集群搭建实践

前言

   这里记录一下第一次搭建的过程,此次搭建的是3.4.6版本的,只是单IP多端口的实践,如果想要多个IP搭建的话,可以多安装几个虚拟机

环境

   JDK1.6或者1.6以上

步骤

   1.修改操作系统的/etc/hosts vi /etc/hosts

    在文件中添加

192.168.126.129 edu-provider-01
    前面的IP是虚拟机的IP地址

    2.下载zookeeper安装包

    执行命令:
    wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz

    3.解压zookeeper到指定安装目录

$ tar –zxvf zookeeper-3.4.6.tar.gz –C /usr/local/zookeeper3.4.6/zookeeper-3.4.6
    4.在安装目录下创建一下文件

$ cd /usr/local/zookeeper3.4.6/zookeeper-3.4.6
$mkdir data
$ mkdir logs
    5.将/usr/local/zookeeper3.4.6/zookeeper-3.4.6/conf 目录下的 zoo_sample.cfg 文件拷贝一份,命名为为zoo.cfg

 cp zoo_sample.cfg zoo.cfg
    6.修改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/zookeeper3.4.6/zookeeper-3.4.6/data
dataLogDir=/usr/local/zookeeper3.4.6/zookeeper-3.4.6/logs
# 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=edu-provider-01:2888:3888
server.2=edu-provider-01:2889:3889
server.3=edu-provider-01:2890:3890
   7.复制两份zoo.cfg

cp zoo.cfg zoo1.cfg
cp.zoo.cfg zoo2.cfg
   将里面clientPort依次改为2182和2183

dataDir=/usr/local/zookeeper3.4.6/zookeeper-3.4.6/data
zoo1.cfg的data改为data1,zoo2.cfg里的data改为data2
   8. 在 dataDir=/usr/local/zookeeper3.4.6/zookeeper-3.4.6/data 下创建 myid 文件,编辑 myid 文件

vi myid
1
   9.复制dataDir=/usr/local/zookeeper3.4.6/zookeeper-3.4.6/data 下的data文件夹两份

cp -r /usr/local/zookeeper3.4.6/zookeeper-3.4.6/data /usr/local/zookeeper3.4.6/zookeeper-3.4.6/data1
cp -r /usr/local/zookeeper3.4.6/zookeeper-3.4.6/data /usr/local/zookeeper3.4.6/zookeeper-3.4.6/data2
   10.修改data1和data2中的myid文件,将data1中的值改为2,将data2的值改为3
   11.关闭防火墙CentOS7中关闭防火墙

$ systemctl disable firewalld.service
   至此环境就已经搭建完成了,接下来就是启动测试验证了

   进入bin目录下挨个启动

$./zkServer.sh start zoo.cfg 
$./zkServer.sh start zoo1.cfg
$./zkServer.sh start zoo2.cfg


查看状态


小结

   虽然这些步骤看起来不难,真正在实践过程中才会知道你会遇到什么错误,也能够体会问题解决后的喜悦!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值