【Zookeeper】本地模式安装

安装步骤

上传gz包

通过rz命令,将zookeeper-3.4.10.tar.gz安装包上传到/opt/soft/文件夹下。

[root@bigdata111 soft]# rz
[root@bigdata111 soft]# ls
hadoop-2.8.4.tar.gz  jdk-8u144-linux-x64.tar.gz  zookeeper-3.4.10.tar.gz

解压包

通过tar命令解压zookeeper到/opt/module/目录下。

[root@bigdata111 soft]# tar -zvxf zookeeper-3.4.10.tar.gz -C /opt/module/
[root@bigdata111 soft]# cd /opt/module/
[root@bigdata111 module]# ls
hadoop-2.8.4  jdk1.8.0_144  zookeeper-3.4.10

新建zkData目录

在zookeeper的解压目录下新建zkData文件夹,用于数据文件目录+数据持久化路径。

[root@bigdata111 module]# cd zookeeper-3.4.10/
[root@bigdata111 zookeeper-3.4.10]# mkdir zkData
[root@bigdata111 zookeeper-3.4.10]# ls
bin  build.xml  conf  contrib  dist-maven  docs  ivysettings.xml  ivy.xml  lib  LICENSE.txt  NOTICE.txt  README_packaging.txt  README.txt  recipes  src  zkData  zookeeper-3.4.10.jar  zookeeper-3.4.10.jar.asc  zookeeper-3.4.10.jar.md5  zookeeper-3.4.10.jar.sha1

修改默认文件名

切换至zookeeper的conf目录下,修改zoo_sample.cfg为默认识别的zoo.cfg配置文件。

[root@bigdata111 module]# cd zookeeper-3.4.10/conf
[root@bigdata111 conf]# ll
总用量 12
-rw-rw-r--. 1 1001 1001  535 3月  23 2017 configuration.xsl
-rw-rw-r--. 1 1001 1001 2161 3月  23 2017 log4j.properties
-rw-rw-r--. 1 1001 1001  922 3月  23 2017 zoo_sample.cfg
[root@bigdata111 conf]# mv zoo_sample.cfg zoo.cfg
[root@bigdata111 conf]# ll
总用量 12
-rw-rw-r--. 1 1001 1001  535 3月  23 2017 configuration.xsl
-rw-rw-r--. 1 1001 1001 2161 3月  23 2017 log4j.properties
-rw-rw-r--. 1 1001 1001  922 3月  23 2017 zoo.cfg

配置修改

配置zookeeper的zoo.cfg文件,保存并退出。

[root@bigdata111 conf]# vi zoo.cfg

将其中的dataDir值修改如下:

dataDir=/opt//module/zookeeper-3.4.10/zkData

配置环境变量

执行vi命令

[root@bigdata111 conf]# vi /etc/profile

在/etc/profile文件内容末尾添加如下内容,配置完毕,保存退出。

export ZOOKEEPER_HOME=/opt/module/zookeeper-3.4.10
export PATH=$PATH:$ZOOKEEPER_HOME/bin

刷新profile配置文件

[root@bigdata111 zookeeper-3.4.10]# source /etc/profile

启动zk服务端

启动zk服务端,查看进程是否启动(QuorumPeerMain进程为zookeeper的server),查看zkServer的状态。

[root@bigdata111 zookeeper-3.4.10]# zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@bigdata111 zookeeper-3.4.10]# jps
2817 NodeManager
2565 DataNode
3014 QuorumPeerMain
2426 NameNode
3034 Jps
[root@bigdata111 zookeeper-3.4.10]# zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: standalone

启动zk客户端

