ZooKeeper安装

ZooKeeper是一种分布式协调服务,用于管理大型主机。在分布式环境中协调和管理服务是一个复杂的过程,ZooKeeper通过其简单的架构和API解决了这个问题。 它是Hadoop和Hbase的重要组件,同时还能使用Java和C的接口。
ZooKeeper典型的应用程序:Apache Hadoop、Apache HBase、Apache Solr

1. 下载ZoopKeeper

使用的版本是 zookeeper-3.4.11.tar.gz
官网:https://zookeeper.apache.org
清华大学镜像节点:https://mirrors.tuna.tsinghua…

windows下载解压就可以了
Linux安装:

$ wget http://www-eu.apache.org/dist/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz # 下载zookeeper软件压缩包
$ tar -zxvf zookeeper-3.4.11.tar.gz # 解压zookper压缩包

2. 修改配置文件

复制 confzoo_sample.cfg 文件,并改名为 zoo.cfg(zookeeper默认使用zoo.cfg配置文件)。主要修改 dataDir、 dataLogDir 两个参数

# The number of milliseconds of each tick
# 每次心跳的间隔时间,单位是毫秒
# ZK中所有时间都是以这个时间单元为基础,进行整数倍配置的。例如,session的最小超时时间是2*tickTime。
tickTime=2000

# The number of ticks that the initial synchronization phase can take
# Follower在启动过程中,会从Leader同步所有最新数据,然后确定自己能够对外服务的起始状态。Leader允许F在 initLimit 时间内完成这个工作。
initLimit=10

# The number of ticks that can pass between sending a request and getting an acknowledgement
# 在运行过程中,Leader负责与ZK集群中所有机器进行通信,例如通过一些心跳检测机制,来检测机器的存活状态
syncLimit=5

# the directory where the snapshot is stored. do not use /tmp for storage, /tmp here is just example sakes. 
# 存储快照文件snapshot的目录。默认情况下,事务日志也会存储在这里。建议同时配置参数dataLogDir, 事务日志的写性能直接影响zk性能。
dataDir=D:/dubbo/zookeeper/data

# 事务日志输出目录。尽量给事务日志的输出配置单独的磁盘或是挂载点,这将极大的提升ZK性能。
dataLogDir=D:/dubbo/zookeeper/dataLog  

# the port at which the clients will connect 
# 客户端连接server的端口,即对外服务端口,一般设置为2181吧。
clientPort=2181


# the maximum number of client connections.
# increase this if you need to handle more clients
# 单个客户端与单台服务器之间的连接数的限制,是ip级别的,默认是60,如果设置为0,那么表明不作任何限制。
#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

3. 启动ZooKeeper服务


```
# windows:
./bin/zkServer.cmd  # 启动ZooKeeper服务
./bin/zkCli.cmd 127.0.0.1:2181 # 测试连接是否正常
./bin/zkCli.sh # 打开ZooKeeper命令行界面(CLI),之后可以对 znode 节点进行操作

netstat -aon|findstr "2181" # 查看ZooKeeper端口监听情况



# Linux:
$ ./bin/zkServer.sh start # 启动ZooKeeper服务器,会有一个QuorumPeerMain进程
$ ./bin/zkServer.sh stop  # 停止zookeeper服务器
$ ./bin/zkCli.sh 127.0.0.1:2181 # 测试连接是否正常
$ ./bin/zkCli.sh # 打开ZooKeeper命令行界面(CLI),之后可以对 znode 节点进行操作

$ netstat -anp | grep 2181 # 查看ZooKeeper端口监听情况
```
    原文作者:Developer
    原文地址: https://segmentfault.com/a/1190000014540765
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