特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过。如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/mao2080/

原理

ZooKeeper是以Fast Paxos算法为基础的,Paxos 算法存在活锁的问题,即当有多个proposer交错提交时,有可能互相排斥导致没有一个proposer能提交成功,而Fast Paxos作了一些优化,通过选举产生一个leader (领导者),只有leader才能提交proposer,具体算法可见Fast Paxos。因此,要想弄懂ZooKeeper首先得对Fast Paxos有所了解。
ZooKeeper的基本运转流程:
1、选举Leader。
2、同步数据。
3、选举Leader过程中算法有很多,但要达到的选举标准是一致的。
4、Leader要具有最高的执行ID,类似root权限。
5、集群中大多数的机器得到响应并follow选出的Leader。

本文将zookeeper在同一台服务器上做一个伪集群部署(实际生产环境不会这样部署),zookeeper有个特性就是节点一般是部署单数(3,5,7,9。。。)具体访问量来权衡,节点down掉一半才算zookeeper服务down掉。

1、下载地址

http://apache.fayea.com/zookeeper/

2、解压安装

1、使用cd命令进入/usr/local/application/zookeeper目录,并上传下载好的zookeeper-3.4.6.tar.gz至安装目录,分别解压移动至zookeeper2181、zookeeper2182、zookeeper2183。

tar -zxvf zookeeper-3.4.6.tar.gz
mv zookeeper-3.4.6 zookeeper2181 tar -zxvf zookeeper-3.4.6.tar.gz
mv zookeeper-3.4.6 zookeeper2182 tar -zxvf zookeeper-3.4.6.tar.gz
mv zookeeper-3.4.6 zookeeper2183 rm -rf zookeeper-3.4.6.tar.gz

3、修改配置

1、修改zookeeper2181/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=/usr/local/application/zookeeper/zookeeper2181/data
  dataLogDir=/usr/local/application/zookeeper/zookeeper2181/logs

# the port at which the clients will connect
clientPort=
# 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.11:4000:5000
server.2=192.168.1.11:4000:5000
server.3=192.168.1.11:4000:5000

2、修改zookeeper2182/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=/usr/local/application/zookeeper/zookeeper2182/data
dataLogDir=/usr/local/application/zookeeper/zookeeper2182/logs
# the port at which the clients will connect
clientPort=
# 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.11:4000:5000
server.2=192.168.1.11:4000:5000
server.3=192.168.1.11:4000:5000

3、修改zookeeper2183/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=/usr/local/application/zookeeper/zookeeper2181/data
 dataLogDir=/usr/local/application/zookeeper/zookeeper2181/logs

# the port at which the clients will connect
clientPort=
# 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.11:4000:5000
server.2=192.168.1.11:4000:5000
server.3=192.168.1.11:4000:5000

4、修改zookeeper2181配置,依次执行下面命令

cd zookeeper2181
mkdir data logs
cd data
vi myid(首先输入字母i进入编辑模式,修改myid内容,这个与zoo.cfg文件里的server.对应(具体服务器是多少就输入多少))

5、修改zookeeper2182配置,依次执行下面命令

cd zookeeper2182
mkdir data logs
cd data
vi myid(首先输入字母i进入编辑模式,修改myid内容,这个与zoo.cfg文件里的server.对应(具体服务器是多少就输入多少))

6、修改zookeeper2183配置,依次执行下面命令

cd zookeeper2183
mkdir data logs
cd data
vi myid(首先输入字母i进入编辑模式,修改myid内容,这个与zoo.cfg文件里的server.对应(具体服务器是多少就输入多少))

4、启动服务

1、启动zookeeper2181服务,进入bin目录,输入命令:./zkServer.sh start

[root@localhost zookeeper2181]# cd bin
[root@localhost bin]# ./zkServer.sh start
JMX enabled by default
Using config: /usr/local/application/zookeeper/zookeeper2181/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost bin]#

2、启动zookeeper2182服务,进入bin目录,输入命令:./zkServer.sh start

[root@localhost zookeeper2182]# cd bin
[root@localhost bin]# ./zkServer.sh start
JMX enabled by default
Using config: /usr/local/application/zookeeper/zookeeper2182/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost bin]#

3、启动zookeeper2183服务,进入bin目录,输入命令:./zkServer.sh start

[root@localhost zookeeper2183]# cd bin
[root@localhost bin]# ./zkServer.sh start
JMX enabled by default
Using config: /usr/local/application/zookeeper/zookeeper2183/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost bin]#

4、查看服务,进入bin目录使用命令:./zkServer.sh status,发现自动选举了leader。

[root@localhost bin]# ./zkServer.sh status
JMX enabled by default
Using config: /usr/local/application/zookeeper/zookeeper2183/bin/../conf/zoo.cfg
Mode: leader
[root@localhost bin]# cd /usr/local/application/zookeeper/zookeeper2181/bin
[root@localhost bin]# ./zkServer.sh status
JMX enabled by default
Using config: /usr/local/application/zookeeper/zookeeper2181/bin/../conf/zoo.cfg
Mode: follower
[root@localhost bin]# cd /usr/local/application/zookeeper/zookeeper2182/bin
[root@localhost bin]# ./zkServer.sh status
JMX enabled by default
Using config: /usr/local/application/zookeeper/zookeeper2182/bin/../conf/zoo.cfg
Mode: follower

5、常用命令

启动服务:./zkServer.sh start (需要进入bin目录)

