Zookeeper运行需要java环境,需要安装jdk,建议本地下载好需要的安装包然后上传到服务器上面,服务器上面下载速度太慢。

上传

[root@192 ~]# java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)

解压

[root@192 modules]# tar -zxvf zookeeper-3.4.13.tar.gz -C /opt/soft/

拷贝三份

[root@192 soft]# cp -r zookeeper-3.4.13/ zookeeper1
[root@192 soft]# cp -r zookeeper1 zookeeper2
[root@192 soft]# cp -r zookeeper1 zookeeper3
[root@192 soft]# ll
total 16
drwxr-xr-x. 12 root root 4096 Sep 9 14:44 zookeeper1
drwxr-xr-x. 12 root root 4096 Sep 9 14:45 zookeeper2
drwxr-xr-x. 12 root root 4096 Sep 9 14:46 zookeeper3
drwxr-xr-x. 12 501 games 4096 Sep 9 14:51 zookeeper-3.4.13

修改配置文件

重命名并修改zookeeper1配置文件

[root@192 conf]# mv zoo_sample.cfg zoo.cfg
[root@192 conf]# ll
total 20
-rw-r--r--. 1 root root 535 Sep 9 11:38 configuration.xsl
-rw-r--r--. 1 root root 2161 Sep 9 11:38 log4j.properties
-rw-r--r--. 1 root root 285 Sep 9 15:03 zoo.cfg
-rw-r--r--. 1 root root 2306 Sep 9 11:48 zookeeper.out
-rw-r--r--. 1 root root 922 Sep 9 11:38 zoo_sample.cfg
[root@192 conf]# vim zoo.cfg
[root@192 conf]# cat zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/soft/zookeeper1/data
dataLogDir=/opt/soft/zookeeper1/logs
clientPort=2181
autopurge.snapRetainCount=500
autopurge.purgeInterval=24
server.1= 192.168.1.101:2888:3888
server.2= 192.168.1.101:2889:3889
server.3= 192.168.1.101:2890:3890
[root@192 conf]#

修改zookeeper2配置文件

[root@192 conf]# cat /opt/soft/zookeeper2/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/opt/soft/zookeeper2/logs
dataDir=/opt/soft/zookeeper2/data
clientPort=2182
autopurge.snapRetainCount=500
autopurge.purgeInterval=24
server.1= 192.168.1.101:2888:3888
server.2= 192.168.1.101:2889:3889
server.3= 192.168.1.101:2890:3890

修改zookeeper3配置文件

[root@192 conf]# cat /opt/soft/zookeeper3/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/opt/soft/zookeeper3/logs
dataDir=/opt/soft/zookeeper3/data
clientPort=2183
autopurge.snapRetainCount=500
autopurge.purgeInterval=24
server.1= 192.168.1.101:2888:3888
server.2= 192.168.1.101:2889:3889
server.3= 192.168.1.101:2890:3890

查看配置好的三个配置文件

[root@192 ~]# egrep -v "^#|^$" /opt/soft/zookeeper1/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/soft/zookeeper1/data
dataLogDir=/opt/soft/zookeeper1/logs
clientPort=2181
autopurge.snapRetainCount=500
autopurge.purgeInterval=24
server.1= 192.168.1.101:2888:3888
server.2= 192.168.1.101:2889:3889
server.3= 192.168.1.101:2890:3890
[root@192 ~]# egrep -v "^#|^$" /opt/soft/zookeeper2/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/opt/soft/zookeeper2/logs
dataDir=/opt/soft/zookeeper2/data
clientPort=2182
autopurge.snapRetainCount=500
autopurge.purgeInterval=24
server.1= 192.168.1.101:2888:3888
server.2= 192.168.1.101:2889:3889
server.3= 192.168.1.101:2890:3890
[root@192 ~]# egrep -v "^#|^$" /opt/soft/zookeeper3/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataLogDir=/opt/soft/zookeeper3/logs
dataDir=/opt/soft/zookeeper3/data
clientPort=2183
autopurge.snapRetainCount=500
autopurge.purgeInterval=24
server.1= 192.168.1.101:2888:3888
server.2= 192.168.1.101:2889:3889
server.3= 192.168.1.101:2890:3890
参数 说明
tickTime=2000 这个时间是作为zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是说每个tickTime时间就会发送一个心跳
initLimit=10 这个配置项是用来配置zookeeper接受客户端(这里所说的客户端不是用户连接zookeeper服务器的客户端,而是zookeeper服务器集群中连接到leader的follower服务器)初始化连接时最长能忍受多少个心跳时间间隔数。
当已经超过10个心跳的时间(也就是tickTime)长度后 zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 10*2000=20
syncLimit=5 这个配置项标识leaderfollower之间发送消息,请求和应答时间长度,最长不能超过多少个tickTime的时间长度,总的时间长度就是5*2000=10
dataDir=/opt/soft/zookeeper1/data zookeeper保存数据的目录,默认情况下zookeeper将写数据的日志文件也保存在这个目录里;
dataLogDir=/opt/soft/zookeeper1/logs zookeeper保存日志文件数据
clientPort=2181 这个端口就是客户端连接Zookeeper服务器的端口,Zookeeper会监听这个端口接受客户端的访问请求
server.1= 192.168.1.101:2888:3888 server.A=B:C:D中的A是一个数字,表示这个是第几号服务器,B是这个服务器的IP地址,C第一个端口用来集群成员的信息交换,表示这个服务器与集群中的leader服务器交换信息的端口,D是在leader挂掉时专门用来进行选举leader所用的端口。

