本文介绍zookeeper伪分布式安装。

所谓 “伪分布式集群” 就是在1台PC中启动多个zookeeper的实例。“完全分布式集群” 是每1台PC启动1个ZooKeeper实例。

由于我的测试环境PC数量有限,所以在1台PC中启动3个zookeeper的实例。下面以3个节点为例,介绍安装的过程

新建3个文件夹

[work@xxx zookeeper-3.4.6]$ mkdir zoo_1 zoo_2 zoo_3

复制配置文件

[work@xxx conf]$ cp zoo.cfg zoo1.cfg
[work@xxx conf]$ cp zoo.cfg zoo2.cfg  
[work@xxx conf]$ cp zoo.cfg zoo3.cfg

修改配置文件

3个节点的配置文件分别如下,注意修改路径和端口

介绍一下配置文件里面的字段含义:

1、tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳

2、dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里

3、clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求

4、initLimit:这个配置项是用来配置 Zookeeper 接受客户端(这里所说的客户端不是用户连接 Zookeeper 服务器的客户端,而是 Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 5个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 5 * 2000 = 10 秒

5、syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2 * 2000 = 4 秒

6、server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的 ip 地址;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号

写入myid

[work@xxx zookeeper-3.4.6]$ echo "1" > zoo_1/myid
[work@xxx zookeeper-3.4.6]$ echo "2" > zoo_2/myid   
[work@xxx zookeeper-3.4.6]$ echo "3" > zoo_3/myid

启动

[work@xxx zookeeper-3.4.6]$ bin/zkServer.sh start zoo1.cfg
JMX enabled by default
Using config: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo1.cfg
Starting zookeeper ... STARTED

[work@xxx zookeeper-3.4.6]$ bin/zkServer.sh start zoo2.cfg
JMX enabled by default
Using config: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo2.cfg
Starting zookeeper ... STARTED

[work@xxx zookeeper-3.4.6]$ bin/zkServer.sh start zoo3.cfg
JMX enabled by default
Using config: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo3.cfg
Starting zookeeper ... STARTED

查看状态
[work@xxx zookeeper-3.4.6]$ bin/zkServer.sh status zoo1.cfg   
JMX enabled by default
Using config: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo1.cfg
Mode: follower

[work@xxx zookeeper-3.4.6]$ bin/zkServer.sh status zoo2.cfg
JMX enabled by default
Using config: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo2.cfg
Mode: leader

[work@xxx zookeeper-3.4.6]$ bin/zkServer.sh status zoo3.cfg
JMX enabled by default
Using config: /home/work/soft/zookeeper-3.4.6/bin/../conf/zoo3.cfg
Mode: follower

可以发现zoo_2被选为了leader

查看目录

[work@xxx zookeeper-3.4.6]$ tree zoo_1   
zoo_1
|-- myid
|-- version-2
|   |-- acceptedEpoch
|   |-- currentEpoch
|   `-- snapshot.0
`-- zookeeper_server.pid

1 directory, 5 files

[work@xxx zookeeper-3.4.6]$ tree zoo_2
zoo_2
|-- myid
|-- version-2
|   |-- acceptedEpoch
|   `-- currentEpoch
`-- zookeeper_server.pid

1 directory, 4 files

[work@xxx zookeeper-3.4.6]$ tree zoo_3
zoo_3
|-- myid
|-- version-2
|   |-- acceptedEpoch
|   |-- currentEpoch
|   `-- snapshot.100000000
`-- zookeeper_server.pid

1 directory, 5 files
[work@xxx zookeeper-3.4.6]$

安装成功后,用cli测试一下,一直报下面这个SB错误!

[work@xxx zookeeper-3.4.6]$ bin/zkCli.sh -server 127.0.0.1:2182
Connecting to 127.0.0.1:2182
2018-01-05 21:32:45,482 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2018-01-05 21:32:45,485 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=xxx
2018-01-05 21:32:45,486 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.7.0_111
2018-01-05 21:32:45,488 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2018-01-05 21:32:45,488 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.111.x86_64/jre
2018-01-05 21:32:45,488 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/home/work/soft/zookeeper-3.4.6/bin/../build/classes:/home/work/soft/zookeeper-3.4.6/bin/../build/lib/*.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/home/work/soft/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/home/work/soft/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/home/work/soft/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/home/work/soft/zookeeper-3.4.6/bin/../conf:
2018-01-05 21:32:45,488 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2018-01-05 21:32:45,488 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2018-01-05 21:32:45,488 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2018-01-05 21:32:45,488 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2018-01-05 21:32:45,489 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2018-01-05 21:32:45,489 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0_1-0-0-8
2018-01-05 21:32:45,489 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=work
2018-01-05 21:32:45,489 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/home/work
2018-01-05 21:32:45,489 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/home/work/soft/zookeeper-3.4.6
2018-01-05 21:32:45,490 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2182 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@7a04c4aa
Welcome to ZooKeeper!
2018-01-05 21:32:45,519 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:2182. Will not attempt to authenticate using SASL (unknown error)
2018-01-05 21:32:45,525 [myid:] - WARN  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1102] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:744)
        at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
JLine support is enabled
[zk: 127.0.0.1:2182(CONNECTING) 0] 2018-01-05 21:32:46,629 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:2182. Will not attempt to authenticate using SASL (unknown error)
2018-01-05 21:32:46,630 [myid:] - WARN  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1102] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:744)
        at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)
2018-01-05 21:32:47,731 [myid:] - INFO  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@975] - Opening socket connection to server 127.0.0.1/127.0.0.1:2182. Will not attempt to authenticate using SASL (unknown error)
2018-01-05 21:32:47,731 [myid:] - WARN  [main-SendThread(127.0.0.1:2182):ClientCnxn$SendThread@1102] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused
        at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
        at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:744)
        at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
        at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)

在网上查了很久也没有找到解决方法,但是用cli连接单节点的zookeeper是没有问题的,奇怪!

参考了http://blog.itpub.net/12219480/viewspace-1778740/ 里面的说明,不过没有验证,先贴到下面:

1、zookeeper配置完毕之候报错,信息如下:

  1. grid@master1:~$ zkCli.sh -server 10.10.10.70:2181
  2. ..............................
  3. 2015-08-21 06:29:48,412 [myid:] - INFO [main-SendThread(10.10.10.70:2181):ClientCnxn$SendThread@975] - Opening socket connection to server 10.10.10.70/10.10.10.70:2181. Will not attempt to authenticate using SASL (unknown error)
  4. Welcome to
  5. 2015-08-21 06:29:48,420 [myid:] - WARN [main-SendThread(10.10.10.70:2181):ClientCnxn$SendThread@1102] - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
  6. java.net.ConnectException: Connection refused
  7. at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
  8. at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739)
  9. at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)
  10. at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1081)

这是连接zookeeper的server一直不断的报错
2、查看zookeeper配置信息

  1. grid@master1:/usr/local/zookeeper/conf$ cat zoo.cfg
  2. # The number of milliseconds of each tick
  3. tickTime=2000
  4. # The number of ticks that the initial
  5. # synchronization phase can take
  6. initLimit=10
  7. # The number of ticks that can pass between
  8. # sending a request and getting an acknowledgement
  9. syncLimit=5
  10. # the directory where the snapshot is stored.
  11. # do not use /tmp for storage, /tmp here is just
  12. # example sakes.
  13. dataDir=/data/zk
  14. dataLogDir=/data/zk/logs
  15. # the port at which the clients will connect
  16. clientPort=2181
  17. # the maximum number of client connections.
  18. # increase this if you need to handle more clients
  19. #maxClientCnxns=60
  20. #
  21. # Be sure to read the maintenance section of the
  22. # administrator guide before turning on autopurge.
  23. #
  24. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
  25. #
  26. # The number of snapshots to retain in dataDir
  27. #autopurge.snapRetainCount=3
  28. # Purge task interval in hours
  29. # Set to "0" to disable auto purge feature
  30. #autopurge.purgeInterval=1
  31. server.70=10.10.10.70:2888:3888
  32. server.71=10.10.10.71:2888:3888
  33. server.72=10.10.10.72:2888:3888
  34. server.73=10.10.10.73:2888:3888

2、在每个服务器上更改myid文件,如10.10.10.70文件

之后启动zookeeper,服务正常

本文参考自:

https://www.cnblogs.com/haippy/archive/2012/07/19/2599989.html

http://blog.csdn.net/chengwenyao18/article/details/23611995

https://www.cnblogs.com/driftingshine/p/6649104.html

http://blog.itpub.net/12219480/viewspace-1778740/

zookeeper伪分布式安装的更多相关文章

  1. zookeeper 伪分布式安装

    1 下载zookeeper安装包 下载地址 http://apache.fayea.com/zookeeper/ 我下载的是zookeeper-3.4.6.tar.gz 2 解压缩 将zookeepe ...

  2. Zookeeper 初体验之——伪分布式安装(转)

    原文地址: http://blog.csdn.net/salonzhou/article/details/47401069 简介 Apache Zookeeper 是由 Apache Hadoop 的 ...

  3. (转)ZooKeeper伪分布式集群安装及使用

    转自:http://blog.fens.me/hadoop-zookeeper-intro/ 前言 ZooKeeper是Hadoop家族的一款高性能的分布式协作的产品.在单机中,系统协作大都是进程级的 ...

  4. ZooKeeper:win7上安装单机及伪分布式安装

    zookeeper是一个为分布式应用所设计的分布式的.开源的调度服务,它主要用来解决分布式应用中经常遇到的一些数据管理问题,简化分布式应用,协调及其管理的难度,提高性能的分布式服务. 本章的目的:如何 ...

  5. HBase伪分布式安装(HDFS)+ZooKeeper安装+HBase数据操作+HBase架构体系

    HBase1.2.2伪分布式安装(HDFS)+ZooKeeper-3.4.8安装配置+HBase表和数据操作+HBase的架构体系+单例安装,记录了在Ubuntu下对HBase1.2.2的实践操作,H ...

  6. ZooKeeper伪分布式集群安装及使用

    ZooKeeper伪分布式集群安装及使用 让Hadoop跑在云端系列文章,介绍了如何整合虚拟化和Hadoop,让Hadoop集群跑在VPS虚拟主机上,通过云向用户提供存储和计算的服务. 现在硬件越来越 ...

  7. HBase基础和伪分布式安装配置

    一.HBase(NoSQL)的数据模型 1.1 表(table),是存储管理数据的. 1.2 行键(row key),类似于MySQL中的主键,行键是HBase表天然自带的,创建表时不需要指定 1.3 ...

  8. Hadoop大数据初入门----haddop伪分布式安装

    一.hadoop解决了什么问题 hdfs 解决了海量数据的分布式存储,高可靠,易扩展,高吞吐量mapreduce 解决了海量数据的分析处理,通用性强,易开发,健壮性 yarn 解决了资源管理调度 二. ...

  9. Hadoop生态圈-hbase介绍-伪分布式安装

    Hadoop生态圈-hbase介绍-伪分布式安装 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.HBase简介 HBase是一个分布式的,持久的,强一致性的存储系统,具有近似最 ...

随机推荐

  1. Boost::Lexical_cast 的使用

    .C++代码 #include <boost/lexical_cast.hpp> #include <iostream> int main() { using boost::l ...

  2. 用latex写毕业论文

    用 LaTeX 写漂亮学位论文(from wloo) 序 一直觉得有必要写这样一篇文章,因为学位论文从格式上说更像一本书,与文章 的排版不同,不仅多出目录等文章没有的部分,而且一般要设置页眉页脚方便阅 ...

  3. 创建maven web项目无法创建sec目录

    创建maven web项目无法创建sec目录 解决方法:-DarchetypeCatalog=internal

  4. Chrome 控制台新玩法-向输出到console的文字加样式

    Chrome 控制台新玩法-向输出到console的文字加样式 有兴趣的同学可以文章最后的代码复制贴到控制台玩玩. Go for Code 在正常模式下,一般只能向console 控制台输出简单的文字 ...

  5. 在ios程序中自己主动滚动TableView到某行的方法

    比方tableview窗体能够显示 30 行, 我想在填充tableview 100 条数据后 选择第 50行, 能把这一行显示到窗体内, 就像手动拖滚动栏到 第 50行一样,要怎样实现呢? ] an ...

  6. c/c++在windows下获取时间和计算时间差的几种方法总结 【转】

    http://blog.csdn.net/coder_xia/article/details/6566708 一.标准C和C++都可用 1.获取时间用time_t time( time_t * tim ...

  7. Vuex内容解析和vue cli项目中使用状态管理模式Vuex

    中文文档:vuex官方中文网站 一.vuex里面都有些什么内容? const store = new Vuex.Store({ state: { name: 'weish', age: }, gett ...

  8. LeetCode56:Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  9. Android技术——在Android中的随意视图中找控件

    1.在非常多情况下,我们可能不知道控件的id,可是我们却希望在包括这个控件的视图中找到它,能够採用例如以下做法: 例:在Activity的根视图中找出当中全部的Button控件 private voi ...

  10. git使用 ——转

    转自:http://blog.csdn.net/jamesmf/article/details/17483787