Zookeeper简单安装使用

zookeeper对外提供分布式协调服务,我们的分布式应用,通过zookeeper可以很轻松的实现协调调度

zookeeper经常组成集群提供服务,如下图所示,集群内各主机之间互联互通,通过选举产生leader,即使有主机因意外宕机,剩余的主机也能选举出一台作为leader继续对外提供服务

更多细节可以查看apach的官方描述

我们有时候自己本地调试服务需要zookeeper提供服务,但是有没有太多资源使用,可以选择安装单机版zookeeper

准备工作:安装Java环境,配置path

1.下载zookeeper安装包,本次使用3.6.0版本,可以去官网下载自己需要的版本

wget https://downloads.apache.org/zookeeper/zookeeper-3.6.0/apache-zookeeper-3.6.0-bin.tar.gz

2.解压tar包

tar -zxvf apache-zookeeper-3.6.0-bin.tar.gz 

3.进入解压好的文件夹,并复制一份配置文件

cd /usr/local/zookeeper/apache-zookeeper-3.6.0/conf
cp zoo_sample.cfg zoo.cfg

4.编辑配置文件

vi coo.cfg

配置文件如下,修改dataDir和dataLogDir

其中dataDir里需要创建一个myid文件,里面配置的当前服务的id编号,本例子里把myid设为了2181

dataLogDir里是日志文件,如果缺少目录文件夹及文件,请自己补全

# 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/apache-zookeeper-3.6.0/data
dataLogDir=/usr/local/zookeeper/apache-zookeeper-3.6.0/logs

# 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

## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true

5.启动zookeeper

/usr/local/zookeeper/apache-zookeeper-3.6.0/bin/zkServer.sh start

启动成功显示如下

/usr/local/jdk1.8.0_251/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/apache-zookeeper-3.6.0/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

6.如果报Java环境的错误就进入/usr/local/zookeeper/apache-zookeeper-3.6.0/bin文件夹修改启动文件

在#!/usr/bin/env bash下添加jdk路径,如果启动不报错可以不配置这项
 

#!/usr/bin/env bash
export=/usr/local/jdk1.8.0_251/bin:$PATH

 

回答: ZooKeeper是一个用于分布式应用程序的开源协调服务。它可以用作配置中心、高可用协调服务以及分布式锁的开发工具。在Windows环境下安装ZooKeeper可以按照以下步骤进行操作:首先,从官网下载ZooKeeper安装包,并解压进入bin目录。然后,双击执行zkServer.cmd文件,如果遇到闪退,可以修改命令文件,在最后添加暂停命令pause,再次双击执行。也可以通过命令行执行start ZooKeeper命令。接下来,需要创建zoo.cfg文件,可以直接复制一份进行使用。最后,启动ZooKeeper服务后,可以通过执行zkCli.cmd命令启动客户端进程,并进行简单的测试使用。\[2\]在Linux环境下安装ZooKeeper的步骤类似,需要上传并解压tar文件,配置文件,然后启动ZooKeeper服务。\[1\]总的来说,ZooKeeper安装使用相对简单,但是对于分布式应用程序的开发和理解来说,学习和熟练使用ZooKeeper是十分有必要的。\[3\] #### 引用[.reference_title] - *1* *2* [zookeeper安装使用(win+linux)](https://blog.csdn.net/suixinfeixiangfei/article/details/122147864)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [安装以及简单使用zookeeper](https://blog.csdn.net/qq_31960623/article/details/121201392)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值