zookeeper集群配置

下载安装

官网下载最新版本的zookeeper

相关地址:http://mirror.bit.edu.cn/apache/zookeeper/current/

# wget --quiet http://mirror.bit.edu.cn/apache/zookeeper/current/zookeeper-3.4.10.tar.gz

# tar -xf zookeeper-3.4.10.tar.gz
# cd zookeeper-3.4.10

进入conf目录,将默认的zoo_sample.cfg改成zoo.cfg,执行命令:bin/zkServer.sh start启动即可

zkServer命令相关参数:

Usage: bin/zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}

集群配置

集群节点必须是奇数个

  1. 将解压出来的zookeeper目录拷贝三份,如:zookeeper1,zookeeper2,zookeeper3。
  2. 分别创建并修改配置文件zoo0x.cfgdataDirclientPort不能相同。
  3. 分别在三个dataDir目录中创建文件myid,存放对应服务节点数字,如:server.1存储1。
  4. 分别修改完成后,即可运行bin/zkServer.sh启动zookeeper服务节点。

配置文件参考:

vim /opt/zookeeper01/conf/zoo01.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=/tmp/zookeeper01
dataDir=/data/product/zookeeper01/datadir
# the port at which the clients will connect
clientPort=2181
# listen ip address
#clientPortAddress=localhost
# 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.01=localhost:2887:3887 
server.02=localhost:2888:3888
server.03=localhost:2889:3889

集群服务配置说明

server.A=B:C:D
- A 是一个数字,表示这个是第几号服务器;
- B 是这个服务器的IP地址(或者是与IP地址做了映射的主机名);
- C 第一个端口用来集群成员的信息交换,表示这个服务器与集群中的Leader服务器交换信息的端口;
- D 是在leader挂掉时专门用来进行选举leader所用的端口。

关于日志

默认情况下zookeeper的日志是根据执行bin/zkServer.sh start命令时所在的路径,在当前路径下创建一个文件名为:zookeeper.out的文件并将日志内容写入其中

修改日志保存到固定路径的文件下:

1,修改启动脚本bin/zkServer.sh,增加:

ZOO_LOG_DIR="$ZOOBINDIR/../logs"

2,修改vim bin/zkEnv.sh

 42 if [ "x$ZOOCFG" = "x" ]
 43 then
 44     ZOOCFG="zoo02.cfg"

客户端链接集群

spring:
  cloud:
    zookeeper:
      connect-string: localhost:2181,localhost:2182,localhost:2183

注意:如果使用 Spring Cloud Zookeeper Config 模块,必须配置在 bootstrap.yml 中

注意:zookeeper集群最好保持奇数个节点,如果集群中的节点只剩下1个,集群将会失效,客户端将无法连接

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值