Zookeeper单机安装

Zookeeper安装

安装环境:

  1. 系统:centos7.6

  2. Java环境:JDK8

zookeeper安装需要java环境,怎么配置请看

https://www.cnblogs.com/hsyw/p/13203495.html

1、下载zookeeper

wget https://mirrors.bfsu.edu.cn/apache/zookeeper/zookeeper-3.5.8/apache-zookeeper-3.5.8-bin.tar.gz

2、安装配置

#规划好安装目录,方便日后搭建集群mkdir /app/zktst -p#把刚刚下载的安装包移动过来mv apache-zookeeper-3.5.8-bin.tar.gz /app/zktst/#解压tar -zxvf apache-zookeeper-3.5.8-bin.tar.gz#删除安装包,节省服务器磁盘空间rm -rf apache-zookeeper-3.5.8-bin.tar.gz#把/app/zktst/apache-zookeeper-3.5.8-bin移动到/app/zktst/#再删除问价夹/apache-zookeeper-3.5.8-bincd /app/zktst/apache-zookeeper-3.5.8-binmv ./* ../ rm -rf apache-zookeeper-3.5.8-bin

做完之后的目录是这样的:

Zookeeper单机安装

3、启动zookeeper准备

#新建两个文件夹一个存数据,一个存日志mkdir {data,logs}#进到conf目录,把zoo_sample.cfg 复制一份改名为zoo.cfgcd conf/    cp zoo_sample.cfg zoo.cfg#然后配置文件更改如下[ conf]# grep -v ^"#" zoo.cfg tickTime=2000initLimit=10syncLimit=5dataDir=/app/zktst/datadataLogDir=/app/zktst/logsclientPort=2181

4、启动

#启动zookeeper,进去bin目录[ bin]# ./zkServer.sh startZooKeeper JMX enabled by defaultUsing config: /app/zktst/bin/../conf/zoo.cfgStarting zookeeper ... STARTED#查看状态[ bin]# ./zkServer.sh statusZooKeeper JMX enabled by defaultUsing config: /app/zktst/bin/../conf/zoo.cfgClient port found: 2181. Client address: localhost.Mode: standalone#查看日志,进去logs目录[ logs]# tail -f zookeeper-root-server-t1.out 2020-06-28 17:09:30,705 [myid:] - INFO  [main:] - Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory2020-06-28 17:09:30,707 [myid:] - INFO  [main:] - Configuring NIO connection handler with 10s sessionless connection timeout, 1 selector thread(s), 2 worker threads, and 64 kB direct buffers.2020-06-28 17:09:30,709 [myid:] - INFO  [main:] - binding to port 0.0.0.0/0.0.0.0:21812020-06-28 17:09:30,733 [myid:] - INFO  [main:] - zookeeper.snapshotSizeFactor = 0.332020-06-28 17:09:30,741 [myid:] - INFO  [main:] - Snapshotting: 0x0 to /app/zktst/data/version-2/snapshot.02020-06-28 17:09:30,744 [myid:] - INFO  [main:] - Snapshotting: 0x0 to /app/zktst/data/version-2/snapshot.02020-06-28 17:09:30,778 [myid:] - INFO  [main:] - Using checkIntervalMs=60000 maxPerMinute=100002020-06-28 17:10:46,179 [myid:] - INFO  [NIOWorkerThread-1:] - The list of known four letter word commands is : [{1936881266=srvr, 1937006964=stat, 2003003491=wchc, 1685417328=dump, 1668445044=crst, 1936880500=srst, 1701738089=envi, 1668247142=conf, -720899=telnet close, 2003003507=wchs, 2003003504=wchp, 1684632179=dirs, 1668247155=cons, 1835955314=mntr, 1769173615=isro, 1920298859=ruok, 1735683435=gtmk, 1937010027=stmk}]2020-06-28 17:10:46,179 [myid:] - INFO  [NIOWorkerThread-1:] - The list of enabled four letter word commands is : [[srvr]]2020-06-28 17:10:46,180 [myid:] - INFO  [NIOWorkerThread-1:] - Processing srvr command from /127.0.0.1:50786##日志无报错说明zk已经安排成功

zoo.cfg文件参数详解

tickTime这个时间是作为zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是说每个tickTime时间就会发送一个心跳。initLimit这个配置项是用来配置zookeeper接受客户端(这里所说的客户端不是用户连接zookeeper服务器的客户端,而是zookeeper服务器集群中连接到leader的follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过10个心跳的时间(也就是tickTime)长度后 zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 10*2000=20秒。syncLimit这个配置项标识leader与follower之间发送消息,请求和应答时间长度,最长不能超过多少个?tickTime的时间长度,总的时间长度就是5*2000=10秒。?dataDir zookeeper保存数据的目录,zookeeper将写数据的日志文件也保存在这个目录里;?logDir 日志文件目录,记录着zookeeper各种日志信息。?clientPort 默认端口号为2181