zoukankan      html  css  js  c++  java
  • 002-zookeeper 基本配置、安装启动 windows环境

    一. 概述

    ZooKeeper是Hadoop的正式子项目,它是一个针对大型分布式系统的可靠协调系统,提供的功能包括:配置维护、名字服务、分布式同步、组服务等。ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。

    二、安装使用

    2.1、下载

      地址:https://mirrors.cnnic.cn/apache/zookeeper/

    2.2、Windows下安装

      1》把下载的zookeeper的文件解压到指定目录:D:developTooolzookeeper-3.4.11

      2》修改conf下增加一个zoo.cfg,内容如下:

      zookeeper的默认配置文件为zookeeper/conf/zoo_sample.cfg,需要将其修改为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 anacknowledgement
    syncLimit=5
    
    # the directory where the snapshot isstored.  //镜像数据位置
    dataDir=D:\zookeeper
    
    #日志位置
    dataLogDir=D:\zookeeper\logs
    # the port at which the clients willconnect 客户端连接的端口 clientPort=2181

      注:如果启动有报错提示cfg文件有错误,可以用zoo_sample.cfg内内容替代也是可以的

    1.tickTime:CS通信心跳时间(cs: client serve)
      Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。
      tickTime=2000

    2.initLimit:LF初始通信时限
      集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
      initLimit=5,

    3.syncLimit:LF同步通信时限
      集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
      syncLimit=2

    4.dataDir:数据文件目录   myid 也放这里
      Zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
      dataDir=/home/michael/opt/zookeeper/data

    5.clientPort:客户端连接端口
      客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
      clientPort=2181

    6.服务器名称与地址:集群信息(服务器编号,服务器地址,LF通信端口,选举端口)

      规则如下:server.N=YYY:A:B

        其中N 是一个数字,表示这个是第几号服务器;

        YYY 是这个服务器的 ip 地址;

        A 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;

        B 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 YYY 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。

        server.1=127.0.0.1:2888:3888 
        server.2=127.0.0.1:2889:3889

    2.3、启动服务端

    进入到bin目录,并且启动zkServer.cmd,这个脚本中会启动一个java进程  

    D:developTooolzookeeper-3.4.11>cd bin
    D:developTooolzookeeper-3.4.11in>zkServer.cmd

    启动后jps可以看到QuorumPeerMain的进程

    2.4、启动客户端运行查看一下

    zkCli.cmd -server 127.0.0.1:2181

    三、伪集群

    在上述能配置基础上

    3.1、CMD配置

    将zkServer.cmd复制为:zkServer-1.cmd

    在对应的zkServer-1.cmd文件中添加

    set ZOOCFG=..confzoo1.cfg

    zkServer-2.cmd、zkServer-3.cmd依次类推

    set ZOOCFG=..confzoo2.cfg
    set ZOOCFG=..confzoo3.cfg

    3.2、cfg配置

    将原来zoo.cfg复制为zoo1.cfg

    dataDir=D:\zookeeper\1
    clientPort=2181
    server.1=127.0.0.1:2887:3887
    server.2=127.0.0.1:2888:3888
    server.3=127.0.0.1:2889:3889

    同时配置:zoo2.cfg、zoo3.cfg

    dataDir=D:\zookeeper\2
    clientPort=2182
    server.1=127.0.0.1:2887:3887
    server.2=127.0.0.1:2888:3888
    server.3=127.0.0.1:2889:3889
    dataDir=D:\zookeeper\3
    clientPort=2183
    server.1=127.0.0.1:2887:3887
    server.2=127.0.0.1:2888:3888
    server.3=127.0.0.1:2889:3889

    3.3、增加myid

    还需要 在对应的:D:\zookeeper\1,D:\zookeeper\2,D:\zookeeper\3

     建立一个文本文件命名为myid,内容就为对应的zoo.cfg里server.后数字

    启动zkServer1.cmd、zkServer2.cmd、zkServer3.cmd即可。

  • 相关阅读:
    is quoted with ["] which must be escaped when used within the value
    QueryDSL与SpringDataJPA复杂查询
    遍历list,同时remove不符合条件的元素
    解决AnnotationTransactionAttributeSource is only available on Java 1.5 and highe
    Windows系统安装MySQL
    sqlyog导sql文件
    myeclipse导入maven项目
    Invalid 'log4jConfigLocation' parameter: class path resource [log4j.xml] cannot be resolved to URL because it does not exist
    Nginx SSL+tomcat集群,取不到https正确协议
    微信开发之通过代理调试本地项目
  • 原文地址:https://www.cnblogs.com/bjlhx/p/8746453.html
Copyright © 2011-2022 走看看