1.需求html
安裝ZooKeeper,metaQapache
2.下載服務器
http://zookeeper.apache.org/releases.htmlide
當前stable版是zookeeper-3.4.6oop
3.解壓ui
tar –xf zookeeper-3.4.6.tar.gzthis
解壓文件到"/usr/local/zookeeper-3.4.6".spa
4.複製conf目錄下的zoo_sample.cfg,並命名爲zoo.cfgcode
5.修改zoo.cfg配置文件server
# 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=/datatmp/zookeeper/data
dataLogDir=/datatmp/zookeeper/logs
# 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
#2888,3888 are election port
server.1=zookeeper:2888:38888
其中,2888端口號是服務之間通訊的端口,而3888是;zookeeper與其餘應用程序通訊的端口.而zookeeper是在hosts中已映射了本機的IP.
initLimit:這個配置項是用來配置Zookeeper接受客戶端(這裏所說的客戶端不是用戶鏈接Zookeeper服務器的客戶端,而是Zookeeper服務器集羣中鏈接到 Leader 的 Follower 服務器)初始化鏈接時最長能忍受多少個心跳時間間隔數。當已經超過 10 個心跳的時間(也就是 tickTime)長度後 Zookeeper 服務器尚未收到客戶端的返回信息,那麼代表這個客戶端鏈接失敗。總的時間長度就是 5*2000=10 秒。
syncLimit:這個配置項標識 Leader 與 Follower 之間發送消息,請求和應答時間長度,最長不能超過多少個 tickTime 的時間長度,總的時間長度就是 2*2000=4 秒。
server.A=B:C:D:其中 A 是一個數字,表示這個是第幾號服務器;B 是這個服務器的 ip 地址;C 表示的是這個服務器與集羣中的 Leader 服務器交換信息的端口;D 表示的是萬一集羣中的 Leader 服務器掛了,須要一個端口來從新進行選舉,選出一個新的 Leader,而這個端口就是用來執行選舉時服務器相互通訊的端口。若是是僞集羣的配置方式,因爲 B 都是同樣,因此不一樣的 Zookeeper 實例通訊端口號不能同樣,因此要給它們分配不一樣的端口號。
6.建立dataDir參數指定的目錄(這裏指的是「 /datatmp/zookeeper/data」),並在目錄下建立文件,命名爲「myid」。
7.編輯「myid」文件,並在對應的IP的機器上輸入對應的編號。如在zookeeper上,「myid」文件內容就是1。因爲本次只在單點上進行安裝配置,因此只有一個server.1。若還有其餘服務器,好比地址爲192.168.1.102,則在zoo.cfg文件中還需加入server.2=192.168.1.102:2888:3888。那麼myid文件在192.168.1.102服務器上的內容就是2。至此,若是是多服務器配置,就須要將zookeeper-3.4.3目錄拷貝到其餘服務器,而後按照上述的方法修改myid。
8.在/etc/profile文件中設置PATH
修改profile文件:
sudo vi /etc/profile
export ZOOKEEPER_HOME=/home/hadooptest/zookeeper-3.4.3 export PATH=$ZOOKEEPER_HOME/bin:$PATH export PATH
OH YEAH!!! 安裝完畢!
安裝好了,啓動搞搞.
1.啓動
zookeeper-3.4.6/bin/zkServer.sh start
1573 QuorumPeerMain
1654 Jps
其中,QuorumPeerMain是zookeeper進程,啓動正常。
三、查看狀態:zookeeper-3.4.3/bin/zkServer.sh status
- JMX enabled by default Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg Mode: standalone
四、啓動客戶端腳本:zookeeper-3.4.3/bin/zkCli.sh -server zookeeper:2181
五、中止zookeeper進程:zookeeper-3.4.3/bin/zkServer.sh stop
參與: