一、簡介: Zookeeper是一個分散式協調服務,提供的服務如下: 命名服務:類似於DNS,但僅對於節點 配置管理:服務配置信息的管理 集群管理:Dubbo使用Zookeeper實現服務治理 分散式鎖:選舉一個leader,這樣某一時刻只有一個服務在幹活,當leader出問題時釋放鎖,立即切到另一 ...
一、簡介:
Zookeeper是一個分散式協調服務,提供的服務如下:
命名服務:類似於DNS,但僅對於節點
配置管理:服務配置信息的管理
集群管理:Dubbo使用Zookeeper實現服務治理
分散式鎖:選舉一個leader,這樣某一時刻只有一個服務在幹活,當leader出問題時釋放鎖,立即切到另一個服務
二、下載:
三、偽分散式集群搭建:
1、進入C:\zookeeper-3.3.6\conf目錄,將zoo_sample.cfg拷貝成3份,分別為:zoo1.cfg、zoo2.cfg、zoo3.cfg
zoo1.cfg內容:
#心跳時間 tickTime=2000 #初始連接能容忍最多心跳次數 initLimit=10 #leader與follower之間的通信時長 syncLimit=5 #保存數據的目錄 dataDir=C:/zookeeper/zk1 #zk監聽埠號 clientPort=2181 # server.1=master:2888:3888 server.2=slave1:2889:3889 server.3=slave2:2890:3890
zoo2.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. dataDir=C:/zookeeper/zk2/ # the port at which the clients will connect clientPort=2182 server.1=master:2888:3888 server.2=slave1:2889:3889 server.3=slave2:2890:3890View Code
zoo3.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. dataDir=C:/zookeeper/zk3/ # the port at which the clients will connect clientPort=2183 server.1=master:2888:3888 server.2=slave1:2889:3889 server.3=slave2:2890:3890View Code
2、hosts配置
127.0.0.1 master 127.0.0.1 slave1 127.0.0.1 slave2
3、zk保存數據的目錄,zk1目錄新建myid的文件,內容為1,zk2目錄新建myid的文件,內容為2,以此類推
4、進入C:\zookeeper-3.3.6\bin目錄,將zkServer.cmd拷貝成3份,分別為:zkServer-1.cmd、zkServer-2.cmd、zkServer-3.cmd
zkServer-1.cmd內容:
@echo off REM Licensed to the Apache Software Foundation (ASF) under one or more REM contributor license agreements. See the NOTICE file distributed with REM this work for additional information regarding copyright ownership. REM The ASF licenses this file to You under the Apache License, Version 2.0 REM (the "License"); you may not use this file except in compliance with REM the License. You may obtain a copy of the License at REM REM http://www.apache.org/licenses/LICENSE-2.0 REM REM Unless required by applicable law or agreed to in writing, software REM distributed under the License is distributed on an "AS IS" BASIS, REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. REM See the License for the specific language governing permissions and REM limitations under the License. setlocal call "%~dp0zkEnv.cmd" set ZOOMAIN=org.apache.zookeeper.server.quorum.QuorumPeerMain set ZOOCFG=..\conf\zoo1.cfg echo on java "-Dzookeeper.log.dir=%ZOO_LOG_DIR%" "-Dzookeeper.root.logger=%ZOO_LOG4J_PROP%" -cp "%CLASSPATH%" %ZOOMAIN% "%ZOOCFG%" %* endlocal
zkServer-2.cmd和zkServer-3.cmd只是set ZOOCFG指定的cfg文件不一樣
5、啟動zkServer-1.cmd、zkServer-2.cmd、zkServer-3.cmd