创建数据目录和日志目录

[root@192 ~]# mkdir -p /opt/soft/zookeeper1/{data,logs}
[root@192 ~]# mkdir -p /opt/soft/zookeeper2/{data,logs}
[root@192 ~]# mkdir -p /opt/soft/zookeeper3/{data,logs}
[root@192 ~]# echo "1">/opt/soft/zookeeper1/data/myid
[root@192 ~]# echo "2">/opt/soft/zookeeper2/data/myid
[root@192 ~]# echo "3">/opt/soft/zookeeper3/data/myid
[root@192 ~]# cat /opt/soft/zookeeper1/data/myid
1
[root@192 ~]# cat /opt/soft/zookeeper2/data/myid
2
[root@192 ~]# cat /opt/soft/zookeeper3/data/myid
3
[root@192 ~]#

myid中的值对应server.A=B:C:D中的A

配置环境变量

[root@192 ~]# vim /etc/profile
#jdk
export JAVA_HOME=/usr/java/jdk1.8.0_202-amd64
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar # append zk1_env
export PATH=$PATH:/opt/soft/zookeeper1/bin
# append zk2_env
export PATH=$PATH:/opt/soft/zookeeper2/bin
# append zk3_env
export PATH=$PATH:/opt/soft/zookeeper3/bin

启动

[root@192 ~]# /opt/soft/zookeeper1/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper1/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@192 ~]# /opt/soft/zookeeper1/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper1/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
[root@192 ~]# /opt/soft/zookeeper2/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper2/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@192 ~]# /opt/soft/zookeeper1/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper1/bin/../conf/zoo.cfg
Mode: follower
[root@192 ~]# /opt/soft/zookeeper2/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper2/bin/../conf/zoo.cfg
Mode: leader
[root@192 ~]# /opt/soft/zookeeper3/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper3/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@192 ~]# /opt/soft/zookeeper3/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper3/bin/../conf/zoo.cfg
Mode: follower
[root@192 ~]#

停止

[root@192 ~]# /opt/soft/zookeeper1/bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper1/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@192 ~]# /opt/soft/zookeeper2/bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper2/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@192 ~]# /opt/soft/zookeeper3/bin/zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /opt/soft/zookeeper3/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED
[root@192 ~]# ps -ef|grep zookeeper
root 4068 3406 0 15:46 pts/0 00:00:00 grep zookeeper
[root@192 ~]#

查看状态

