Zookeeper 及其安裝配置和啟動
阿新 • • 發佈:2019-02-08
Zookeeper 為分散式系統提供一次性的服務,管理和協調分散式系統的工作,保證系統的高有效性。為什麼需要它?因為分散式系統很容易出錯,特別是在處理競爭和死鎖的過程中。
提供的功能包括:配置維護、名字服務、分散式同步、組服務等。
Client就是分散式系統中的節點,他們可以在ZooKeeper中設定監控,如果ZooKeeper中的目錄節點儲存的資料修改了,就會通知client。 設計目標:
initLimit=5
syncLimit=2
dataDir=/var/lib/zookeeperdata/1
server.1=localhost:2888:3888 server.2=localhost:2889:3889 server.3=localhost:2890:3890 各個引數的意義:
修改:dataDir=/var/lib/zookeeperdata/2 修改:clientPort=2182 配置第三個: # cp zoo1.cfg zoo3.cfg
修改:dataDir=/var/lib/zookeeperdata/3 修改:clientPort=2183
建立相應的dataDir目錄和myid檔案: # cd /var/lib # mkdir zookeeperdata # cd zookeeperdata # mkdir 1 # mkdir 2
# mkdir 3
# echo "1" > 1/myid # echo "2" > 2/myid
# echo "3" > 3/myid
啟動ZooKeeper: # cd <ZOOKEEPER_HOME> # bin/zkServer.sh start ./conf/zoo1.cfg # bin/zkServer.sh start ./conf/zoo2.cfg # bin/zkServer.sh start ./conf/zoo3.cfg 啟動結果: JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo1.cfg
Starting zookeeper ... STARTED
JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo2.cfg
Starting zookeeper ... STARTED
JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo3.cfg
Starting zookeeper ... STARTED 檢視狀態: 用jps命令檢視程序: # jps 24617 QuorumPeerMain (這個就是zookeeper程序) /opt/app/zookeeper/bin/zkServer.sh status zoo1.cfg
JMX enabled by default Using config: /opt/app/zookeeper/bin/../conf/zoo1.cfg Error contacting service. It is probably not running. 說明有錯誤,檢視日誌檔案: # cd <zookeeper_home> # less zookeeper.out java.net.BindException: 地址已在使用 殺掉當前程序: # kill -9 24617 再重啟那三個例項後,檢視狀態: # /opt/app/zookeeper/bin/zkServer.sh status zoo1.cfg
JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo1.cfg
Mode: follower
# /opt/app/zookeeper/bin/zkServer.sh status zoo2.cfg
JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo2.cfg
Mode: leader
# /opt/app/zookeeper/bin/zkServer.sh status zoo3.cfg
JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo3.cfg
Mode: follower 一切正常! # echo mntr | nc localhost 2181
Client就是分散式系統中的節點,他們可以在ZooKeeper中設定監控,如果ZooKeeper中的目錄節點儲存的資料修改了,就會通知client。 設計目標:
- 簡單
- 可複製
- 20個搜尋引擎伺服器:每一個負責總索引中的一部分的搜尋任務
- 2個總伺服器(主備各一個):負責向搜尋引擎伺服器發出搜尋請求,併合並結果
- 1個web伺服器:向總伺服器傳送搜尋請求
server.1=localhost:2888:3888 server.2=localhost:2889:3889 server.3=localhost:2890:3890 各個引數的意義:
- tickTime:心跳檢測的時間間隔(毫秒),預設:2000
- clientPort:其他應用(比如solr)訪問ZooKeeper的埠,預設:2181
- initLimit:初次同步的階段(followers連線到leader的階段),允許的時長(tick數量),預設:10
- syncLimit:允許followers同步到ZooKeeper的時長(tick數量),預設:5
- dataDir:資料(比如所管理的配置檔案)的存放路徑,初始時應該為空
- server.X:X是ensemble中一個伺服器的id,後面指定該server的hostname、第一個埠號用於ZooKeeper之間的通訊、第二個埠用於和其他應用之間的通訊
修改:dataDir=/var/lib/zookeeperdata/2 修改:clientPort=2182 配置第三個: # cp zoo1.cfg zoo3.cfg
修改:dataDir=/var/lib/zookeeperdata/3 修改:clientPort=2183
建立相應的dataDir目錄和myid檔案: # cd /var/lib # mkdir zookeeperdata # cd zookeeperdata # mkdir 1 # mkdir 2
# mkdir 3
# echo "1" > 1/myid # echo "2" > 2/myid
# echo "3" > 3/myid
啟動ZooKeeper: # cd <ZOOKEEPER_HOME> # bin/zkServer.sh start ./conf/zoo1.cfg # bin/zkServer.sh start ./conf/zoo2.cfg # bin/zkServer.sh start ./conf/zoo3.cfg 啟動結果: JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo1.cfg
Starting zookeeper ... STARTED
JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo2.cfg
Starting zookeeper ... STARTED
JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo3.cfg
Starting zookeeper ... STARTED 檢視狀態: 用jps命令檢視程序: # jps 24617 QuorumPeerMain (這個就是zookeeper程序) /opt/app/zookeeper/bin/zkServer.sh status zoo1.cfg
JMX enabled by default Using config: /opt/app/zookeeper/bin/../conf/zoo1.cfg Error contacting service. It is probably not running. 說明有錯誤,檢視日誌檔案: # cd <zookeeper_home> # less zookeeper.out java.net.BindException: 地址已在使用 殺掉當前程序: # kill -9 24617 再重啟那三個例項後,檢視狀態: # /opt/app/zookeeper/bin/zkServer.sh status zoo1.cfg
JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo1.cfg
Mode: follower
# /opt/app/zookeeper/bin/zkServer.sh status zoo2.cfg
JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo2.cfg
Mode: leader
# /opt/app/zookeeper/bin/zkServer.sh status zoo3.cfg
JMX enabled by default
Using config: /opt/app/zookeeper/bin/../conf/zoo3.cfg
Mode: follower 一切正常! # echo mntr | nc localhost 2181