1. 程式人生 > >【zookeeper】zookeeper單機和叢集環境的搭建

【zookeeper】zookeeper單機和叢集環境的搭建

首先去官網下載zookeeper安裝包,本文采用3.4.6stable版本

tar命令解壓後的目錄結構如下:

[[email protected] zookeeper-3.4.6]# ll
total 1612
drwxr-xr-x  2 1000 1000    4096 Feb 20  2014 bin
-rw-rw-r--  1 1000 1000   82446 Feb 20  2014 build.xml
-rw-rw-r--  1 1000 1000   80776 Feb 20  2014 CHANGES.txt
drwxr-xr-x  2 1000 1000    4096 Jan 22 11:39 conf
drwxr-xr-x 10 1000 1000    4096 Feb 20  2014 contrib
drwxr-xr-x  2 1000 1000    4096 Feb 20  2014 dist-maven
drwxr-xr-x  6 1000 1000    4096 Feb 20  2014 docs
-rw-rw-r--  1 1000 1000    1953 Feb 20  2014 ivysettings.xml
-rw-rw-r--  1 1000 1000    3375 Feb 20  2014 ivy.xml
drwxr-xr-x  4 1000 1000    4096 Feb 20  2014 lib
-rw-rw-r--  1 1000 1000   11358 Feb 20  2014 LICENSE.txt
-rw-rw-r--  1 1000 1000     170 Feb 20  2014 NOTICE.txt
-rw-rw-r--  1 1000 1000    1770 Feb 20  2014 README_packaging.txt
-rw-rw-r--  1 1000 1000    1585 Feb 20  2014 README.txt
drwxr-xr-x  5 1000 1000    4096 Feb 20  2014 recipes
drwxr-xr-x  8 1000 1000    4096 Feb 20  2014 src
-rw-rw-r--  1 1000 1000 1340305 Feb 20  2014 zookeeper-3.4.6.jar
-rw-rw-r--  1 1000 1000     836 Feb 20  2014 zookeeper-3.4.6.jar.asc
-rw-rw-r--  1 1000 1000      33 Feb 20  2014 zookeeper-3.4.6.jar.md5
-rw-rw-r--  1 1000 1000      41 Feb 20  2014 zookeeper-3.4.6.jar.sha1
-rw-r--r--  1 root root   46852 Jan 22 11:42 zookeeper.out
我們進入conf目錄下新建zoo.cfg配置檔案,檔名隨便都行,但是預設是這個檔名,為什麼呢?

看zkEnv.sh就知道了

if [ "x$ZOOCFG" = "x" ]
then
    ZOOCFG="zoo.cfg"
fi

1、單機模式

檔案內容如下:
#the basic time unit in milliseconds used by zookeeper,it is used to do heartbeats and the min session timeout will be twice the tickTime
tickTime=2000
#the location to store the in-memory database snapshots and ,unless specified otherwise,the transaction log of updates to database
dataDir=/home/zookeeper/zkData
#the port to listen for client connections
clientPort=2181
至此,單機配置就結束了,下面可以啟動了
bin/zkServer.sh start
啟動完成後,通過如下命令連線上去:
bin/zkCli.sh -server serverIp:2181
當然你的客戶端肯定要裝個zk啦
[zk: localhost:2181(CONNECTED) 27] ll
ZooKeeper -server host:port cmd args
        connect host:port
        get path [watch]
        ls path [watch]
        set path data [version]
        rmr path
        delquota [-n|-b] path
        quit 
        printwatches on|off
        create [-s] [-e] path data acl
        stat path [watch]
        close 
        ls2 path [watch]
        history 
        listquota path
        setAcl path acl
        getAcl path
        sync path
        redo cmdno
        addauth scheme auth
        delete path [version]
        setquota -n|-b val path
至此,單機模式就結束了!

2、叢集模式

修改配置檔案如下:

#the basic time unit in milliseconds used by zookeeper,it is used to do heartbeats and the min session timeout will be twice the tickTime
tickTime=2000
#the location to store the in-memory database snapshots and ,unless specified otherwise,the transaction log of updates to database
dataDir=/home/zookeeper/zkData
#the port to listen for client connections
clientPort=2181
#timeouts zookeeper uses to limit the length of time the zookeeper servers in quorum have to connect to a leader
initLimit=5
#limits how far out of date a server can be from a leader
syncLimit=2
#With both of above timeouts, you specify the unit of time using tickTime. In this example, the timeout for initLimit is 5 ticks at 2000 milleseconds a tick, or 10 seconds.
server.1=192.168.11.176:2888:3888
server.2=192.168.11.177:2888:3888
server.3=192.168.11.178:2888:3888
The entries of the form server.X list the servers that make up the ZooKeeper service. When the server starts up, it knows which server it is by looking for the file myid in the data directory. That file has the contains the server number, in ASCII.
這句話的意思,server.X中的x是從dataDir路徑下的myid檔案來讀取的,所以我們要建立相應的myid檔案,內容分別是1,2,3

