`
gaojingsong
  • 浏览: 1181894 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

【分布式系统之zookeeper安装】

阅读更多

ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等。
设计目的
1.最终一致性:client不论连接到哪个Server,展示给它都是同一个视图,这是zookeeper最重要的性能。
2 .可靠性:具有简单、健壮、良好的性能,如果消息m被到一台服务器接受,那么它将被所有的服务器接受。
3 .实时性:Zookeeper保证客户端将在一个时间间隔范围内获得服务器的更新信息,或者服务器失效的信息。但由于网络延时等原因,Zookeeper不能保证两个客户端能同时得到刚更新的数据,如果需要最新数据,应该在读数据之前调用sync()接口。
4 .等待无关(wait-free):慢的或者失效的client不得干预快速的client的请求,使得每个client都能有效的等待。
5.原子性:更新只能成功或者失败,没有中间状态。
6 .顺序性:包括全局有序和偏序两种:全局有序是指如果在一台服务器上消息a在消息b前发布,则在所有Server上消息a都将在消息b前被发布;偏序是指如果一个消息b在消息a后被同一个发送者发布,a必将排在b前面。

ZK安装分为单机安装、伪分布安装和分布式安装

 

一、单机安装

[root@node1 bin]# wget http://apache.opencas.org/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
[root@node1 zk]# ls
zookeeper-3.4.6.tar.gz
[root@node1 zk]# tar -zxvf zookeeper-3.4.6.tar.gz
[root@node1 zk]# ls
zookeeper-3.4.6  zookeeper-3.4.6.tar.gz
[root@node1 zk]# mv zookeeper-3.4.6 zookeeper
[root@node1 zk]# cd zookeeper
[root@node1 zookeeper]# ls
bin        CHANGES.txt  contrib     docs             ivy.xml  LICENSE.txt  README_packaging.txt  recipes  zookeeper-3.4.6.jar      zookeeper-3.4.6.jar.md5
build.xml  conf         dist-maven  ivysettings.xml  lib      NOTICE.txt   README.txt            src      zookeeper-3.4.6.jar.asc  zookeeper-3.4.6.jar.sha1
[root@node1 zookeeper]# cd conf/
[root@node1 conf]# ls
configuration.xsl  log4j.properties  zoo_sample.cfg
[root@node1 conf]# cp zoo_sample.cfg  zoo.cfg
[root@node1 conf]# cat 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=/tmp/zookeeper
# 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

[root@node1 conf]# java -version
java version "1.7.0_45"
OpenJDK Runtime Environment (rhel-2.4.3.3.el6-i386 u45-b15)
OpenJDK Client VM (build 24.45-b08, mixed mode, sharing)
[root@node1 conf]# cd ../
[root@node1 zookeeper]# cd bin/
[root@node1 bin]# ls
README.txt  zkCleanup.sh  zkCli.cmd  zkCli.sh  zkEnv.cmd  zkEnv.sh  zkServer.cmd  zkServer.sh
[root@node1 bin]# ./zkServer.sh
JMX enabled by default
Using config: /opt/zk/zookeeper/bin/../conf/zoo.cfg
Usage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
[root@node1 bin]# ./zkServer.sh  start
JMX enabled by default
Using config: /opt/zk/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@node1 bin]# jps
4341 Jps
4325 QuorumPeerMain



二、伪分布式安装

安装技巧:注意修改clientPort端口号,建议依次改为2181、2182、2183,写入myId文件,必须和Server.X里面的序号对应


server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890

[root@node1 conf]# vi 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=../zkdata
# 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

server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890
~
"zoo.cfg" 33L, 1007C written
[root@node1 conf]# cd ../
[root@node1 zookeeper]# mkdir zkdata
[root@node1 zookeeper]# cd ../
[root@node1 zk]# clear
[root@node1 zk]# ls
zookeeper  zookeeper-3.4.6.tar.gz
[root@node1 zk]# cp -R zookeeper zookeeper2
[root@node1 zk]# cp -R zookeeper zookeeper3
[root@node1 zk]# jps
4372 Jps
4325 QuorumPeerMain
[root@node1 zk]# kill -9 4325
[root@node1 zk]# jps
4381 Jps

[root@node1 zk]# echo 1 > zookeeper/zkdata/myid
[root@node1 zk]# echo 2 > zookeeper2/zkdata/myid
[root@node1 zk]# echo 3 > zookeeper3/zkdata/myid


[root@node1 zk]# echo 2 > zookeeper2/zkdata/myid
[root@node1 zk]# cat  zookeeper3/zkdata/myid
3
[root@node1 zk]# cat  zookeeper2/zkdata/myid
2
[root@node1 zk]# cat  zookeeper/zkdata/myid
1
[root@node1 zk]#

 

 

启动验证
/opt/zk/zookeeper/bin/zkServer.sh start-foreground
/opt/zk/hadoop/zookeeper2/bin/zkServer.sh start-foreground
/opt/zk/hadoop/zookeeper3/bin/zkServer.sh start-foreground
启用成功后,输入 jps 看下进程

 

 

三、分布式安装

修改单机安装的zoo.cfg文件,如下图所示,因为是分布式安装,所以下图表红色部分,只需要修改对应的IP地址即可[root@node1 conf]# vi 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=../zkdata
# 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

server.1=192.168.1.1:2888:3888
server.2=192.168.1.2:2888:3888
server.3=192.168.1.3:2888:3888
~

步骤二、通过Scp命令分发文件到其余两台机器上面

 

步骤三、修改各自的myid文件,必须和zoo.cfg里面配置的server.1=192.168.1.1数字和IP对应起来

[root@node1 zk]# echo 1 > zookeeper/zkdata/myid

 

步骤四、启动验证/opt/zk/zookeeper/bin/zkServer.sh start-foreground

  • 大小: 14.3 KB
0
4
分享到:
评论

相关推荐

    分布式同步系统Zookeeper的优化.pdf

    本文档《分布式同步系统Zookeeper的优化》主要讨论了针对Zookeeper在大规模计算机集群上运行效率低下的问题,并提出了一种基于成员节点选举的自动设定响应节点算法来进行优化。 Zookeeper系统在云计算和分布式计算...

    分布式系统协调 ZooKeeper.rar

    分布式系统协调ZooKeeper是Apache软件基金会的一个开源项目,它主要设计用于构建高可用和高性能的分布式应用。在深入理解ZooKeeper之前,我们需要先理解分布式系统的基本概念。分布式系统是由多台计算机通过网络互相...

    java分布式系统服务ZooKeeper的学习历程.rar

    分布式系统服务ZooKeeper的学习历程

    分布式系统服务ZooKeeper的学习历程

    分布式系统服务ZooKeeper的学习历程.。。。。。。。。。

    zookeeper, 分布式系统服务ZooKeeper的学习历程.zip

    《分布式系统服务ZooKeeper深度探索》 ZooKeeper,作为一个开源的分布式协调服务,源自雅虎研究院,现已成为Apache基金会的重要项目。它为分布式应用提供了一种高效、可靠的命名服务、配置管理、集群同步、领导者...

    分布式服务框架 Zookeeper -- 管理分布式环境中的数据

    Zookeeper的设计目标是简化分布式系统中的协调任务,使得开发者能够更专注于业务逻辑。 Zookeeper的核心概念包括节点(ZNode)、会话(Session)和观察者模式(Watcher)。ZNode是Zookeeper中的基本数据单元,类似...

    zookeeper伪分布式搭建(1)1

    Zookeeper 是一个分布式的,开放源码的分布式应用程序协调服务,它是集群的管理者,监视着集群中各个节点的状态根据节点提交的反馈进行下一步合理操作。最终将简单易用的接口和性能高效、功能稳定的系统提供给用户。...

    微服务分布式系统架构之zookeeper与dubbo.pdf

    微服务分布式系统架构是当前软件开发领域的热点技术之一,它允许开发人员将一个大的应用系统划分为若干个小的、独立的服务。ZooKeeper和Dubbo是微服务架构中的两个关键技术组件,它们在服务管理和服务调用方面发挥着...

    04分布式协调服务器Zookeeper.pdf

    Zookeeper提供了一种集中式的、高性能的服务,它以基于Paxos算法的ZAB(Zookeeper Atomic Broadcast)协议为核心,确保了在分布式系统中的强一致性。 Zookeeper的主要功能包括配置管理、域名服务、分布式同步和集群...

    分布式服务框架zookeeper 3.4.13版本

    1. **命名服务**:Zookeeper可以作为一个全局的名字注册中心,使得分布式系统中的服务可以通过名字来查找和访问,避免了硬编码IP地址或域名导致的维护困难。 2. **配置管理**:在分布式系统中,配置管理是一个挑战...

    分布式系统协调之ZooKeeper面试准备指南

    ### 分布式系统协调之ZooKeeper面试准备指南 #### ZooKeeper是什么? ZooKeeper是一个分布式协调服务,它主要用于简化复杂分布式系统中的开发任务。它提供了高性能和稳定性的基础架构,帮助开发者解决分布式环境中...

    分布式服务框架 Zookeeper — 管理分布式环境中的数据.doc

    Zookeeper 是一个高度可靠的分布式服务框架,由 Apache Hadoop 项目开发,旨在解决大型分布式系统中的数据管理问题。它的核心功能包括配置管理、命名服务、分布式同步和组服务,为分布式应用提供了强一致性、高可用...

    开课吧-04分布式协调服务器Zookeeper.pdf

    分布式协调服务器Zookeeper是Apache的一款开源项目,设计用于构建分布式协调服务,它为分布式系统提供了一致性保障。Zookeeper的出现源于雅虎研究院的研究,后来成为Apache软件基金会的顶级项目。Zookeeper的核心...

    微服务分布式系统架构之zookeeper与dubbo1

    【微服务分布式系统架构之zookeeper与dubbo1】课程主要涵盖了微服务架构中的关键组件Zookeeper和Dubbo,以及相关的分布式系统基础知识。本课程旨在帮助开发者理解和掌握微服务架构的核心概念,通过实际操作和案例...

    分布式工程配置zookeeper化zkconfigutil.zip

    分布式系统配置项zookeeper化,可实现动态更新,极大方便系统的配置管理,彻底摆脱配置文件,使用annotation实现,easy play! 这是一个非常好用的使用zookeeper配置(分布式)工程的组件,使用java注解实现,想...

    基于ZooKeeper的一种分布式系统架构设计与实现.pdf

    本文介绍了一种基于ZooKeeper的分布式系统架构设计与实现,展示了如何通过分布式服务模型和异步通信来实现服务注册、服务监管、服务加载、通信服务等关键功能,并通过实际项目对所设计架构进行测试验证,证明了该...

    基于zookeeper的分布式锁简单实现

    分布式锁是一种在分布式系统中实现同步的技术,它允许多个节点在同一时刻访问共享资源。在大型分布式环境中,由于网络延迟和并发操作,简单的本地锁可能无法有效解决数据一致性问题。这时,Zookeeper,一个高可用的...

    大厂学苑-01分布式协调服务器Zookeeper1

    Zookeeper的主要功能是为分布式系统提供一致性服务,它扮演着协调者角色,帮助处理分布式环境中的配置管理、域名服务、分布式同步以及集群管理等问题。Zookeeper的一致性是通过基于Paxos算法的ZAB(Zookeeper Atomic...

Global site tag (gtag.js) - Google Analytics