• Zookeeper学习笔记2


    环境搭建

    JDK(>1.6)安装

    Zookeeper安装

    1、下载
    http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.10.tar.gz
    2、解压

    tar -zxvf zookeeper-3.4.10.tar.gz
    

    3、在zookeeper-xx/conf文件夹下面创建配置文件,可直接复制zoo_sample.cfg

    cp 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 an acknowledgement
    syncLimit=5
    # the directory where the snapshot is stored.
    dataDir=/tmp/zookeeper
    # the port at which the clients will connect
    clientPort=2181
    

    运行

    单机环境

    1、配置文件默认zoo.cfg
    2、启动服务

    3、启动客户端

    集群环境

    搭建集群只需要修改配置文件,添加一个myid的文件
    1、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.
    dataDir=/tmp/zookeeper
    # the port at which the clients will connect
    clientPort=2181
    server.1=192.168.2.192:2888:3888
    server.2=192.168.2.200:2888:3888
    server.3=192.168.2.233:2888:3888
    

    server.server_id=server_ip:port_1:port_2
    server_id:服务器编号1~255
    server_ip:服务器ip
    port_1:flower和leader同步数据的端口
    port_2:flower进行leader选举的端口

    2、在192.168.2.192机器上添加/tmp/zookeeper/myid
    内容为1,
    同理,其他机器的zoo.cfg一样,添加对应的myid文件

    3、在其中任意台机器中运行

    ./bin/zkServer.sh status
    

    你将会看到是leader还是flower

    JMX enabled by default
    Using config: /opt/Java/zookeeper-3.3.6/bin/../conf/zoo.cfg
    Mode: leader
    

    如果提示未运行,请查看zookeeper.out找到原因

    4、在任一台机器创建节点,其他机器将同步数据

  • 相关阅读:
    【WPF】城市级联(XmlDataProvider)
    【C#】利用反射构建实体
    毕业档案保存
    【WPF】淡入淡出切换页面
    【C#】Lamada表达式演变过程
    【C#】实现INotifyPropertyChanged的3种方法
    【Unity】矩阵运算
    (win7/8/10)鼠标右键添加按下SHIFT键时弹出带管理员权限的“在此处打开命令窗口”
    如何给grldr.mbr和grldr改名
    常用的时间同步服务器地址
  • 原文地址:https://www.cnblogs.com/lanqie/p/8656220.html
Copyright © 2020-2023  润新知