zookeeper是一个为分布式应用所设计的分布式的、开源的调度服务,它主要用来解决分布式应用中经常遇到的一些数据管理问题,简化分布式应用,协调及其管理的难度,提高性能的分布式服务。
本章的目的:如何安装zookeeper(在win7环境下),zookeeper下载https://mirrors.cnnic.cn/apache/zookeeper/。这里下载的版本是3.4.8.
zoomkeeper本身是可以单节点模式安装运行,不过一般为了确保zookeeper的稳定性和可用性,都会采用分布式部署,也进而保证了分布式应用的可靠性。它在分布式zookepper集群中,会基于选举算法来实现一个leader,多个follower。
参考文章:http://blog.csdn.net/lovesummerforever/article/details/48975703
单节点安装:
1)下载zookeeper-3.4.8.tar.gz,并解压到目录:D:\Work\zookeeper\zookeeper-3.4.8下
2)进入conf目录下把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.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=D:\\Work\\zookeeper\\data
# log config
dataLogDir=D:\\Work\\zookeeper\\log
# 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
3)启动zookeeper服务:
进入目录:D:\Work\zookeeper\zookeeper-3.4.8\bin,执行zkServer.cmd,这样就启动了zookeeper服务了。
--启动打印信息
D:\Work\zookeeper\zookeeper-3.4.8\bin>zkServer.cmd D:\Work\zookeeper\zookeeper-3.4.8\bin>call "D:\Program Files\Java\jdk1.8.0_111"\bin\java "-Dzookeeper.log.dir=D:\Work\zookeeper\zookeeper-3.4.8\bin\.." "-Dzookeeper.root.logger=INFO,CONSOLE" -cp "D:\Work\zookeeper\zookeeper-3.4.8\bin\..\build\classes;D:\Work\zookeeper\zookeeper-3.4.8\bin\..\build\lib\*;D:\Work\zookeeper\zookeeper-3.4.8\bin\..\*;D:\Work\zookeeper\zookeeper-3.4.8\bin\..\lib\*;D:\Work\zookeeper\zookeeper-3.4.8\bin\..\conf" org.apache.zookeeper.server.quorum.QuorumPeerMain "D:\Work\zookeeper\zookeeper-3.4.8\bin\..\conf\zoo.cfg"
2017-09-09 21:02:58,180 [myid:] - INFO [main:QuorumPeerConfig@103] - Reading configuration from: D:\Work\zookeeper\zookeeper-3.4.8\bin\..\conf\zoo.cfg
2017-09-09 21:02:58,204 [myid:] - INFO [main:DatadirCleanupManager@78] - autopurge.snapRetainCount set to 3
2017-09-09 21:02:58,205 [myid:] - INFO [main:DatadirCleanupManager@79] - autopurge.purgeInterval set to 0
2017-09-09 21:02:58,205 [myid:] - INFO [main:DatadirCleanupManager@101] - Purge task is not scheduled.
2017-09-09 21:02:58,211 [myid:] - WARN [main:QuorumPeerMain@113] - Either no config or no quorum defined in config, running in standalone mode
2017-09-09 21:02:58,445 [myid:] - INFO [main:QuorumPeerConfig@103] - Reading configuration from: D:\Work\zookeeper\zookeeper-3.4.8\bin\..\conf\zoo.cfg
2017-09-09 21:02:58,446 [myid:] - INFO [main:ZooKeeperServerMain@95] - Starting server
2017-09-09 21:02:58,769 [myid:] - INFO [main:Environment@100] - Server environment:zookeeper.version=3.4.8--1, built on 02/06/2016 03:18 GMT
2017-09-09 21:02:58,772 [myid:] - INFO [main:Environment@100] - Server environment:host.name=192.168.233.1
2017-09-09 21:02:58,777 [myid:] - INFO [main:Environment@100] - Server environment:java.version=1.8.0_111
2017-09-09 21:02:58,778 [myid:] - INFO [main:Environment@100] - Server environment:java.vendor=Oracle Corporation
2017-09-09 21:02:58,780 [myid:] - INFO [main:Environment@100] - Server environment:java.home=D:\Program Files\Java\jdk1.8.0_111\jre
2017-09-09 21:02:58,782 [myid:] - INFO [main:Environment@100] - Server environment:java.class.path=D:\Work\zookeeper\zookeeper-3.4.8\bin\..\build\classes;D:\Work\zookeeper\zookeeper-3.4.8\bin\..\build\lib\*;D:\Work\zookeeper\zookeeper-3.4.8\bin\..\zookeeper-3.4.8.jar;D:\Work\zookeeper\zookeeper-3.4.8\bin\..\lib\jline-0.9.94.jar;D:\Work\zookeeper\zookeeper-3.4.8\bin\..\lib\log4j-1.2.16.jar;。。。2017-09-09 21:02:58,784 [myid:] - INFO [main:Environment@100] - Server environment:java.library.path=D:\Program Files\Java\jdk1.8.0_111\bin;D:\Program Files\Java\jdk1.8.0_111\bin;D:\Program Files\Java\jdk1.8.0_111\jre\bin;
.
2017-09-09 21:02:58,789 [myid:] - INFO [main:Environment@100] - Server environment:java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\
2017-09-09 21:02:58,791 [myid:] - INFO [main:Environment@100] - Server environment:java.compiler=<NA>
2017-09-09 21:02:58,800 [myid:] - INFO [main:Environment@100] - Server environment:os.name=Windows 7
2017-09-09 21:02:58,801 [myid:] - INFO [main:Environment@100] - Server environment:os.arch=amd64
2017-09-09 21:02:58,804 [myid:] - INFO [main:Environment@100] - Server environment:os.version=6.1
2017-09-09 21:02:58,811 [myid:] - INFO [main:Environment@100] - Server environment:user.name=Administrator
2017-09-09 21:02:58,813 [myid:] - INFO [main:Environment@100] - Server environment:user.home=C:\Users\Administrator
2017-09-09 21:02:58,816 [myid:] - INFO [main:Environment@100] - Server environment:user.dir=D:\Work\zookeeper\zookeeper-3.4.8\bin
2017-09-09 21:02:58,849 [myid:] - INFO [main:ZooKeeperServer@787] - tickTime set to 2000
2017-09-09 21:02:58,851 [myid:] - INFO [main:ZooKeeperServer@796] - minSessionTimeout set to -1
2017-09-09 21:02:58,852 [myid:] - INFO [main:ZooKeeperServer@805] - maxSessionTimeout set to -1
2017-09-09 21:03:00,548 [myid:] - INFO [main:NIOServerCnxnFactory@89] - binding to port 0.0.0.0/0.0.0.0:2181 --当客户端启动后,就立即打印出来以下信息:
2017-09-09 21:05:23,463 [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:NIOServerCnxnFactory@192] - Accepted socket connection from /127.0.0.1:33988
2017-09-09 21:05:23,483 [myid:] - INFO [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2181:ZooKeeperServer@900] - Client attempting to establish new session at /127.0.0.1:33988
2017-09-09 21:05:23,496 [myid:] - INFO [SyncThread:0:FileTxnLog@199] - Creating new log file: log.1
2017-09-09 21:05:23,542 [myid:] - INFO [SyncThread:0:ZooKeeperServer@645] - Established session 0x15e66bc75ec0000 with negotiated timeout 30000 for client /127.0.0.1:33988
4)启动客户端
进入目录:D:\Work\zookeeper\zookeeper-3.4.8\bin,执行zkCli.cmd -server 127.0.0.1:2181,这样就启动了zookeeper服务了。
D:\Work\zookeeper\zookeeper-3.4.8\bin>zkCli.cmd -server 127.0.0.1:2181
Connecting to 127.0.0.1:2181
2017-09-09 21:05:21,934 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.8--1, built on 02/06/2016 03:18 GMT
2017-09-09 21:05:21,942 [myid:] - INFO [main:Environment@100] - Client environment:host.name=192.168.233.1
2017-09-09 21:05:21,943 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_111
2017-09-09 21:05:21,947 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2017-09-09 21:05:21,948 [myid:] - INFO [main:Environment@100] - Client environment:java.home=D:\Program Files\Java\jdk1.8.0_111\jre
2017-09-09 21:05:21,949 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=D:\Work\zookeeper\zookeeper-3.4.8\bin\..\build\classes;D:\Work\zookeeper\zookeeper-3.4.8\bin\..。。。。;
.
2017-09-09 21:05:21,960 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp\
2017-09-09 21:05:21,963 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2017-09-09 21:05:21,965 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Windows 7
2017-09-09 21:05:21,967 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2017-09-09 21:05:21,969 [myid:] - INFO [main:Environment@100] - Client environment:os.version=6.1
2017-09-09 21:05:21,973 [myid:] - INFO [main:Environment@100] - Client environment:user.name=Administrator
2017-09-09 21:05:21,975 [myid:] - INFO [main:Environment@100] - Client environment:user.home=C:\Users\Administrator
2017-09-09 21:05:21,977 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=D:\Work\zookeeper\zookeeper-3.4.8\bin
2017-09-09 21:05:21,983 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=127.0.0.1:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@7aec35a
Welcome to ZooKeeper!
2017-09-09 21:05:23,459 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server 127.0.0.1/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
2017-09-09 21:05:23,464 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@876] - Socket connection established to 127.0.0.1/127.0.0.1:2181, initiating session
JLine support is enabled
[zk: 127.0.0.1:2181(CONNECTING) 0] 2017-09-09 21:05:23,548 [myid:] - INFO [main-SendThread(127.0.0.1:2181):ClientCnxn$SendThread@1299] - Session establishmentcomplete on server 127.0.0.1/127.0.0.1:2181, sessionid = 0x15e66bc75ec0000, negotiated timeout = 30000 WATCHER:: WatchedEvent state:SyncConnected type:None path:null
这样就安装完成了单节点zookeeper服务。
伪分布式安装:
伪分布式安装就是在同一台pc上安装,安装时使用同一个zookeeper包,多个配置文件分别配置为不同的端口。
1)将D:\Work\zookeeper\zookeeper-3.4.8\conf\下的zoo.cfg分别复制出文件zoo1.cfg,zoo2.cfg,zoo3.cfg三个文件,分别修改配置为:
zoo1.cfg
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=D:\\Work\\zookeeper\\data\\1
# log config
dataLogDir=D:\\Work\\zookeeper\\log\\1
# the port at which the clients will connect
clientPort=2181 server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889
zoo2.cfg
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=D:\\Work\\zookeeper\\data\\2
# log config
dataLogDir=D:\\Work\\zookeeper\\log\\2
# the port at which the clients will connect
clientPort=2182 server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889
zoo3.cfg
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=D:\\Work\\zookeeper\\data\\3
# log config
dataLogDir=D:\\Work\\zookeeper\\log\\3
# the port at which the clients will connect
clientPort=2183 server.1=localhost:2887:3887
server.2=localhost:2888:3888
server.3=localhost:2889:3889
备注:
假设把配置文件表示为:zoo{num}.cfg, server.{num}=ip/domain:Port1:Port2
其中num:表示数字表示第几号服务器;ip/domain :是服务器域名或者ip地址。
Port1:表示这个服务器和集群中的Leader服务器交换信息的端口;
Port2:表示万一集群中的Leader服务器挂了,需要一个端口重新进行选举,选出一个新的Leader,这个端口就是用来执行选举时服务器相互通信的端口。
由于我们是伪集群,所以ip或者域名是一样的,所以要分配不同的端口号
2)创建目录D:\Work\zookeeper\data\1,D:\Work\zookeeper\data\2,D:\Work\zookeeper\data\3
分别在三个文件下创建myid文件,文件内容依次为:1,2,3
3)进入D:\Work\zookeeper\zookeeper-3.4.8\bin下复制文件zkServer.cmd为zkServer-1.cmd,zkServer-2.cmd,zkServer-3.cmd
zkServer-1.cmd内容修改为如下:
setlocal
call "%~dp0zkEnv.cmd" set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain
set ZOOCFG=D:\\Work\\zookeeper\\zookeeper-3.4.8\\conf\\zoo1.cfg echo on
call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %* endlocal
zkServer-2.cmd内容修改为如下:
setlocal
call "%~dp0zkEnv.cmd" set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain
set ZOOCFG=D:\\Work\\zookeeper\\zookeeper-3.4.8\\conf\\zoo2.cfg echo on
call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %* endlocal
zkServer-3.cmd内容修改为如下:
setlocal
call "%~dp0zkEnv.cmd" set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain
set ZOOCFG=D:\\Work\\zookeeper\\zookeeper-3.4.8\\conf\\zoo3.cfg echo on
call %JAVA% "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %* endlocal
4)分别启动zkServer-1.cmd,zkServer-2.cmd,zkServer-3.cmd
进入目录:D:\Work\zookeeper\zookeeper-3.4.8\bin,分布执行zkServer-1.cmd,zkServer-2.cmd,zkServer-3.cmd,启动伪分布式zookeeper集群,启动过程中如果前两个启动的服务户出现异常情况为正常,直到3个zkServer-x.cmd都启动完后就不会出现异常情况。
ZooKeeper:win7上安装单机及伪分布式安装的更多相关文章
-
Hadoop单机和伪分布式安装
本教程为单机版+伪分布式的Hadoop,安装过程写的有些简单,只作为笔记方便自己研究Hadoop用. 环境 操作系统 Centos 6.5_64bit 本机名称 hadoop001 本机IP ...
-
Linux系统zookeeper环境搭建(单机、伪分布式、分布式)
本人现在对zookeeper的环境搭建做一个总结,一般zookeeper的安装部署可以有三种模式,单机模式.伪分布式和分布式,这三种模式在什么时候应用具体看大家的使用场景,如果你只有一台机器且只是想自 ...
-
hadoop2.7.2单机与伪分布式安装
环境相关 系统:CentOS 6.8 64位 jdk:1.7.0_79 hadoop:hadoop 2.7.2 安装java环境 详见:linux中搭建java开发环境 创建hadoop用户 # 以r ...
-
HBase伪分布式安装(HDFS)+ZooKeeper安装+HBase数据操作+HBase架构体系
HBase1.2.2伪分布式安装(HDFS)+ZooKeeper-3.4.8安装配置+HBase表和数据操作+HBase的架构体系+单例安装,记录了在Ubuntu下对HBase1.2.2的实践操作,H ...
-
Zookeeper 初体验之——伪分布式安装(转)
原文地址: http://blog.csdn.net/salonzhou/article/details/47401069 简介 Apache Zookeeper 是由 Apache Hadoop 的 ...
-
zookeeper伪分布式安装
本文介绍zookeeper伪分布式安装. 所谓 “伪分布式集群” 就是在1台PC中启动多个zookeeper的实例.“完全分布式集群” 是每1台PC启动1个ZooKeeper实例. 由于我的测试环境P ...
-
在Hadoop2.2基础上安装Spark(伪分布式)
没想到,在我的hadoop2.2.0小集群上上安装传说中的Spark竟然如此顺利,可能是因为和搭建Hadoop时比较像,更多需要学习的地方还是scala编程和RDD机制吧 总之,开个好头 原来的集群: ...
-
第二章 伪分布式安装hadoop hbase
安装单机模式的hadoop无须配置,在这种方式下,hadoop被认为是一个单独的java进程,这种方式经常用来调试.所以我们讲下伪分布式安装hadoop. 我们继续上一章继续讲解,安装完先试试SSH装 ...
-
HBase基础和伪分布式安装配置
一.HBase(NoSQL)的数据模型 1.1 表(table),是存储管理数据的. 1.2 行键(row key),类似于MySQL中的主键,行键是HBase表天然自带的,创建表时不需要指定 1.3 ...
随机推荐
-
Spring用代码来读取properties文件
我们都知道,Spring可以@Value的方式读取properties中的值,只需要在配置文件中配置org.springframework.beans.factory.config.PropertyP ...
-
delete archivelog all 无法彻底删除归档日志?
最近在因归档日志暴增,使用delete archivelog all貌似无法清除所有的归档日志,到底是什么原因呢? 1.演示环境 SQL> select * from v$version whe ...
-
poj 1050 To the Max_dp求最大子矩阵和
题意:求最大子矩阵和 利用dp[i]每次向下更新,构成竖起的单条矩阵,再按不小于零就加起来来更新,构成更大的矩阵 #include <iostream> #include<cstdi ...
-
[Git]02 如何简单使用
本章将介绍几个最基本的,也是最常用的 Git命令,以后绝大多数时间里用到的也就是这几个命令. 初始化一个新的代码仓库,做一些适当配置:开始或停止跟踪某些文件:暂存或提交某些更新.我们还会展示如何 ...
-
Python--day14(迭代器)
今日主要内容 1. 带参装饰器 (了了解) 2. 迭代器(*****) 可迭代对象 迭代器对象 for迭代器 枚举对象 1. 带参装饰器 1. 通常,装饰器为被装饰的函数添加新功能,需要外界的 ...
-
如何解决代码中if…else 过多的问题
前言 if...else 是所有高级编程语言都有的必备功能.但现实中的代码往往存在着过多的 if...else.虽然 if...else 是必须的,但滥用 if...else 会对代码的可读性.可维护 ...
-
IO测试工具之fio详解
目前主流的第三方IO测试工具有fio.iometer和Orion,这三种工具各有千秋. fio在Linux系统下使用比较方便,iometer在window系统下使用比较方便,Orion是oracle的 ...
-
Unity 3D光源-Point Light点光源详解/灯泡、模拟灯光效果教程
Unity4大光源之点光源 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享. ...
-
leetCode题解 Student Attendance Record I
1.题目描述 You are given a string representing an attendance record for a student. The record only conta ...
-
非常全的linux面试笔试题及答案
一.填空题:1. 在Linux系统中,以 文件 方式访问设备 .2. Linux内核引导时,从文件/etc/fstab 中读取要加载的文件系统.3. Linux文件系统中每个文件用 i节点来标识.4. ...