zoomkeeper java使用_Zoonkeeper安装、集群配置 [Mac]

Zoonkeeper安装、集群配置 [Mac]

1. 下载Zoonkeeper

进去后选择你需要的版本,然后下载对应的压缩文件到本地,比如我选择的是当前最新的版本

zookeeper-3.5.4-beta

2. 解压安装 [单服务非集群配置]

打开终端进入到压缩文件 zookeeper-3.5.4.gz 文件对应的目录,然后解压

$ cd Download //进入到目录

$ tar -xzf zookeeper-3.5.4.gz //解压文件

$ cd zookeeper-3.5.4-beta/conf //进入配置目录

$ mv zoo_sample.cfg zoo.cfg //更改默认配置文件名称

$ vi zoo.cfg //编辑配置文件,自定义dataDir

修改配置

关于配置文件说明:

文件名可以任意,不是非得改为zoo.cfg

tickTime: zookeeper中使用的基本时间单位, 毫秒

dataDir: 内存数据快照的保存目录;如果没有自定义Log也使用该目录

clientPort: 监听Cli连接的端口号

配置文件 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=/tmp/zookeeper

# 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

服务启动

注意:服务启动前需要本机安装好 java 运行环境

$ cd zookeeper-3.5.4-beta/bin //进入目录

// 启动服务,也可以不加 -foreground 直接用start也可以启动

// -foreground 表示前台启动,能够在终端打印启动信息,如果出错能看到报错信息

$ ./zkServer.sh start-foreground

3. 解压安装 [多服务集群配置]

打开终端进入到压缩文件 zookeeper-3.5.4.gz 文件对应的目录,然后解压

$ cd Download //进入到目录

$ tar -xzf zookeeper-3.5.4.gz //解压文件

$ cd zookeeper-3.5.4-beta/conf //进入配置目录

$ mv zoo_sample.cfg zoo.cfg //更改默认配置文件名称

$ vi zoo.cfg //编辑配置文件,自定义dataDir

新建一个文件夹取名 zk-cluster ,名字你可以自己定义

然后移动上面 第1步解压的 zookeeper-3.5.4-beta 文件到 zk-cluster 目录,并且新复制出另外的两份来

现在有三个服务文件夹,然后分别取名 zk3.5.4-8001、 zk3.5.4-8002、zk3.5.4-8003,我现在列一下整个需要的目录结构:

/zk-cluster/

|-- zk3.5.4-8001

|-- zk3.5.4-8002

|-- zk3.5.4-8003

`-- zk-data # 存放每个服务数据和日志的总目录

|-- 8001

|-- logs

|-- data

|-- myid # 配置文件,文件名称myid无后缀,内容为数字1

|-- 8002

|-- logs

|-- data

|-- myid # 配置文件,文件名称myid无后缀,内容为数字2

|-- 8003

|-- logs

|-- data

|-- myid # 配置文件,文件名称myid无后缀,内容为数字3

分别修改zk3.5.4-8001、 zk3.5.4-8002、zk3.5.4-8003里面的 conf/zoo.cfg 配置文件,8001的配置文件内容如下:

# 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=/Users/leitan/Downloads/zk-cluster/zk-data/8001/data

dataLogDir=/Users/leitan/Downloads/zk-cluster/zk-data/8001/logs

# the port at which the clients will connect

clientPort=3001

# 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

# Cluster Zookeeper Server Address 下面配置不需要修改 要注意的就是,下面server.number (number是1、2、3)分别对应myid中的内容,

# zookeeper也是通过server后面的数字以及dataDir下的myid内容来判断zookeeper集群的关系的(哪个server对应哪个地址),然后后面两个端

# 口号,一个是跟服务器发送链接的端口,另一个是接受服务器链接的端口

server.1=127.0.0.1:8001:9001

server.2=127.0.0.1:8002:9002

server.3=127.0.0.1:8003:9003

配置说明:

dataDir 数据目录

dataLogDir 日志目录

clientPort 服务端口

上面这三个都配置成第4步目录列表里的各自的目录,没有的需要自己去新建

服务集群启动

进入到对应服务的bin目录,然后把三个目录下的服务依次启动即可

$ ./zkServer.sh start-foreground

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值