[root@192 ~]# ps -ef|grep zookeeper
root 3649 1 0 15:07 pts/0 00:00:02 /usr/java/jdk1.8.0_202-amd64/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /opt/soft/zookeeper1/bin/../build/classes:/opt/soft/zookeeper1/bin/../build/lib/*.jar:/opt/soft/zookeeper1/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/soft/zookeeper1/bin/../lib/slf4j-api-1.7.25.jar:/opt/soft/zookeeper1/bin/../lib/netty-3.10.6.Final.jar:/opt/soft/zookeeper1/bin/../lib/log4j-1.2.17.jar:/opt/soft/zookeeper1/bin/../lib/jline-0.9.94.jar:/opt/soft/zookeeper1/bin/../lib/audience-annotations-0.5.0.jar:/opt/soft/zookeeper1/bin/../zookeeper-3.4.13.jar:/opt/soft/zookeeper1/bin/../src/java/lib/*.jar:/opt/soft/zookeeper1/bin/../conf:.:/usr/java/jdk1.8.0_202-amd64/jre/lib/rt.jar:/usr/java/jdk1.8.0_202-amd64/lib/dt.jar:/usr/java/jdk1.8.0_202-amd64/lib/tools.jar -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /opt/soft/zookeeper1/bin/../conf/zoo.cfg
root 3725 1 0 15:07 pts/0 00:00:04 /usr/java/jdk1.8.0_202-amd64/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /opt/soft/zookeeper2/bin/../build/classes:/opt/soft/zookeeper2/bin/../build/lib/*.jar:/opt/soft/zookeeper2/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/soft/zookeeper2/bin/../lib/slf4j-api-1.7.25.jar:/opt/soft/zookeeper2/bin/../lib/netty-3.10.6.Final.jar:/opt/soft/zookeeper2/bin/../lib/log4j-1.2.17.jar:/opt/soft/zookeeper2/bin/../lib/jline-0.9.94.jar:/opt/soft/zookeeper2/bin/../lib/audience-annotations-0.5.0.jar:/opt/soft/zookeeper2/bin/../zookeeper-3.4.13.jar:/opt/soft/zookeeper2/bin/../src/java/lib/*.jar:/opt/soft/zookeeper2/bin/../conf:.:/usr/java/jdk1.8.0_202-amd64/jre/lib/rt.jar:/usr/java/jdk1.8.0_202-amd64/lib/dt.jar:/usr/java/jdk1.8.0_202-amd64/lib/tools.jar -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /opt/soft/zookeeper2/bin/../conf/zoo.cfg
root 3777 1 0 15:07 pts/0 00:00:02 /usr/java/jdk1.8.0_202-amd64/bin/java -Dzookeeper.log.dir=. -Dzookeeper.root.logger=INFO,CONSOLE -cp /opt/soft/zookeeper3/bin/../build/classes:/opt/soft/zookeeper3/bin/../build/lib/*.jar:/opt/soft/zookeeper3/bin/../lib/slf4j-log4j12-1.7.25.jar:/opt/soft/zookeeper3/bin/../lib/slf4j-api-1.7.25.jar:/opt/soft/zookeeper3/bin/../lib/netty-3.10.6.Final.jar:/opt/soft/zookeeper3/bin/../lib/log4j-1.2.17.jar:/opt/soft/zookeeper3/bin/../lib/jline-0.9.94.jar:/opt/soft/zookeeper3/bin/../lib/audience-annotations-0.5.0.jar:/opt/soft/zookeeper3/bin/../zookeeper-3.4.13.jar:/opt/soft/zookeeper3/bin/../src/java/lib/*.jar:/opt/soft/zookeeper3/bin/../conf:.:/usr/java/jdk1.8.0_202-amd64/jre/lib/rt.jar:/usr/java/jdk1.8.0_202-amd64/lib/dt.jar:/usr/java/jdk1.8.0_202-amd64/lib/tools.jar -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /opt/soft/zookeeper3/bin/../conf/zoo.cfg
root 3995 3406 0 15:45 pts/0 00:00:00 grep zookeeper

zookeeper伪集群的更多相关文章

  1. (原) 1.2 Zookeeper伪集群安装

    本文为原创文章,转载请注明出处,谢谢 Zookeeper伪集群安装 zookeeper单机安装配置可以查看 1.1 zookeeper单机安装 1.复制三份zookeeper,分别为zookeeper ...

  2. win10环境下搭建zookeeper伪集群

    一.下载zookeeper https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/ 这里笔者下载的是zookeeper-3.3.6 二.配置zoo ...

  3. 分享知识-快乐自己:zookeeper 伪集群搭建

    1):单一 zookeeper  搭建步骤 2):zookeeper 伪集群搭建 1):新建一个集群目录 [root@zoodubbo opt]# mkdir zookeeper_cluster 2) ...

  4. ZooKeeper伪集群环境搭建

    1.从官网下载程序包. 2.解压. [dev@localhost software]$ tar xzvf zookeeper-3.4.6.tar.gz 3.进入zookeeper文件夹后创建data文 ...

  5. CentOS6.3搭建ZooKeeper伪集群

    1. 将zookeeper安装包移动至/home, 解压后改名为zookeeper 相关命令 # 解压 .tar.gz # 重命名 zookeeper 2. 进入zookeeper/conf/目录下, ...

  6. zookeeper伪集群搭建

    zookeeper伪集群搭建 1. 下载zookeeper: https://zookeeper.apache.org/ 2. 解压: tar -zxvf zookeeper-3.4.14.tar.g ...

  7. windows下zookeeper伪集群搭建

    下载 http://www.apache.org/dyn/closer.cgi/zookeeper/ 解压 D:\Java\soft\zookeeper-3.4.6 伪集群 1.在 \zookeepe ...

  8. zookeeper 伪集群模式

    问题二:开发没有足够机器,一台机子上是否装三个zookeeper服务器集群. 问题解答: 这种安装模式只能说是一种伪集群模式.三个zookeeper服务器都安装在同一个服务器(platform)上,需 ...

  9. [dubbo实战] dubbo+zookeeper伪集群搭建

    zookeeper作为注册中心,服务器和客户端都要访问,如果有大量的并发,肯定会有等待.所以可以通过zookeeper集群解决. 一.为什么需要zookeeper呢? 大部分分布式应用需要一个主控.协 ...

  10. dubbo+zookeeper伪集群配置

    zookeeper作为注册中心,服务器和客户端都要访问,如果有大量的并发,肯定会有等待.所以可以通过zookeeper集群解决. 一.为什么需要zookeeper呢? 大部分分布式应用需要一个主控.协 ...

随机推荐

  1. 使用 Docker 部署 Spring Boot

    Docker 技术发展为微服务落地提供了更加便利的环境,使用 Docker 部署 Spring Boot 其实非常简单,这篇文章我们就来简单学习下. 首先构建一个简单的 Spring Boot 项目, ...

  2. Mac查看及清理QQ、微信之前下载的图片、视频或DB等

    之前写过一篇清理Mac空间的文章: Mac系统清理.占用空间大.空间不够.查看系统文件大小分布 其实这篇文章不是太全,有些资源还是清理不彻底,正好前段时间需要找微信下载的资源,其实可以算作空间清理的续 ...

  3. MongoDB的一些高级语法.md

      MongoDB的一些高级语法 AND 和 OR操作 AND操作 OR操作 嵌入式文档 插入 查询 数组(Array)字段 插入 查询 聚合(Aggregation) 筛选数据 修改字段 注意事项 ...

  4. 通过类来实现多session 运行

    #xilerihua import tensorflow as tf import numpy as np import os from PIL import Image import matplot ...

  5. unity_数据结构(常见数据结构及适用场景)

    常见的数据结构: 1.Array: 最简单的数据结构 特点:数组存储在连续的内存上.数组的内容都是相同类型.数组可以直接通过下标访问.优点:由于是在连续内存上存储的,所以它的索引速度非常快,访问一个元 ...

  6. 一文看尽Java-Thread

    一.前言      主要分成两部说起:Thread源码解读和常见面试题解答,废话不多说开始: 二.源码解读 首先看下构造函数,构造函数都是通过调用init方法对属性进行初始化,主要是对线程组.线程名字 ...

  7. 猫眼电影和电影天堂数据csv和mysql存储

    字符串常用方法 # 去掉左右空格 'hello world'.strip() # 'hello world' # 按指定字符切割 'hello world'.split(' ') # ['hello' ...

  8. Dart语法学习

    Dart语法学习 目录 参考资料 语言特性 关键字 变量与常量 数据类型 运算符 operators 控制流程语句 异常 Exceptions 函数 Function 类 Class 类-方法 类-抽 ...

  9. mysql类似oracle rownum写法

    rownum是oracle才有的写法,rownum在oracle中可以用于取第一条数据,或者批量写数据时限定批量写的数量等 mysql取第一条数据写法 SELECT * FROM t order by ...

  10. Badboy参数化 - Add Variable(循环使用不同的关键字进行搜索)

    参考: http://leafwf.blog.51cto.com/872759/1113716 http://www.51testing.com/html/00/130600-1367743.html ...