至此,叢集的配置已經完成了!

下面到各個節點機器上去啟動zookeeper

sh bin/zkServer.sh start
可以去看zookeeper.out的啟動日誌輸出

檢視節點狀態

[[email protected] zookeeper-3.4.6]# sh bin/zkServer.sh status
JMX enabled by default
Using config: /home/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: leader
[[email protected] zookeeper-3.4.6]# sh bin/zkServer.sh status
JMX enabled by default
Using config: /home/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
[[email protected] zookeeper-3.4.6]# sh bin/zkServer.sh status
JMX enabled by default
Using config: /home/zookeeper/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: follower
三個節點,一個leader,兩個follower

這裡補充一點:zookeeper的叢集必須得奇數個節點,因為zookeeper有個機制,當叢集中大於半數的節點掛了,整個zookeeper將停止服務,如果說是偶數臺的話,一半對一半,zookeeper很難判斷,所以zookeeper的叢集建議偶數臺搭建。

下面另起一個客戶端去連線zk叢集:

[[email protected] zookeeper-3.4.6]# sh bin/zkCli.sh -server 192.168.11.178:2181
Connecting to 192.168.11.178:2181
2015-01-22 14:41:08,947 [myid:] - INFO  [main:[email protected]] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2015-01-22 14:41:08,975 [myid:] - INFO  [main:[email protected]] - Client environment:host.name=com20.authentication
2015-01-22 14:41:08,975 [myid:] - INFO  [main:[email protected]] - Client environment:java.version=1.7.0_60
2015-01-22 14:41:08,989 [myid:] - INFO  [main:[email protected]] - Client environment:java.vendor=Oracle Corporation
2015-01-22 14:41:08,990 [myid:] - INFO  [main:[email protected]] - Client environment:java.home=/usr/java/jdk1.7.0_67/jre
2015-01-22 14:41:08,991 [myid:] - INFO  [main:[email protected]] - Client environment:java.class.path=/home/zookeeper/zookeeper-3.4.6/bin/../build/classes:/home/zookeeper/zookeeper-3.4.6/bin/../build/lib/*.jar:/home/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-log4j12-1.6.1.jar:/home/zookeeper/zookeeper-3.4.6/bin/../lib/slf4j-api-1.6.1.jar:/home/zookeeper/zookeeper-3.4.6/bin/../lib/netty-3.7.0.Final.jar:/home/zookeeper/zookeeper-3.4.6/bin/../lib/log4j-1.2.16.jar:/home/zookeeper/zookeeper-3.4.6/bin/../lib/jline-0.9.94.jar:/home/zookeeper/zookeeper-3.4.6/bin/../zookeeper-3.4.6.jar:/home/zookeeper/zookeeper-3.4.6/bin/../src/java/lib/*.jar:/home/zookeeper/zookeeper-3.4.6/bin/../conf:.:/usr/java/jdk1.7.0_67/lib:/usr/java/jdk1.7.0_67/lib/tools.jar:/usr/java/jdk1.7.0_67/lib/dt.jar:/usr/java/jdk1.7.0_67/jre/lib:/usr/java/jdk1.7.0_67/jre/lib/charsets.jar:/usr/java/jdk1.7.0_67/jre/lib/rt.jar
2015-01-22 14:41:08,991 [myid:] - INFO  [main:[email protected]] - Client environment:java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
2015-01-22 14:41:08,992 [myid:] - INFO  [main:[email protected]] - Client environment:java.io.tmpdir=/tmp
2015-01-22 14:41:08,993 [myid:] - INFO  [main:[email protected]] - Client environment:java.compiler=<NA>
2015-01-22 14:41:08,993 [myid:] - INFO  [main:[email protected]] - Client environment:os.name=Linux
2015-01-22 14:41:08,994 [myid:] - INFO  [main:[email protected]] - Client environment:os.arch=amd64
2015-01-22 14:41:08,995 [myid:] - INFO  [main:[email protected]] - Client environment:os.version=2.6.18-308.el5
2015-01-22 14:41:08,995 [myid:] - INFO  [main:[email protected]] - Client environment:user.name=root
2015-01-22 14:41:08,996 [myid:] - INFO  [main:[email protected]] - Client environment:user.home=/root
2015-01-22 14:41:08,996 [myid:] - INFO  [main:[email protected]] - Client environment:user.dir=/home/zookeeper/zookeeper-3.4.6
2015-01-22 14:41:09,000 [myid:] - INFO  [main:[email protected]] - Initiating client connection, connectString=192.168.11.178:2181 sessionTimeout=30000 [email protected]
Welcome to ZooKeeper!
2015-01-22 14:41:09,187 [myid:] - INFO  [main-SendThread(192.168.11.178:2181):[email protected]] - Opening socket connection to server 192.168.11.178/192.168.11.178:2181. Will not attempt to authenticate using SASL (unknown error)
JLine support is enabled
2015-01-22 14:41:09,243 [myid:] - INFO  [main-SendThread(192.168.11.178:2181):[email protected]] - Socket connection established to 192.168.11.178/192.168.11.178:2181, initiating session
[zk: 192.168.11.178:2181(CONNECTING) 0] 2015-01-22 14:41:09,481 [myid:] - INFO  [main-SendThread(192.168.11.178:2181):[email protected]] - Session establishment complete on server 192.168.11.178/192.168.11.178:2181, sessionid = 0x34b1057cbfa0000, negotiated timeout = 30000

WATCHER::

WatchedEvent state:SyncConnected type:None path:null

[zk: 192.168.11.178:2181(CONNECTED) 0] 
[zk: 192.168.11.178:2181(CONNECTED) 1] ls /
[zookeeper, zk_test]
[zk: 192.168.11.178:2181(CONNECTED) 2] get /zk_test
my_data
cZxid = 0x5
ctime = Thu Jan 22 13:52:58 CST 2015
mZxid = 0x5
mtime = Thu Jan 22 13:52:58 CST 2015
pZxid = 0x5
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 7
numChildren = 0
[zk: 192.168.11.178:2181(CONNECTED) 3] 
如果你的客戶端只是去連zk叢集,只需要解壓zk安裝包即可,使用命令直接可以連線,無需任何配置!

如遇任何問題,建議大家去官網參考,官網的永遠是權威!

共勉!

相關推薦

Redis單機叢集環境搭建

一、安裝單機版redis  1、可以自己去官網下載,當然也可以用課程提供的壓縮包 # yum install gcc # wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz # tar -xzvf tcl8.6.1-s

zookeeperzookeeper單機叢集環境搭建

首先去官網下載zookeeper安裝包,本文采用3.4.6stable版本 tar命令解壓後的目錄結構如下: [[email protected] zookeeper-3.4.6]# ll total 1612 drwxr-xr-x 2 1000 1000

ZooKeeper系列1.ZooKeeper單機版、偽叢集叢集環境搭建

ZooKeeper安裝模式主要有3種: 單機版(Standalone模式)模式:僅有一個ZooKeeper服務 偽叢集模式:單機多個ZooKeeper服務 叢集模式:多機多ZooKeeper服務 1 單機版(Standalone模式)安裝 ZooKeeper官網下載地址:http://zookeeper.

ZooKeeper 系列(二)—— Zookeeper單機環境叢集環境搭建

一、單機環境搭建         1.1 下載         1.2 解壓         1.3 配置環境變數         1.4 修改配置         1.5 啟動         1.6 驗證 二、叢集環境搭建         2.1 修改配置         2.2 標識節點       

ZooKeeper系列(二)—— Zookeeper 單機環境叢集環境搭建

一、單機環境搭建 1.1 下載 下載對應版本 Zookeeper,這裡我下載的版本 3.4.14。官方下載地址:https://archive.apache.org/dist/zookeeper/ # wget https://archive.apache.org/dist/zookeeper/zookeep

zookeeper-3.4.10分散式叢集環境搭建

初始叢集狀態 機器名 IP 作用 linux系統 master 192.168.218.133   CentOS-6.9-x86_64-bin-D

命令Ubuntu設定檢視環境變數

轉自【Ubuntu】Ubuntu設定和檢視環境變數 檢視環境變數 env env命令是environment的縮寫,用於列出所有的環境變數 export 單獨使用export命令也可以像env列出所有的環境變數,不過export命令還有其他額外的功能 echo $PATH echo $PAT

UbuntuUbuntu設定檢視環境變數

檢視環境變數檢視環境變數有三個命令envenv命令是environment的縮寫,用於列出所有的環境變數export單獨使用export命令也可以像env列出所有的環境變數,不過export命令還有其他額外的功能echo $PATHecho $PATH用於列出變數PATH的值,裡面包含了已新增的目錄設定方式設

ARVuforia之unity3d 開發環境搭建

AR Vurforia 一、Unity3d環境搭建 下載安裝包地址:https://developer.vuforia.com/downloads/sdk Download for Android Download for iOS Download for UWP Download Unity Ext

VUEMac下vue 開發環境搭建,以及目錄結構

1 安裝Node.js    參看 node.js環境安裝   http://www.cnblogs.com/richerdyoung/p/7265786.html   2 安裝淘寶映象 sudo npm ins

Redis主從複製叢集環境搭建

Redis主從複製和叢集配置   redis主從複製 概述 1、redis的複製功能是支援多個數據庫之間的資料同步。一類是主資料庫(master)一類是從資料庫(slave),主資料庫可以進行讀寫操作,當發生寫操作的時候自動將資料同步到從資料庫,而從資料庫一般是

Kafka 單機分散式環境搭建與案例使用

實驗環境: 1、Ubuntu Server 16.04 2、kafka_2.11-0.11.0.0 一、單機環境搭建 官方參考文章: 1、下載和解壓安裝包 這裡下載了zookeeper和kafaka兩個安裝包,下載地址:

zookeeperzookeeper介紹及安裝叢集配置

1.什麼是zookeeper ?     zookeeper 英文直譯是動物管理員,試想下,動物園裡有很多動物,如果沒有動物管理員去做管理的話,各種動物混在一起很可能出現打架問題,疾病,髒,等等一系列問題,這個時候就需要有個主人去把這些動物統一管理起來,zookeeper其實

Win7下Zookeeper 單機叢集搭建可行版

Win7下Zookeeper 單機與叢集的搭建【可行版】 2014年04月08日 17:35:32 單向街的夏天 閱讀數:3218更多 個人分類: 大資料處理 版權宣告:本文為博主原創文章,未經博主允許不得轉載。 https://blog.csdn.net/wenzhibinbin_p

實踐Zookeeper c client原始碼剖析——不同event觸發的條件時機

watcher,watcherCtx));//關鍵語句:add_stat_completion函式往zh->sent_requests(即傳送請求佇列)中新增非同步完成資料結構物件(包括非同步回撥型別COMPLETION_STAT和回撥函式地址,同時該物件中還儲存著當關注的事件發生時要回調的watch

ZooKeeper詳細介紹使用第一節

一、分散式協調技術 在給大家介紹ZooKeeper之前先來給大家介紹一種技術——分散式協調技術。那麼什麼是分散式協調技術?那麼我來告訴大家,其實分散式協調技術 主要用來解決分散式環境當中多個程序之間的同步控制,讓他們有序的去訪問某種臨界資源,防止造成"髒資料"的後果。這時,有人可能會說這個簡單,寫一個調 度

ZookeeperZookeeper原始碼環境搭建出現的問題

一、ant eclipse 時提示Connection reset    從GitHub下載下來的壓縮包不是eclipse版本的工程,我們需要使用ant eclipse命令編譯成eclipse版本的專案,執行過程提示Connection reset 是編譯檔案build.xm

2zookeeper節點搭建(單節點模式 || docker搭建zookeeper叢集 [bridge模式|host模式] )

分散式理論知識 CAP原理 C(Consistency):一致性,這裡指的是有效時間內資料的強一致性。 A(Availability):可用性,要求即便系統故障,也能在有效的時間內返回結果(成功或失敗) P(Partition tolera

zookeeper 單機. 叢集環境搭建

zookeeper分散式系統中面臨的很多問題, 如分散式鎖,統一的命名服務,配置中心,叢集的管理Leader的選舉等 環境準備 分散式系統中各個節點之間通訊,Zookeeper保證了這個過程中 資料的唯一性,安全可靠 官網下載地址 修改配置檔案 將/conf/zoo_sample.cfg 修改成

Zookeeper學習---zookeeper 選舉機制介紹

erp change 交換 內容 數值 所有 ase 一輪 eval 【原文】https://www.toutiao.com/i6593162565872779784/ zookeeper集群 配置多個實例共同構成一個集群對外提供服務以達到水平擴展的目的,每個服務器上的數據