歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> centos下安裝ZooKeeper

centos下安裝ZooKeeper

日期:2017/3/3 12:03:28   编辑:Linux技術
1.需求安裝ZooKeeper,metaQ2.下載http://zookeeper.apache.org/releases.html當前stable版是zookeeper-3.4.63.解壓tar –xf zookeeper-3.4.6.tar.gz解壓文件到"/usr/local/zookeeper-3.4.6".4.復制conf目錄下的zoo_sample.cfg,並命名為zoo.cfg5.修改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=/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.3export PATH=$ZOOKEEPER_HOME/bin:$PATH
export PATH

OH YEAH!!! 安裝完畢!安裝好了,啟動搞搞.1.啟動
zookeeper-3.4.6/bin/zkServer.sh start
2.輸入jps命令查看進程
1573 QuorumPeerMain1654 Jps
其中,QuorumPeerMain是zookeeper進程,啟動正常。3、查看狀態:zookeeper-3.4.3/bin/zkServer.sh status
-JMX enabled by defaultUsing config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone
4、啟動客戶端腳本:zookeeper-3.4.3/bin/zkCli.sh -server zookeeper:21815、停止zookeeper進程:zookeeper-3.4.3/bin/zkServer.sh stop參與:http://zookeeper.apache.org/doc/trunk/zookeeperStarted.html
Copyright © Linux教程網 All Rights Reserved