zookeeper-伪分布式集群搭建

搭建一主两从集群:一个Leader 两个Follower

创建数据目录跟myid文件

因为是搭建伪集群,所以要给Zookeeper创建三个数据目录:

1. 在 $ZK_HOME 下面创建数据目录 data
2. 在data目录下创建zookeeper1、zookeeper2、zookeeper3 三个目录并且在每个目录下创建myid文件,内容为zookeeper的服务节点ID 自定义。

在conf下拷贝出3个zoo1.cfg 、zoo2.cfg 、zoo3.cfg

配置文件

zoo1.cfg

 10 # do not use /tmp for storage, /tmp here is just 
 11 # example sakes.
 12 dataDir=/usr/local/zookeeper-3.4.14/data/zookeeper1
 13 # the port at which the clients will connect
 # 再次修改客户端连接的端口 另外两个分别为2182、2183
 14 clientPort=2181
 15 # the maximum number of client connections.
 16 # increase this if you need to handle more clients
 17 #maxClientCnxns=60
 18 #
 19 # Be sure to read the maintenance section of the 
 20 # administrator guide before turning on autopurge.
 21 #
 22 # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
 23 #
 24 # The number of snapshots to retain in dataDir
 25 #autopurge.snapRetainCount=3
 26 # Purge task interval in hours
 27 # Set to "0" to disable auto purge feature
 28 #autopurge.purgeInterval=1
 29 # 这里的IP在真实集群下可以一致 伪分布要给不同的zookeeper 不同的ID 但是3个配置文件都是一样的 
 30 server.1=127.0.0.1:2881:3881
 31 server.2=127.0.0.1:2882:3882
 32 server.3=127.0.0.1:2883:3883

注意最后三行

  server.1=127.0.0.1:2881:3881
  server.2=127.0.0.1:2882:3882
  server.3=127.0.0.1:2883:3883

server.$id=ip:port1:port2

  • $id 就是在数据目录下myid文件中的id;
  • ip 就是zookeeper的ip
  • port1: 第一个端口用来集群成员的信息交换,表示这个服务器与集群中的leader服务器交换信息的端口
  • port2是在leader挂掉时专门用来进行选举leader所用的端口
启动zookeeper集群

/usr/local/zookeeper-3.4.14/bin 执行如下的命令启动集群

./zkServer.sh start ../conf/zoo1.cfg
./zkServer.sh start ../conf/zoo2.cfg
./zkServer.sh start ../conf/zoo3.cfg

然后查看状态
./zkServer.sh status ../conf/zoo1.cfg
./zkServer.sh status ../conf/zoo2.cfg
./zkServer.sh status ../conf/zoo3.cfg

可以看到一个Leader节点跟两个Follower节点。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值