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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值