[root@bigdata111 zookeeper-3.4.10]# zkCli.sh
Connecting to localhost:2181
2019-09-01 00:00:07,411 [myid:] - INFO  [main:Environment@100] - Client environment:zookeeper.version=3.4.10-39d3a4f269333c922ed3db283be479f9deacaa0f, built on 03/23/2017 10:13 GMT
2019-09-01 00:00:07,413 [myid:] - INFO  [main:Environment@100] - Client environment:host.name=bigdata111
2019-09-01 00:00:07,413 [myid:] - INFO  [main:Environment@100] - Client environment:java.version=1.8.0_144
2019-09-01 00:00:07,423 [myid:] - INFO  [main:Environment@100] - Client environment:java.vendor=Oracle Corporation
2019-09-01 00:00:07,423 [myid:] - INFO  [main:Environment@100] - Client environment:java.home=/opt/module/jdk1.8.0_144/jre
2019-09-01 00:00:07,424 [myid:] - INFO  [main:Environment@100] - Client environment:java.class.path=/opt/module/zookeeper-3.4.10/bin/../build/classes:/opt/module/zookeeper-3.4.10/bin/../build/lib/*.jar:/opt/module/zookeeper-3.4.10/bin/../lib/slf4j-log4j12-1.6.1.jar:/opt/module/zookeeper-3.4.10/bin/../lib/slf4j-api-1.6.1.jar:/opt/module/zookeeper-3.4.10/bin/../lib/netty-3.10.5.Final.jar:/opt/module/zookeeper-3.4.10/bin/../lib/log4j-1.2.16.jar:/opt/module/zookeeper-3.4.10/bin/../lib/jline-0.9.94.jar:/opt/module/zookeeper-3.4.10/bin/../zookeeper-3.4.10.jar:/opt/module/zookeeper-3.4.10/bin/../src/java/lib/*.jar:/opt/module/zookeeper-3.4.10/bin/../conf:
2019-09-01 00:00:07,424 [myid:] - INFO  [main:Environment@100] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2019-09-01 00:00:07,424 [myid:] - INFO  [main:Environment@100] - Client environment:java.io.tmpdir=/tmp
2019-09-01 00:00:07,424 [myid:] - INFO  [main:Environment@100] - Client environment:java.compiler=<NA>
2019-09-01 00:00:07,424 [myid:] - INFO  [main:Environment@100] - Client environment:os.name=Linux
2019-09-01 00:00:07,424 [myid:] - INFO  [main:Environment@100] - Client environment:os.arch=amd64
2019-09-01 00:00:07,424 [myid:] - INFO  [main:Environment@100] - Client environment:os.version=3.10.0-327.el7.x86_64
2019-09-01 00:00:07,424 [myid:] - INFO  [main:Environment@100] - Client environment:user.name=root
2019-09-01 00:00:07,424 [myid:] - INFO  [main:Environment@100] - Client environment:user.home=/root
2019-09-01 00:00:07,424 [myid:] - INFO  [main:Environment@100] - Client environment:user.dir=/opt/module/zookeeper-3.4.10
2019-09-01 00:00:07,425 [myid:] - INFO  [main:ZooKeeper@438] - Initiating client connection, connectString=localhost:2181 sessionTimeout=30000 watcher=org.apache.zookeeper.ZooKeeperMain$MyWatcher@5c29bfd
2019-09-01 00:00:07,467 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1032] - Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
Welcome to ZooKeeper!
JLine support is enabled
2019-09-01 00:00:07,559 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@876] - Socket connection established to localhost/127.0.0.1:2181, initiating session
2019-09-01 00:00:07,588 [myid:] - INFO  [main-SendThread(localhost:2181):ClientCnxn$SendThread@1299] - Session establishment complete on server localhost/127.0.0.1:2181, sessionid = 0x16ce86366fb0000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
[zk: localhost:2181(CONNECTED) 0]

查看zk节点

使用ls 查看 / 根目录,只用ls不会输出内容。

[zk: localhost:2181(CONNECTED) 1] ls /
[zookeeper]

退出客户端

[zk: localhost:2181(CONNECTED) 0] quit
Quitting...
2019-09-01 00:01:10,945 [myid:] - INFO  [main:ZooKeeper@684] - Session: 0x16ce86366fb0000 closed
2019-09-01 00:01:10,947 [myid:] - INFO  [main-EventThread:ClientCnxn$EventThread@519] - EventThread shut down for session: 0x16ce86366fb0000

停止Zookeeper

[root@bigdata111 zookeeper-3.4.10]# zkServer.sh stop
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Stopping zookeeper ... STOPPED

配置参数解读

tickTime

tickTime=2000:通信心跳数,Zookeeper服务器心跳时间,单位毫秒

Zookeeper使用的基本时间,服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个tickTime时间就会发送一个心跳,时间单位为毫秒。

它用于心跳机制,并且设置最小的session超时时间为两倍心跳时间。(session的最小超时时间是2*tickTime)

initLimit

initLimit=10:Leader和Follower初始通信时限

集群中的follower跟随者服务器与leader领导者服务器之间初始连接时能容忍的最多心跳数(tickTime的数量),用它来限定集群中的Zookeeper服务器连接到Leader的时限。

投票选举新leader的初始化时间

Follower在启动过程中,会从Leader同步所有最新数据,然后确定自己能够对外服务的起始状态。

Leader允许Follower在initLimit时间内完成这个工作。

syncLimit

syncLimit=5:Leader和Follower同步通信时限

集群中Leader与Follower之间的最大响应时间单位,假如响应超过syncLimit * tickTime,Leader认为Follwer死掉,从服务器列表中删除Follwer。

在运行过程中,Leader负责与ZK集群中所有机器进行通信,例如通过一些心跳检测机制,来检测机器的存活状态。

如果L发出心跳包在syncLimit之后,还没有从F那收到响应,那么就认为这个F已经不在线了。

dataDir

dataDir:数据文件目录+数据持久化路径

保存内存数据库快照信息的位置,如果没有其他说明,更新的事务日志也保存到数据库。

clientPort

clientPort=2181:客户端连接端口

监听客户端连接的端口

posted @ 2019-09-02 11:55  ShadowFiend  阅读(275)  评论(0编辑  收藏  举报