停止服务:./zkServer.sh stop (需要进入bin目录)

重启服务:./zkServer.sh restart (需要进入bin目录)

查看状态:./zkServer.sh status (需要进入bin目录)

Zookeeper集群及配置的更多相关文章

  1. [推荐]Hadoop+HBase+Zookeeper集群的配置

    [推荐]Hadoop+HBase+Zookeeper集群的配置 Hadoop+HBase+Zookeeper集群的配置  http://wenku.baidu.com/view/991258e881c ...

  2. 原创:centos7.1下 ZooKeeper 集群安装配置+Python实战范例

    centos7.1下 ZooKeeper 集群安装配置+Python实战范例 下载:http://apache.fayea.com/zookeeper/zookeeper-3.4.9/zookeepe ...

  3. hbase和ZooKeeper集群安装配置

    一:ZooKeeper集群安装配置 1:解压zookeeper-3.3.2.tar.gz并重命名为zookeeper. 2:进入~/zookeeper/conf目录: 拷贝zoo_sample.cfg ...

  4. Zookeeper 集群安装配置,超详细,速度收藏!

    今天,栈长分享下 Zookeeper 的集群安装及配置. 下载 下载地址:http://zookeeper.apache.org/ 下载过程就不说了,我们下载了最新的zookeeper-3.4.11. ...

  5. Zookeeper 集群安装配置

    今天,栈长分享下 Zookeeper 的集群安装及配置. 下载 下载地址:http://zookeeper.apache.org/ 下载过程就不说了,我们下载了最新的zookeeper-3.4.11. ...

  6. 【集群搭建】Zookeeper集群环境配置

    1.下载解压安装文件 2.配置文件:conf/zoo.cfg tickTime=2000 dataDir=/usr/sunny/logs/zookeeper/data dataLogDir=/usr/ ...

  7. zookeeper 集群相关配置实践

    一,zookeeper 集群下载及配置 1.1, 准备三台服务器node1,node2,node3. 1.2, [root@liunx local]#yum install -y java #安装ja ...

  8. 8.3.ZooKeeper集群安装配置

    1.Zookeeper的搭建方式 Zookeeper安装方式有三种,单机模式和集群模式以及伪集群模式. 单机模式:Zookeeper只运行在一台服务器上,适合测试环境: 伪集群模式:就是在一台物理机上 ...

  9. zookeeper集群管理配置优化总结

    1:默认jvm没有配置Xmx.Xms等信息,可以在conf目录下创建java.env文件 export JVMFLAGS="-Xms512m -Xmx512m $JVMFLAGS" ...

随机推荐

  1. sql server 获取整数的函数ceiling(x)和floor(x)

    --ceiling(x)返回不小于x的最小整数值,floor(x)返回不大于x的最大整数值 示例:select CEILING(-3.35), CEILING(3.35), FLOOR(-3.35), ...

  2. 13.AutoMapper 之映射前后(Before and After Map Action)

    https://www.jianshu.com/p/1ff732094f21 映射前后(Before and After Map Action) 你可能偶尔需要在映射发生前后执行自定义逻辑.这应该很少 ...

  3. CF Gym102028G Shortest Paths on Random Forests

    传送门 这题要求的期望,就是总权值(所有不在同一个连通块点对的贡献+同一连通块点对的贡献)/总方案(森林个数) 先求森林个数,森林是由一堆树组成的,而根据purfer序列,一棵\(n\)个点的有标号的 ...

  4. Solaris下truss的使用

    Solaris下truss的使用 原文转载:http://blog.csdn.net/sunlin5000/article/details/6560736 在Solaris下面,如果需要跟踪系统的调用 ...

  5. Docker下载镜像出现failed to register layer: symlink....问题

    在用Docker下载RabbitMQ的时候出现如下问题 个人解决方案:重启Docker. 若重启还是无法解决问题,可以先关闭Docker systemctl stop docker 然后把已下载的相关 ...

  6. 扫描全能王 v5.13.0.20190916 去水印和广告版

    说明 1.先安装1(安装完不要打开),再安装2,然后打开2,参考下图: 2.不要登录扫描全能王账号,否则会导致失败! 3.激活完成后可以卸载2 下载地址 城通网盘 蓝奏云(仅含1) 百度网盘 另外口袋 ...

  7. ARM调试器只能偶尔连接成功问题

    这里分析一个ARM板子JTAG调试器经常连接失败,只能偶尔连上目标板问题. 背景 这是原先另一个部门的板子,在部门合并之后,最近要对这个板子的代码体系进行转移,在过问开发进度时,工程师反映这个板子调试 ...

  8. Android开发艺术探索笔记之Activity

    内容来源:Android开发艺术探索第一章:Activity的生命周期与启动模式 不能在onPause中做重量级的操作,因为必须执行完成以后新Activity才能Resume.onPause和onSt ...

  9. 清北学堂清华大学钟皓曦神仙讲课day3摘要

    ---恢复内容开始--- 今天全是DP awsl,真的好难 先从斐波那契开始: dp:满足有一个状态边界条件(f[0]=0,f[1]=1) 边界条件:不需要计算其他状态的值而可以直接得出的状态或者最底 ...

  10. Java基本的程序结构设计 大数操作

    大数操作 BigInteger 不可变的任意精度的整数.所有操作中,都以二进制补码形式表示 BigInteger(如 Java 的基本整数类型).BigInteger 提供所有 Java 的基本整数操 ...