前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >ZooKeeper分布式实战(一) - 基本安装配置

ZooKeeper分布式实战(一) - 基本安装配置

作者头像
JavaEdge
修改2025-03-11 10:54:27
修改2025-03-11 10:54:27
4580
举报
文章被收录于专栏:JavaEdgeJavaEdge

1 概述

1.1 zookeeper 简介

  • 中间件,提供协调服务
  • 作用于分布式系统,发挥其优势,为大数据服务
  • 支持 Java,提供 Java 和 C语言的客户端 API

1.2 什么是分布式系统

  • 很多台计算机组成一个整体,一个整体一致对外并且处理同一请求
  • 内部的每台计算机都可以相互通信(REST/RPC)
  • 客户端到服务端的一次请求到响应结束会经历多台计算机

1.3 分布式系统的瓶颈

1.3.1 zookeeper 的特性
  • 一致性 数据一致性,数据按照顺序分批入库
  • 原子性 事务要么成功要么失败,不会局部化
  • 单一视图 客户端连接集群中的任一 zk 节点,数据都是一致的
  • 可靠性 每次对 zk的操作状态都会保存在服务端
  • 实时性 客户端可以读取到 zk 服务端的最新数据

2 下载、安装以及配置

安装 JDK

2.1 单机模式

2.1.1 Linux环境操作

linux etc/profile:

2.1.2 Mac OS操作
代码语言:bash
复制
$brew install zookeeper
==> Downloading https://homebrew.bintray.com/bottles/zookeeper-3.4.6_1.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring zookeeper-3.4.6_1.mavericks.bottle.2.tar.gz
==> Caveats
To have launchd start zookeeper at login:
  ln -sfv /usr/local/opt/zookeeper/*.plist ~/Library/LaunchAgents
Then to load zookeeper now:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.zookeeper.plist
Or, if you don't want/need launchctl, you can just run:
  zkServer start
==> Summary

安装成功后,在/usr/local/etc/zookeeper/目录,已有默认配置文件

代码语言:bash
复制
$ cd /usr/local/etc/zookeeper/
$ ls
zoo.cfg

配置/usr/local/etc/zookeeper/zoo.cfg 文件

代码语言:bash
复制
# 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/var/run/zookeeper/data
dataLogDir=/usr/local/var/run/zookeeper/log
# the port at which the clients will connect
clientPort=2181

bin下的可执行文件:

手动下载

下载tar包解压,推荐使用3.5.x,不要使用3.6以高版本,和JDK1.8冲突,事到如今,也不要直接brew install zookeeper--默认会下载最高版本!很难用!

下载二进制安装包:

https://www.apache.org/dyn/closer.lua/zookeeper/zookeeper-3.5.10/apache-zookeeper-3.5.10-bin.tar.gz

解压缩:

代码语言:bash
复制
tar -zxvf apache-zookeeper-3.5.10-bin.tar.gz

将conf目录下的zoo_sample.cfg文件更名为zoo.cfg,简单修改配置文件,自定义设置数据文件目录和日志文件目录。

新建文件夹data和log:

代码语言:bash
复制
$ zookeeper-3.5.10 ll
total 48
-rw-r--r--@ 1 sss admin 11K 5 19 2022 LICENSE.txt
-rw-r--r--@ 1 sss admin 432B 5 19 2022 NOTICE.txt
-rw-r--r--@ 1 sss admin 1.5K 5 19 2022 README.md
-rw-r--r--@ 1 sss admin 1.3K 5 19 2022 README_packaging.txt
drwxr-xr-x@ 13 sss admin 416B 5 19 2022 bin
drwxr-xr-x@ 5 sss admin 160B 3 8 17:49 conf
drwxr-xr-x 2 sss admin 64B 3 8 17:50 data
drwxr-xr-x@ 21 sss admin 672B 5 29 2022 docs
drwxr-xr-x 54 sss admin 1.7K 3 8 17:46 lib
drwxr-xr-x 2 sss admin 64B 3 8 17:50 log

修改路径地址:dataDir 和 dataLogDir

代码语言:properties
复制
# 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=/Volumes/doc/zookeeper-3.5.10/data
dataLogDir=/Volumes/doc/zookeeper-3.5.10/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
配置环境变量

sudo vi ~/.bash_profile

代码语言:properties
复制
export ZK_HOME=/Volumes/doc/zookeeper-3.5.10/
export PATH=$PATH:$ZK_HOME/bin
代码语言:bash
复制
$ cd bin
$ bin zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /Volumes/doc/zookeeper-3.5.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED

3 常用命令

3.1 启动

执行命令zkServer:

代码语言:bash
复制
$ zkServer 
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Usage: ./zkServer.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}

zkServer status

代码语言:bash
复制
$ zkServer status
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Mode: standalone

zkServer start

代码语言:bash
复制
$ zkServer start
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Starting zookeeper ... STARTED
代码语言:bash
复制
brew services start zookeeper

brew services restart zookeeper

3.2 查看运行状态

代码语言:bash
复制
$ zkServer status
ZooKeeper JMX enabled by default
Using config: /usr/local/etc/zookeeper/zoo.cfg
Mode: standalone
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/09/01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1 概述
    • 1.1 zookeeper 简介
    • 1.2 什么是分布式系统
    • 1.3 分布式系统的瓶颈
      • 1.3.1 zookeeper 的特性
  • 2 下载、安装以及配置
    • 2.1 单机模式
      • 2.1.1 Linux环境操作
      • 2.1.2 Mac OS操作
  • 3 常用命令
    • 3.1 启动
    • 3.2 查看运行状态
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档