zoukankan      html  css  js  c++  java
  • centos7安装zookeeper3.4.6

    注:zookeeper充当注册中心 

    下载地址

    http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.6/

    单机

    下载完成后,将安装包上传值服务器,解压

    tar xvzf zookeeper-3.4.6.tar.gz

    进入解压后的目录

    cd zookeeper-3.4.6

    创建data,logs目录

    mkdri data

    mkdri logs

    找到conf文件夹,进去

    cd conf

    拷贝一份 zoo_sample.cfg到 zoo.cfg

     cp zoo_sample.cfg zoo.cfg

    编辑zoo.cfg

    tickTime=2000
    initLimit=10
    syncLimit=5
    dataDir=/zookeeper-3.4.6/data
    dataLogDir=/zookeeper-3.4.6/logs
    clientPort=2181

    cd /zookeeper-3.4.6/bin

     ./zkServer.sh start 

    ./zkServer.sh status (查看状态)

     ./zkServer.sh stop(关闭)

    集群

    $ cd zookeeper-3.4.6/conf
    $ cp zoo_sample.cfg zoo.cfg
    $ vi zoo.cfg
    
    各机器下,zoo.cfg配置内容
    master:
    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=/home/hadoop/zookeeper/data
    dataLogDir=/home/hadoop/zookeeper/logs
    # the port at which the clients will connect
    clientPort=2181
    server.1=master:8880:7770
    server.2=slave1:8880:7770
    server.3=slave2:8880:7770
    
    slave1:
    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=/home/hadoop/zookeeper/data
    dataLogDir=/home/hadoop/zookeeper/logs
    # the port at which the clients will connect
    clientPort=2182
    server.1=master:8880:7770
    server.2=slave1:8880:7770
    server.3=slave2:8880:7770
    
    192.168.192.13:
    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=/home/hadoop/zookeeper/data
    dataLogDir=/home/hadoop/zookeeper/logs
    # the port at which the clients will connect
    clientPort=2183
    server.1=master:8880:7770
    server.2=slave1:8880:7770
    server.3=slave2:8880:7770
    • 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
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67

    在刚才创建的data文件夹地下创建myid文件

    $ vi myid
    
    各节点myid文件内容如下
    192.168.192.11:
    1
    192.168.192.12:
    2
    192.168.192.13:
    3
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    各节点分别启动zookeeper

    $ cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin
    $ ./zkServer.sh start
    
    $ ./zkServer.sh status (查看状态)
    $ ./zkServer.sh stop(关闭)
    • 1
    • 2
    • 3
    • 4
    • 5

    我这里写了各小脚本,方便在Master直接调用脚本启动Zookeeper和关闭Zookeeper 
    启动脚本如下:

    #!/bin/bash
    cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin
    ./zkServer.sh start
    ssh -tt  hadoop@192.168.192.12 > /dev/null 2>&1  << remotessh
    cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin
    ./zkServer.sh start
    exit
    remotessh
    
    ssh -tt hadoop@192.168.192.13 > /dev/null 2>&1  << remotessh
    cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin
    ./zkServer.sh start
    exit
    remotessh
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    关闭脚本如下:

    #!/bin/bash
    cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin/
    ./zkServer.sh stop
    ssh -tt  hadoop@192.168.192.12 > /dev/null 2>&1 << remotessh
    cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin/
    ./zkServer.sh stop
    exit
    remotessh
    
    ssh -tt hadoop@192.168.192.13 > /dev/null 2>&1 << remotessh
    cd /home/hadoop/zookeeper/zookeeper-3.4.6/bin/
    ./zkServer.sh stop
    exit
    remotessh
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    注:使用脚本时,请先赋予脚本权限以及注意脚本文件格式

    $ sudo chmod 777 脚本名称.sh
    • 1

    出现: 
    /bin/bash^M: bad interpreter: No such file or dire 
    在执行shell脚本时提示这样的错误主要是由于shell脚本文件是dos格式,即每一行结尾以 来标识,而unix格式的文件行尾则以 来标识。 查看脚本文件是dos格式还是unix格式的几种办法。 
    (1)cat -A filename 从显示结果可以判断,dos格式的文件行尾为^Munix。 
    (2)od -t x1 filename 如果看到输出内容中存在0d 0a的字符,那么文件是dos格式,如果只有0a,则是unix格式。 
    (3)vi filename打开文件,执行 : set ff,如果文件为dos格式在显示为fileformat=dos,如果是unxi则显示为fileformat=unix。 
    解决方法: 
    (1)使用linux命令dos2unix filename,直接把文件转换为unix格式 
    (2)使用sed命令sed -i “s/ //” filename 或者 sed -i “s/^M//” filename直接替换结尾符为unix格式 
    (3)vi filename打开文件,执行 : set ff=unix 设置文件为unix,然后执行:wq,保存成unix格式。

  • 相关阅读:
    [心得]如何快速利用SqlMap做安全檢測
    [心得]群裡提問的流水序號產生方式
    STL中使用reverse_iterator时,如何正确使用erase函数
    西山居面试之旅
    LAMP兄弟连 视频教程集
    [译]理解Windows消息循环
    C++设计模式 -- 解析和实现
    winsock 收发广播包
    SqlServer sysobjects_table
    查询反模式
  • 原文地址:https://www.cnblogs.com/zfzf1/p/6644122.html
Copyright © 2011-2022 走看看