zookeeper搭建(单机模式和集群模式)

        

目录

        单机模式:

        集群搭建


单机模式:

1.新建data和logs目录(data目录用来存放数据库快照,logs目录用来存放日志文件)

[root@master dev]# mkdir -p /home/apps/zookeeper/data
[root@master dev]# mkdir -p /home/apps/zookeeper/logs

2.找到zookeeper目录下的 conf 配置文件夹

[root@master dev]# cd /home/apps/zookeeper/conf/
[root@master conf]# ll
total 16
-rw-r--r--. 1 root root  535 May  4  2020 configuration.xsl
-rw-r--r--. 1 root root 2712 May  4  2020 log4j.properties
-rw-r--r--. 1 root root  922 May  4  2020 zoo_sample.cfg
-rw-r--r--. 1 root root  152 Jan 15 13:05 zoo.cfg.dynamic.next



3.重命名 zoo_sample.cfg 为zoo.cfg

[root@master conf]# mv zoo_sample.cfg zoo.cfg


4.用vi命令打开zoo.cfg文件

[root@master conf]# vi zoo.cfg
# The number of milliseconds of each tick
tickTime=2000  #Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,单位为毫秒
# The number of ticks that the initial
# synchronization phase can take
initLimit=10 #表示允许从服务器连接到leader并完成数据同步的时间,总的时间长度就是 initLimit * tickTime 秒
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5 #配置 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 syncLimit * tickTime 秒 
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/home/apps/zookeeper/data #Zookeeper 保存数据的数据库快照的位置
dataLogDir=/home/apps/zookeeper/logs #事务日志日志路径,若没提供的话则用dataDir
# the port at which the clients will connect
clientPort=2181 #Zookeeper服务器监听的端口,以接受客户端的访问请求
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60 # 限制连接到ZK上的客户端数量,并且限制并发连接数量,值为0表示不做任何限制
#
# 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 # 自动清理日志,该参数设置保留多少个快照文件和对应的事务日志文件,默认为3,如果小于3则自动调整为3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1


5.配置完之后就可以直接启动Zookeeper。

[root@master conf]# cd /home/apps/zookeeper/bin
[root@master bin]# ./zkServer.sh start

ZooKeeper JMX enabled by default
Using config: /home/apps/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

启动成功

6.可以使用 status 命令查看zookeeper状态

[root@master bin]# ./zkServer.sh status

集群搭建:

        1.解压压缩包

tar -zxvf /opt/software/apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module/

        2.进入zookeeper下面的conf,编辑zoo开头文件(修改框起来的):

cd /opt/module/zookeeper/conf
vim zoo_sample.cfg

        3.进入到zookeeper下,新建data目录

mkdir data

 

        进入data目录,新建myid文件

cd /opt/module/zookeeper/data
vim myid

在myid文件中写入1:

 

 

         4.分发文件:

分发给bigdata2:

scp -r /opt/module/zookeeper root@bigdata2:/opt/module/

分发给bigdata3:

scp -r /opt/module/zookeeper root@bigdata3:/opt/module/

        5.修改bigdata2和bigdata3中zookeeper下面data目录中的myid文件

bigdata2:

[root@bigdata2 /] cd /opt/module/zookeeper/data

编辑myid:

[root@bigdata2 data]vim myid

 将原来的1修改为2:

bigdata3:

[root@bigdata2 /]cd /opt/module/zookeeper/data

 修改myid文件:

[root@bigdata2 data]vim myid

将原来的1修改为3:

 

 

        5.启动并查看

启动zookeeper:

[root@bigdata1 /]sh /opt/module/zookeeper/bin/zkServer.sh start

[root@bigdata2 /]sh /opt/module/zookeeper/bin/zkServer.sh start

 

[root@bigdata3 /]sh /opt/module/zookeeper/bin/zkServer.sh start

 

查看状态:

 

 

 

 

 

 

  • 9
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值