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. ReactJS:最大更新深度超出错误

    Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside com ...

  2. pip升级命令

    pip升级命令 $ python -m pip install --upgrade pip

  3. Jupter NotebooK学习

    1.参考资料 B站上学习视频 Jupyter 安装与使用 2.安装 在cmd窗口中输入(创建的文件会再当前的目录下):pip install jupyter 然后输入:jupyter notebook ...

  4. 如何配置sigar在Linux和Windows下使用java语言获得各种系统信息

    转自:https://blog.csdn.net/qq_27093465/article/details/70227619

  5. Flink中Periodic水印和Punctuated水印实现原理(源码分析)

    在用户代码中,我们设置生成水印和事件时间的方法assignTimestampsAndWatermarks()中这里有个方法的重载 我们传入的对象分为两种 AssignerWithPunctuatedW ...

  6. Unity Shader 卡通渲染 基于退化四边形的实时描边

    从csdn转移过来,顺便把写过的文章改写一下转过来. 一.边缘检测算法 3D模型描边有两种方式,一种是基于图像,即在所有3D模型渲染完成一张图片后,对这张图片进行边缘检测,最后得出描边效果.一种是基于 ...

  7. Delphi - cxGrid颜色显示相关设置

    1:单元格的值满足某个条件时,该单元格所在整行颜色设置整行字体设置 选中cxGridDBTableView,单击F11调出属性配置面板,在Events中双击OnCustomDrawCell后双击编辑重 ...

  8. 在.net core web 项目中操作MySql数据库(非ORM框架,原生sql语句方式)

    本案例通过MySql.Data和Dapper包执行原生sql,实现对数据库的操作. 操作步骤: 第1步:在MySql数据库中新建表User(使用Navicat For MySql工具) 建表语句: c ...

  9. 在.net core web api项目中安装swagger展示api接口(相当于生成api文档)

    1,  建立或打开项目后,在“程序包管理器控制台”中执行以下命令添加包引用: Install-Package Swashbuckle.AspNetCore 2,在项目中打开Startup.cs文件,找 ...

  10. 洛谷 P1135 【奇怪的电梯】

    题库 :洛谷 题号 :1135 题目 :奇怪的电梯 link :https://www.luogu.org/problemnew/show/P1135 一. 动态规划 : 思路 :这道题用动规来解决其 ...