前提准备3台centos7.0虚拟机

c7003:192.168.70.103

c7004:192.168.70.104

c7005:192.168.70.105

并在三台虚拟机上配置hosts为

192.168.70.103   c7003

192.168.70.104   c7004

192.168.70.105   c7005

架构图如下:

注意:follower负责响应读请求,leader负责提交写请求

1、下载zookeeper并解压

登录到c7003并进入/opt目录下执行如下命令

[vagrant@c7003 opt]$ wget http://apache.fayea.com/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
[vagrant@c7003 opt]$ tar -zxvf zookeeper-3.4.10.tar.gz
[vagrant@c7003 opt]$ chmod +wxr zookeeper-3.4.10

2、修改zookeeper的配置文件,并建立数据目录和日志目录

[vagrant@c7003 opt]$ cd zookeeper-3.4.10
[vagrant@c7003 zookeeper-3.4.10]$ mkdir data
[vagrant@c7003 zookeeper-3.4.10]$ mkdir logs
[vagrant@c7003 zookeeper-3.4.10]$ vi conf/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=/opt/zookeeper-3.4.10/data
dataLogDir=/opt/zookeeper-3.4.10/logs
server.1=c7003:2888:3888
server.2=c7004:2888:3888
server.3=c7005:2888:3888
# 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

[vagrant@c7003 zookeeper-3.4.10]$ cd data
[vagrant@c7003 data]$ vi myid
1

3、复制c7003的zookeeper-3.4.10到c7004和c7005上

[vagrant@c7003 opt]$ scp zookeeper-3.4.10 vagrant@c7004:/opt/zookeeper-3.4.10
[vagrant@c7003 opt]$ scp zookeeper-3.4.10 vagrant@c7005:/opt/zookeeper-3.4.10

4、分别修改c7004和c7005上myid的值为2和3

[vagrant@c7004 zookeeper-3.4.10]$ vi data/myid
2
[vagrant@c7005 zookeeper-3.4.10]$ vi data/myid
3

5、分别启动c7003、c7004、c7005上的zookeeper

[vagrant@c7003 zookeeper-3.4.10]$ bin/zkServer.sh start
[vagrant@c7004 zookeeper-3.4.10]$ bin/zkServer.sh start
[vagrant@c7005 zookeeper-3.4.10]$ bin/zkServer.sh start

6、查看zookeeper的状态

[vagrant@c7003 zookeeper-3.4.10]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower
[vagrant@c7004 zookeeper-3.4.10]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
[vagrant@c7005 zookeeper-3.4.10]$ bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower

7、验证zookeeper集群

