天天看點

ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令

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環境操作

ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令
ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令
ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令
ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令

2.1.2 Mac OS操作

$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/目錄下,已經有了預設的配置檔案

ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令

配置[/usr/local/etc/zookeeper/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/var/run/zookeeper/data
# 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
      

在bin下有很多可執行檔案

ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令

3 常用指令

3.1 啟動

執行指令zkServer

ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令

zkServer status

ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令

zkServer start

ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令

3.2 檢視運作狀态

ZooKeeper分布式實戰(一) - 基本安裝配置1 概述2 下載下傳、安裝以及配置3 常用指令