zookeeper集群配置

来源:互联网 发布:网络购物被骗怎么办 编辑:程序博客网 时间:2024/06/05 20:13

下载安装

从官网下载最新版本的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 ticktickTime=2000# The number of ticks that the initial # synchronization phase can takeinitLimit=10# The number of ticks that can pass between # sending a request and getting an acknowledgementsyncLimit=5# the directory where the snapshot is stored.# do not use /tmp for storage, /tmp here is just # example sakes.#dataDir=/tmp/zookeeper01dataDir=/data/product/zookeeper01/datadir# the port at which the clients will connectclientPort=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=1server.01=localhost:2887:3887 server.02=localhost:2888:3888server.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个,集群将会失效,客户端将无法连接

原创粉丝点击