[vagrant@c7003 zookeeper-3.4.10]$ bin/zkCli.sh -server c7003:2181
Connecting to c7003:2181
2017-04-02 03:06:12,251 [myid:] - INFO [main:Environment@100] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
2017-04-02 03:06:12,257 [myid:] - INFO [main:Environment@100] - Client environment:host.name=c7003.ambari.apache.org
2017-04-02 03:06:12,257 [myid:] - INFO [main:Environment@100] - Client environment:java.version=1.8.0_121
2017-04-02 03:06:12,260 [myid:] - INFO [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2017-04-02 03:06:12,260 [myid:] - INFO [main:Environment@100] - Client environment:java.home=/opt/jdk1.8.0_121/jre
2017-04-02 03:06:12,260 [myid:] - INFO [main:Environment@100] - Client environment:java.class.path=/opt/zookeeper-3.4.10/bin/../build/classes:/opt/zookeeper-3.4.10/bin/../build/lib/*.jar:/opt/zookeeper-3.4.10/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/zookeeper-3.4.10/bin/../lib/slf4j-api-1.6.1.jar:/opt/zookeeper-3.4.10/bin/../lib/netty-3.10.5.Final.jar:/opt/zookeeper-3.4.10/bin/../lib/log4j-1.2.16.jar:/opt/zookeeper-3.4.10/bin/../lib/jline-0.9.94.jar:/opt/zookeeper-3.4.10/bin/../zookeeper-3.4.10.jar:/opt/zookeeper-3.4.10/bin/../src/java/lib/*.jar:/opt/zookeeper-3.4.10/bin/../conf:
2017-04-02 03:06:12,260 [myid:] - INFO [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2017-04-02 03:06:12,260 [myid:] - INFO [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2017-04-02 03:06:12,260 [myid:] - INFO [main:Environment@100] - Client environment:java.compiler=<NA>
2017-04-02 03:06:12,260 [myid:] - INFO [main:Environment@100] - Client environment:os.name=Linux
2017-04-02 03:06:12,260 [myid:] - INFO [main:Environment@100] - Client environment:os.arch=amd64
2017-04-02 03:06:12,261 [myid:] - INFO [main:Environment@100] - Client environment:os.version=4.1.12-32.el7uek.x86_64
2017-04-02 03:06:12,261 [myid:] - INFO [main:Environment@100] - Client environment:user.name=vagrant
2017-04-02 03:06:12,261 [myid:] - INFO [main:Environment@100] - Client environment:user.home=/home/vagrant
2017-04-02 03:06:12,261 [myid:] - INFO [main:Environment@100] - Client environment:user.dir=/opt/zookeeper-3.4.10
2017-04-02 03:06:12,262 [myid:] - INFO [main:ZooKeeper@438] - Initiating client connection, connectString=c7003:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@506c589e
Welcome to ZooKeeper!

ls /
[zookeeper, zk_test]

至此:zookeeper集群安装完毕!

PS:

1、由于zk运行一段时间后,会产生大量的日志文件,把磁盘空间占满,导致整个机器进程都不能活动了,所以需要定期清理这些日志文件,方法如下:

1)、写一个脚本文件cleanup.sh内容如下:

 java -cp zookeeper.jar:lib/slf4j-api-1.6.1.jar:lib/slf4j-log4j12-1.6.1.jar:lib/log4j-1.2.15.jar:conf org.apache.zookeeper.server.PurgeTxnLog <dataDir> <snapDir> -n <count>

其中:

  dataDir:即上面配置的dataDir的目录

snapDir:即上面配置的dataLogDir的目录

  count:保留前几个日志文件,默认为3

2)、通过crontab写定时任务,来完成定时清理日志的需求

crontab -e 0 0 * *  /opt/zookeeper-3.4.10/bin/cleanup.sh

3)、在其它2台机器做同样操作












1、zookeeper集群安装的更多相关文章

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

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

  2. hbase和ZooKeeper集群安装配置

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

  3. Zookeeper集群安装Version3.5.1

    Zookeeper集群安装,基于版本3.5.1, 使用zookeeper-3.5.1-alpha.tar.gz安装包. 1.安装规划 zookeeper集群模式,安装到如下三台机器 10.43.159 ...

  4. Zookeeper集群安装详解

    Zookeeper的角色   Zookeeper集群搭建 要求:服务器集群规模不小于3个节点,各服务器之间系统时间要保持一致! 安装步骤 1.在h1节点解压,目录改名. tar –zxvf zooke ...

  5. ZooKeeper集群安装

    ZooKeeper是Apache提供的.分布式服务协调系统,应用比較广泛. 由于项目中使用Kafka MQ,而Kafka全然使用ZooKeeper实现Kafka各组件的服务协调,包含Broker.Co ...

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

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

  7. centos7下zookeeper集群安装部署

    应用场景:ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件. 它是一个为分布式应用提供一致性服务的软 ...

  8. Zookeeper 集群安装配置

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

  9. zookeeper 集群安装与配置

    Zookeeper安装和配置 准备工作 安装 JDK,此步略. 下载 zookeeper wget http://archive.apache.org/dist/zookeeper/zookeeper ...

随机推荐

  1. Activiti进阶(二)——部署流程资源的三种方式

    转自:http://blog.csdn.net/zjx86320/article/details/50234707 流程资源可以是各种类型的文件,在启动流程或流程实例运行过程中会被读取.下面介绍常用的 ...

  2. SQL Server 数据库获取架构信息

    得到数据库存储过程列表: select * from dbo.sysobjects where OBJECTPROPERTY(id, N'IsProcedure') = 1 order by name ...

  3. OO第二次单元总结

    OO第二次单元总结 前言 第二单元的三次作业:系列电梯与多线程. 第五次作业 (1)设计策略 电梯的第一次作业是单部傻瓜电梯,采用FAFS调度策略,电梯按队列顺序依次处理请求,单次只处理一个请求.本次 ...

  4. LA3905

    题意: 给出n颗流星,第i颗在第T秒时飞到(xi+ai*t,yi+bi*t),给出一个矩形,问在某一时刻这个矩形中的流星数目最多有多少 题解: 首先计算出每一颗流星经过时间 然后左端点移动,计算出少了 ...

  5. JS实现点击按钮,下载文件

    PS:本文说的,并非如何用js创建流.创建文件.实现下载功能. 而是说的:你已知一个下载文件的后端接口,前端如何请求该接口,实现点击按钮.下载文件到本地.(可以是zip啦.excel啦都是一样) 有两 ...

  6. 微软IE团队发布《逃离XP》浏览器小游戏

    微软IE团队今天发布了一个有趣的小游戏<逃离Windows XP>,这款游戏可以工作在所有现代浏览器下,简单的街机风格可以让你尽情对XP施展破坏欲.微软发布XP及提供支持服务已经史无前例地 ...

  7. 安装win8时提不能在gpt磁盘中安装

    首先,你要知道,GPT和NTFS根本就是两码事儿.所谓的GPT,是指可扩展固件接口 (EFI) 使用的磁盘分区架构,是与主启动记录 (MBR) 分区架构相对应的,是一种磁盘分区架构.而ntfs,fat ...

  8. ZooKeeper客户端原生API的使用以及ZkClient第三方API的使用

    这两部分内容的介绍主要讲的是节点及节点内容和子节点的操作,并且讲解的节点的事件监听以及ACL授权 ZooKeeper客户端原生API的使用 百度网盘地址: http://pan.baidu.com/s ...

  9. vue 登录验证引擎

    1.router配置: 路由元信息 const router = new VueRouter({ routes: [ { path: '/foo', component: Foo, children: ...

  10. ReSharper2017.3的列对齐、排版格式、列对齐错误的修复

    ReSharper代码排版格式 列对齐 本文提供全流程,中文翻译.Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- ...