zoukankan      html  css  js  c++  java
  • 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、在任一台机器创建节点,其他机器将同步数据

  • 相关阅读:
    热烈祝贺《名博是怎样炼成的》出版
    公司年会在民俗文化村举行
    春节后第一周个人新闻两则
    用asp.net来回收IIS6.0应用程序池
    ComponentArt Web.UI 升级遇到的问题
    今天给博客设计了个博皮
    2009春运购火车票经历
    Android平台下实现一个进程管理器
    【转】Windows平台下Android源码的下载
    【转】 使用git 工具下载android.jar Source Code
  • 原文地址:https://www.cnblogs.com/lanqie/p/8656220.html
Copyright © 2011-2022 走看看