• Zookeeper:在三种模式下的部署


    zookeeper 安装模式有三种:单机模式:单机单 server;集群模式:多机多 server,形成集群;伪集群模式:单机多 server,形成伪集群。

    ~

    本篇内容包括:Zookeeper 官网下载、Zookeeper 单机模式部署、Zookeeper 集群安装、Zookeeper 集群安装



    一、Zookeeper 官网下载

    进入官网下载 Zookeeper,这里我们使用的版本为 Zookeeper-3.5.7

    Zookeeper 官网地址: http://zookeeper.apache.org/

    zookeeper 安装模式有三种:单机模式:单机单 server;集群模式:多机多 server,形成集群;伪集群模式:单机多 server,形成伪集群。

    二、Zookeeper 单机模式部署

    1、安装 JDK

    # 安装JDK

    可以参照:Java基础:Java程序设计环境

    2、安装 Zookeeper

    # 官网下载

    # 拷贝 apache-zookeeper-3.5.7-bin.tar.gz 到 Linux系统下

    # 解压到指定目录:

    tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module/
    
    • 1

    # 改名

    mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7
    
    • 1
    3、修改 Zookpeeper 配置

    # 进入conf目录

    # mv zoo_sample.cfg zoo.cfg

    # mkdir /opt/module/zookeeper-3.5.7/zkData

    # vi 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 an acknowledgement
    syncLimit=5
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just
    # example sakes.
    dataDir=/opt/module/zookeeper-3.5.7/zkData
    # the port at which the clients will connect
    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    4、运行 Zookeeper

    # 启动Zookeeper:bin/zkServer.sh start

    # 查看进程jps

    # 客户端访问:bin/zkCli.sh

    三、Zookeeper 集群安装

    1、安装JDK(每一台服务器);

    # 安装JDK

    可以参照:Java基础:Java程序设计环境

    2、安装 Zookeeper

    # 拷贝 apache-zookeeper-3.5.7-bin.tar.gz 到 Linux系统下(每一台服务器)

    # 解压到指定目录(每一台服务器):

    tar -zxvf apache-zookeeper-3.5.7-bin.tar.gz -C /opt/module/
    
    • 1

    # 改名(每一台服务器)

    mv apache-zookeeper-3.5.7-bin zookeeper-3.5.7
    
    • 1
    3、修改 Zookpeeper 配置

    # 进入conf目录(每一台服务器)

    # mv zoo_sample.cfg zoo.cfg(每一台服务器)

    # mkdir /opt/module/zookeeper-3.5.7/zkData(每一台服务器)

    # vi /opt/module/zookeeper-3.5.7/zkData/myid,填写每天服务器对应的 ID

    # vi 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 an acknowledgement
    syncLimit=5
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just
    # example sakes.
    dataDir=/opt/module/zookeeper-3.5.7/zkData
    # the port at which the clients will connect
    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.1=master:2888:3888
    server.2=slave1:2888:3888
    server.3=slave2:2888:3888
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    4、运行 Zookeeper

    # 启动服务:每台机器执行:bin/zkServer.sh start

    # 查看每个节点状态:bin/zkServer.sh status

    四、Zookeeper 集群启动停止脚本

    #!/bin/bash
    
    case $1 in
    "start"){
            for i in master slave1 slave2
            do
                    echo ----- zookeeper $i 启动-----
                    ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh start"
            done
    }
    ;;
    "stop"){
            for i in master slave1 slave2
            do
                    echo ----- zookeeper $i 停止-----
                    ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh stop"
            done
    }
    ;;
    "status"){
            for i in master slave1 slave2
            do
                    echo ----- zookeeper $i 状态-----
                    ssh $i "/opt/module/zookeeper-3.5.7/bin/zkServer.sh status"
            done
    }
    ;;
    esac
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
  • 相关阅读:
    2023_Spark_实验七:Scala函数式编程部分演示
    java-php-python-基于vue框架的疫情防控知识在线答题系统设计与实现计算机毕业设计
    分销系统开发|如何正确定义三级分销?
    ip地址跟wifi有关系吗
    设计模式系列详解 -- 对象池模式&解释器模式
    Dijkstra算法
    Java整合t-io实现在线聊天功能
    速盾:cdn缓存的文件是无法被篡改的吧?
    2023-11笔记
    树莓派无桌面配置WiFi连接
  • 原文地址:https://blog.csdn.net/weixin_45187434/article/details/127939706