ZooKeeper 单节点部署

下载解压
进入官方下载地址:http://zookeeper.apache.org/releases.html#download 

解压到本地:

tar -zxf zookeeper-3.4.6.tar.gz
cd zookeeper-3.4.6


环境变量
执行 vim /etc/profile,添加环境变量:

export ZOOKEEPER_HOME=/usr/app/zookeeper-3.4.14
export PATH=$ZOOKEEPER_HOME/bin:$PATH

再执行 source /etc/profile , 使得配置的环境变量生效。


修改配置
必须创建 conf/zoo.cfg 文件,否则启动时会提示你没有此文件。

初次尝试,不妨直接使用 Kafka 提供的模板配置文件 conf/zoo_sample.cfg:

cp conf/zoo_sample.cfg conf/zoo.cfg

修改后完整配置如下:

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/log
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#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


配置参数说明:

tickTime:用于计算的基础时间单元。比如 session 超时:N*tickTime;
initLimit:用于集群,允许从节点连接并同步到 master 节点的初始化连接时间,以 tickTime 的倍数来表示;
syncLimit:用于集群, master 主节点与从节点之间发送消息,请求和应答时间长度(心跳机制);
dataDir:数据存储位置;
dataLogDir:日志目录;
clientPort:用于客户端连接的端口,默认 2181


启动服务
执行以下命令

bin/zkServer.sh start

执行此命令后,你将收到以下响应

JMX enabled by default
Using config: /Users/../zookeeper-3.4.6/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED


停止服务
可以使用以下命令停止 zookeeper 服务器。

bin/zkServer.sh stop

 

posted @ 2021-12-08 14:02  屠魔的少年  阅读(8)  评论(0)    收藏  举报