1. 程式人生 > >zookeeper 3.4.9配置

zookeeper 3.4.9配置


1、首先肯定是從官網下載相應的tar包,並解壓

  網址:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz

  解壓:tar -zxvf zookeeper-3.4.9.tar.gz

2、新增環境變數

export ZOOKEEPER_HOME=/usr/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin

3、修改配置檔案

cd   /usr/zookeeper/conf ,將zoo_sample.cfg複製為zoo.cfg,並修改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/zookeeper/data
dataLogDir=/var/log/zookeeper
# 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
server.1=rdb01:2888:3888
server.2=rdb02:2888:3888
server.3=rdb03:2888:3888

在這裡需要注意zoo.cfg的配置檔案中的dataDir和dataLogDir的路徑當中的資料夾必須要已存在,否則後面啟動zkServer服務的時候會失敗。

4、在dataDir對應的路徑資料夾下(我這裡是zkdata資料夾),建立一個myid的檔案,並在該檔案中輸入對應叢集各節點的id,我這裡對應的是hadoop1對應的就是1,這個是與1
server.1=rdb01:2888:3888對應的。各個節點分別輸入對應的id值即可。

5、啟動zkServer
在各節點上執行:zkServer.sh start   並通過jps可以看到:啟動了QuorumpeerMain程序。
[[email protected]
conf]# jps 9904 QuorumPeerMain 9987 Jps 6950 NodeManager 3943 DataNode 9657 NameNode 6847 ResourceManager

6、此時可以通過zkServer.sh  status 命令來檢視節點的啟動狀態。
這裡需要注意點,只有當至少啟動了三個節點之後,該命令才會產生結果。否則會顯示:zookeeper Error contacting service. It is probably not running錯誤
當你啟動了至少三個節點之後,執行該命令可以看到:
[[email protected] data]# zkServer.sh  status
ZooKeeper JMX enabled by default
Using config: /usr/zookeeper/bin/../conf/zoo.cfg
Mode: leader

[[email protected] conf]# zkServer.sh  status
ZooKeeper JMX enabled by default
Using config: /usr/zookeeper/bin/../conf/zoo.cfg
Mode: follower

[[email protected] data]# zkServer.sh  status
ZooKeeper JMX enabled by default
Using config: /usr/zookeeper/bin/../conf/zoo.cfg
Mode: follower

7、關閉zookeeper服務
zkServer.sh stop  關閉zkServer.sh restart  重啟