ZooKeeper安裝 及 分散式搭建
下載映象地址(3.4.9):
http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
解壓
tar xzvf zookeeper-3.4.9.tar.gz
解壓後移至 /usr/local 目錄下
修改配置檔案
${ZOOKEEPER_HOME}/conf/zoo_sample.cfg
# The number of milliseconds of each tick
# session的會話時間 時間是毫秒 tickTime=2000 # The number of ticks that the initial # synchronization phase can take
# 伺服器啟動後 slave與master進行啟動的時間
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
#master與slave的心跳時間
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
# 儲存zookeeper的資料與快照 dataDir=/tmp/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
配置偽分散式複製 cp zoo_sample.cfg zoo1.cfg
修改zoo1.cfg檔案
server.1=master:2888:3888
server.2=master:2889:3889
server.3=master:2890:3890
建立資料儲存目錄並配置zoo1.cfg
dataDir=/home/hadoop/tmp/zookeeper/zk1
複製第一臺機器的配置到第二臺 cp zoo1.cfg zoo2.cfg
修改配置檔案(修改資料儲存地址與伺服器埠,不能跟第一臺衝突)
# example sakes.
dataDir=/home/hadoop/tmp/zookeeper/zk2
# the port at which the clients will connect
clientPort=2182
同理複製第三臺伺服器的配置 cp zoo2.cfg zoo3.cfg,修改配置
在dataDir指定的目錄下,建立myid檔案
cd /home/hadoop/tmp/zookeeper/zk1
cd /home/hadoop/tmp/zookeeper/zk2
cd /home/hadoop/tmp/zookeeper/zk3
echo "1" >> myid
echo "2" >> myid
echo "3" >> myid
啟動zookeeper
./zkServer.sh start /usr/local/zookeeper-3.4.9/conf/zoo1.cfg
./zkServer.sh start /usr/local/zookeeper-3.4.9/conf/zoo2.cfg
./zkServer.sh start /usr/local/zookeeper-3.4.9/conf/zoo3.cfg
檢視zookeeper
./zkServer.sh status /usr/local/zookeeper-3.4.9/conf/zoo1.cfg
./zkServer.sh status /usr/local/zookeeper-3.4.9/conf/zoo2.cfg
./zkServer.sh status /usr/local/zookeeper-3.4.9/conf/zoo3.cfg
停止zookeeper
./zkServer.sh stop /usr/local/zookeeper-3.4.9/conf/zoo1.cfg
./zkServer.sh stop /usr/local/zookeeper-3.4.9/conf/zoo2.cfg
./zkServer.sh stop /usr/local/zookeeper-3.4.9/conf/zoo3.cfg
遇到的問題;
檢視zookeeper日誌 目錄 /usr/local/zookeeper/bin/zookeeper.out
此時需要檢視下 hostname 將cfg檔案裡的master給為自己的hostname主機名
server.1=kakashi:2888:3888
server.2=kakashi:2889:3889
server.3=kakashi:2890:3890
這樣就可以運行了
配置真分散式
配置真分散式clientport不需要修改,只需要修改zoo.cfg下的伺服器,埠都一樣不動,只需要改下主機名即可。
server.1=master:2888:3888
server.2=slave1:2888:3888
server.3=slave2:2888:3888
檢視啟動狀態 jps ,三臺機器全部啟動