ZooKeeper安装

ZooKeeper安装

ZooKeeper单机安装

  • 官网下载地址

  • 环境

    • centos7
    • jdk8
  • 创建用户zookeeper

    # 创建用户组
    groupadd zookeeper
    # 创建用户
    useradd -d /home/zookeeper -g zookeeper -G zookeeper -m zookeeper
    # 创建密码
    passwd zookeeper
    
  • 上传安装包并解压

    [zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$ ll
    total 35816
    drwxr-xr-x 11 zookeeper zookeeper     4096 Mar  9 11:44 zookeeper-3.4.12
    -rwxr-xr-x  1 zookeeper zookeeper 36667596 Mar  9 11:43 zookeeper-3.4.12.tar.gz
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$ 
    
  • 修改配置文件

    # 进入配置目录
    cd zookeeper-3.4.12/conf/
    # 修改配置文件名
    cp zoo_sample.cfg zoo.cfg
    # 修改配置文件
    vi zoo.cfg
    
    # The number of milliseconds of each tick
    # tickTime:CS通信心跳数
    # Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。
    tickTime=2000
    
    # The number of ticks that the initial 
    # synchronization phase can take
    # initLimit:LF初始通信时限
    # 集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
    initLimit=10
    
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    # syncLimit:LF同步通信时限
    # 集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
    syncLimit=5
    
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    # dataDir:数据文件目录
    # zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
    dataDir=/home/zookeeper/software/zookeeper-3.4.12/data
    
    # dataLogDir:日志文件目录
    # zookeeper保存日志文件的目录。
    dataLogDir=/home/zookeeper/software/zookeeper-3.4.12/logs
    
    # the port at which the clients will connect
    # clientPort:客户端连接端口
    # 客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
    clientPort=2181
    
    # 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
    
  • 命令汇总

    # 启动命令
    ./bin/zkServer.sh start
    # 停止命令
    ./bin/zkServer.sh stop  
    # 重启命令
    ./bin/zkServer.sh restart
    # 状态查看命令
    ./bin/zkServer.sh status
    

ZooKeeper集群单机部署

  • 部署规划

    ip client端服务端口 zk通讯端口 zk选举端口
    127.0.0.1 2181 2887 3887
    127.0.0.1 2182 2888 3888
    127.0.0.1 2183 2889 3889
  • 官网下载地址

  • 环境

    • centos7
    • jdk8
  • 创建用户zookeeper

    # 创建用户组
    groupadd zookeeper
    # 创建用户
    useradd -d /home/zookeeper -g zookeeper -G zookeeper -m zookeeper
    # 创建密码
    passwd zookeeper
    
  • 上传安装包并解压三份

    [zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$ ll
    total 35824
    drwxr-xr-x 10 zookeeper zookeeper     4096 Mar 10 16:56 zk1
    drwxr-xr-x 10 zookeeper zookeeper     4096 Mar 10 16:56 zk2
    drwxr-xr-x 10 zookeeper zookeeper     4096 Mar 10 16:56 zk3
    -rwxr-xr-x  1 zookeeper zookeeper 36667596 Mar  9 11:43 zookeeper-3.4.12.tar.gz
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ software]$ 
    
  • 创建myid文件

    # zk1服务器
    mkdir zk1/data
    cd zk1/data/
    
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$ pwd
    /home/zookeeper/software/zk1/data
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$
    
    # 创建myid文件,并写入内容1
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$ cat myid
    1
    [zookeeper@iZuf62iexj3ztw81eg1cnoZ data]$ 
    
    # zk2, zk3服务器分别创建myid文件,分别写入2,3
    
  • 配置文件

    # 进入配置目录
    cd zk1/conf/
    # 修改配置文件名
    cp zoo_sample.cfg zoo.cfg
    

    zk1-zoo.cfg

    # The number of milliseconds of each tick
    # tickTime:CS通信心跳数
    # Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。
    tickTime=2000
    
    # The number of ticks that the initial 
    # synchronization phase can take
    # initLimit:LF初始通信时限
    # 集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
    initLimit=10
    
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    # syncLimit:LF同步通信时限
    # 集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
    syncLimit=5
    
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    # dataDir:数据文件目录
    # zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
    dataDir=/home/zookeeper/software/zk1/data
    # dataLogDir:日志文件目录
    # zookeeper保存日志文件的目录。
    dataLogDir=/home/zookeeper/software/zk1/logs
    
    # the port at which the clients will connect
    # clientPort:客户端连接端口
    # 客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
    clientPort=2181
    
    # 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.myid文件中的值=ip:集群内部通讯地址:集群选举端口
    server.1=127.0.0.1:2887:3887
    server.2=127.0.0.1:2888:3888
    server.3=127.0.0.1:2889:3889
    

    zk2-zoo.cfg

    # The number of milliseconds of each tick
    # tickTime:CS通信心跳数
    # Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。
    tickTime=2000
    
    # The number of ticks that the initial 
    # synchronization phase can take
    # initLimit:LF初始通信时限
    # 集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
    initLimit=10
    
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    # syncLimit:LF同步通信时限
    # 集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
    syncLimit=5
    
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    # dataDir:数据文件目录
    # zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
    dataDir=/home/zookeeper/software/zk2/data
    # dataLogDir:日志文件目录
    # zookeeper保存日志文件的目录。
    dataLogDir=/home/zookeeper/software/zk2/logs
    
    # the port at which the clients will connect
    # clientPort:客户端连接端口
    # 客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
    clientPort=2182
    
    # 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.myid文件中的值=ip:集群内部通讯地址:集群选举端口
    server.1=127.0.0.1:2887:3887
    server.2=127.0.0.1:2888:3888
    server.3=127.0.0.1:2889:3889
    

    zk3-zoo.cfg

    # The number of milliseconds of each tick
    # tickTime:CS通信心跳数
    # Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位。
    tickTime=2000
    
    # The number of ticks that the initial 
    # synchronization phase can take
    # initLimit:LF初始通信时限
    # 集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)。
    initLimit=10
    
    # The number of ticks that can pass between 
    # sending a request and getting an acknowledgement
    # syncLimit:LF同步通信时限
    # 集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)。
    syncLimit=5
    
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just 
    # example sakes.
    # dataDir:数据文件目录
    # zookeeper保存数据的目录,默认情况下,Zookeeper将写数据的日志文件也保存在这个目录里。
    dataDir=/home/zookeeper/software/zk3/data
    # dataLogDir:日志文件目录
    # zookeeper保存日志文件的目录。
    dataLogDir=/home/zookeeper/software/zk3/logs
    
    # the port at which the clients will connect
    # clientPort:客户端连接端口
    # 客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
    clientPort=2183
    
    # 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.myid文件中的值=ip:集群内部通讯地址:集群选举端口
    server.1=127.0.0.1:2887:3887
    server.2=127.0.0.1:2888:3888
    server.3=127.0.0.1:2889:3889
    
  • 启动

    # zk1
    /home/zookeeper/software/zk1/bin/zkServer.sh start
    # zk2
    /home/zookeeper/software/zk2/bin/zkServer.sh start
    # zk3
    /home/zookeeper/software/zk3/bin/zkServer.sh start
    
  • 查看状态

    # zk1
    /home/zookeeper/software/zk1/bin/zkServer.sh status
    ----------------
    ZooKeeper JMX enabled by default
    Using config: /home/zookeeper/software/zk1/bin/../conf/zoo.cfg
    Mode: follower
    ----------------
    # zk2
    /home/zookeeper/software/zk2/bin/zkServer.sh status
    ----------------
    ZooKeeper JMX enabled by default
    Using config: /home/zookeeper/software/zk2/bin/../conf/zoo.cfg
    Mode: leader
    ----------------
    # zk3
    /home/zookeeper/software/zk3/bin/zkServer.sh status
    ----------------
    ZooKeeper JMX enabled by default
    Using config: /home/zookeeper/software/zk3/bin/../conf/zoo.cfg
    Mode: follower
    ----------------
    

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容